|
| 1 | +import { test, expect } from "@playwright/test"; |
| 2 | +import { SessionsPage } from "./pages/sessions-page"; |
| 3 | + |
| 4 | +test.describe("Activity Minimap", () => { |
| 5 | + let sp: SessionsPage; |
| 6 | + |
| 7 | + test.beforeEach(async ({ page }) => { |
| 8 | + sp = new SessionsPage(page); |
| 9 | + await sp.goto(); |
| 10 | + await sp.selectSession(0); |
| 11 | + }); |
| 12 | + |
| 13 | + test("minimap is hidden by default", async ({ |
| 14 | + page, |
| 15 | + }) => { |
| 16 | + await expect( |
| 17 | + page.locator(".activity-minimap"), |
| 18 | + ).not.toBeVisible(); |
| 19 | + }); |
| 20 | + |
| 21 | + test("toggle button shows and hides minimap", async ({ |
| 22 | + page, |
| 23 | + }) => { |
| 24 | + await page.locator(".minimap-btn").click(); |
| 25 | + await expect( |
| 26 | + page.locator(".activity-minimap"), |
| 27 | + ).toBeVisible(); |
| 28 | + |
| 29 | + await page.locator(".minimap-btn").click(); |
| 30 | + await expect( |
| 31 | + page.locator(".activity-minimap"), |
| 32 | + ).not.toBeVisible(); |
| 33 | + }); |
| 34 | + |
| 35 | + test("minimap shows bars for sessions with timestamps", async ({ |
| 36 | + page, |
| 37 | + }) => { |
| 38 | + await page.locator(".minimap-btn").click(); |
| 39 | + |
| 40 | + await expect( |
| 41 | + page.locator(".minimap-status"), |
| 42 | + ).not.toBeVisible({ timeout: 3000 }); |
| 43 | + |
| 44 | + const bars = page.locator(".minimap-bar"); |
| 45 | + const count = await bars.count(); |
| 46 | + expect(count).toBeGreaterThan(0); |
| 47 | + }); |
| 48 | + |
| 49 | + test("clicking a bar scrolls the message list", async ({ |
| 50 | + page, |
| 51 | + }) => { |
| 52 | + await page.locator(".minimap-btn").click(); |
| 53 | + |
| 54 | + const clickableBars = page.locator( |
| 55 | + "g.minimap-bar[role='button']", |
| 56 | + ); |
| 57 | + await clickableBars.first().waitFor({ timeout: 3000 }); |
| 58 | + |
| 59 | + const barCount = await clickableBars.count(); |
| 60 | + expect(barCount).toBeGreaterThan(0); |
| 61 | + |
| 62 | + const scrollBefore = await sp.scroller.evaluate( |
| 63 | + (el) => el.scrollTop, |
| 64 | + ); |
| 65 | + |
| 66 | + const lastBar = clickableBars.nth(barCount - 1); |
| 67 | + await lastBar.click(); |
| 68 | + |
| 69 | + if (barCount > 1) { |
| 70 | + await expect |
| 71 | + .poll( |
| 72 | + () => |
| 73 | + sp.scroller.evaluate((el) => el.scrollTop), |
| 74 | + { timeout: 3000 }, |
| 75 | + ) |
| 76 | + .not.toBe(scrollBefore); |
| 77 | + } |
| 78 | + }); |
| 79 | + |
| 80 | + test("active indicator moves after reopen without scroll", async ({ |
| 81 | + page, |
| 82 | + }) => { |
| 83 | + // Open minimap, wait for multiple bars. |
| 84 | + await page.locator(".minimap-btn").click(); |
| 85 | + const bars = page.locator("g.minimap-bar[role='button']"); |
| 86 | + await bars.first().waitFor({ timeout: 3000 }); |
| 87 | + |
| 88 | + const barCount = await bars.count(); |
| 89 | + if (barCount < 2) { |
| 90 | + // Can't test indicator movement with < 2 bars. |
| 91 | + return; |
| 92 | + } |
| 93 | + |
| 94 | + // Record the x position of the active indicator. |
| 95 | + const indicator = page.locator(".bar-indicator"); |
| 96 | + await expect(indicator).toBeVisible(); |
| 97 | + const xBefore = await indicator.evaluate( |
| 98 | + (el) => el.getAttribute("x"), |
| 99 | + ); |
| 100 | + |
| 101 | + // Close minimap, scroll to the bottom. |
| 102 | + await page.locator(".minimap-btn").click(); |
| 103 | + await expect( |
| 104 | + page.locator(".activity-minimap"), |
| 105 | + ).not.toBeVisible(); |
| 106 | + |
| 107 | + await sp.scroller.evaluate((el) => { |
| 108 | + el.scrollTop = el.scrollHeight; |
| 109 | + }); |
| 110 | + |
| 111 | + // Reopen — indicator should appear at a different |
| 112 | + // position reflecting the new scroll location. |
| 113 | + await page.locator(".minimap-btn").click(); |
| 114 | + await expect(indicator).toBeVisible({ timeout: 3000 }); |
| 115 | + |
| 116 | + await expect |
| 117 | + .poll( |
| 118 | + () => |
| 119 | + indicator.evaluate( |
| 120 | + (el) => el.getAttribute("x"), |
| 121 | + ), |
| 122 | + { timeout: 3000 }, |
| 123 | + ) |
| 124 | + .not.toBe(xBefore); |
| 125 | + }); |
| 126 | +}); |
0 commit comments