|
| 1 | +import { expect, test } from "@playwright/test"; |
| 2 | + |
| 3 | +import { waitForAnimations } from "../helpers/animations"; |
| 4 | +import { installMockBridge } from "../helpers/bridge"; |
| 5 | + |
| 6 | +const SHOTS = "test-results/message-feedback"; |
| 7 | + |
| 8 | +async function waitForMockLiveSubscription( |
| 9 | + page: import("@playwright/test").Page, |
| 10 | + channelName: string, |
| 11 | +) { |
| 12 | + await expect |
| 13 | + .poll(async () => { |
| 14 | + return page.evaluate( |
| 15 | + ({ ch }) => |
| 16 | + ( |
| 17 | + window as Window & { |
| 18 | + __BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__?: (input: { |
| 19 | + channelName: string; |
| 20 | + }) => boolean; |
| 21 | + } |
| 22 | + ).__BUZZ_E2E_HAS_MOCK_LIVE_SUBSCRIPTION__?.({ channelName: ch }) ?? |
| 23 | + false, |
| 24 | + { ch: channelName }, |
| 25 | + ); |
| 26 | + }) |
| 27 | + .toBe(true); |
| 28 | +} |
| 29 | + |
| 30 | +test("pending continuation keeps Sending next to its timestamp", async ({ |
| 31 | + page, |
| 32 | +}) => { |
| 33 | + await installMockBridge(page); |
| 34 | + await page.goto("/"); |
| 35 | + await page.getByTestId("channel-general").click(); |
| 36 | + await expect(page.getByTestId("chat-title")).toHaveText("general"); |
| 37 | + await waitForMockLiveSubscription(page, "general"); |
| 38 | + |
| 39 | + const sentMessage = `Message before pending state ${Date.now()}`; |
| 40 | + const pendingMessage = `Pending message status ${Date.now()}`; |
| 41 | + const createdAt = Math.floor(Date.now() / 1_000); |
| 42 | + await page.evaluate( |
| 43 | + ({ firstMessage, secondMessage, timestamp }) => { |
| 44 | + const emit = ( |
| 45 | + window as Window & { |
| 46 | + __BUZZ_E2E_EMIT_MOCK_MESSAGE__?: (input: { |
| 47 | + channelName: string; |
| 48 | + content: string; |
| 49 | + createdAt: number; |
| 50 | + pending?: boolean; |
| 51 | + }) => unknown; |
| 52 | + } |
| 53 | + ).__BUZZ_E2E_EMIT_MOCK_MESSAGE__; |
| 54 | + emit?.({ |
| 55 | + channelName: "general", |
| 56 | + content: firstMessage, |
| 57 | + createdAt: timestamp - 1, |
| 58 | + }); |
| 59 | + emit?.({ |
| 60 | + channelName: "general", |
| 61 | + content: secondMessage, |
| 62 | + createdAt: timestamp, |
| 63 | + pending: true, |
| 64 | + }); |
| 65 | + }, |
| 66 | + { |
| 67 | + firstMessage: sentMessage, |
| 68 | + secondMessage: pendingMessage, |
| 69 | + timestamp: createdAt, |
| 70 | + }, |
| 71 | + ); |
| 72 | + |
| 73 | + const pendingRow = page |
| 74 | + .getByTestId("message-row") |
| 75 | + .filter({ hasText: pendingMessage }); |
| 76 | + const status = pendingRow.getByTestId("message-send-status"); |
| 77 | + await expect(status).toHaveText("Sending…"); |
| 78 | + await expect(pendingRow.getByTestId("message-author")).toHaveCount(1); |
| 79 | + |
| 80 | + const timestamp = status.locator("xpath=../p[1]"); |
| 81 | + const [timestampBox, statusBox] = await Promise.all([ |
| 82 | + timestamp.boundingBox(), |
| 83 | + status.boundingBox(), |
| 84 | + ]); |
| 85 | + expect(timestampBox).not.toBeNull(); |
| 86 | + expect(statusBox).not.toBeNull(); |
| 87 | + if (!timestampBox || !statusBox) { |
| 88 | + throw new Error("Pending message metadata is missing its inline layout."); |
| 89 | + } |
| 90 | + expect(statusBox.x).toBeGreaterThan(timestampBox.x); |
| 91 | + expect(Math.abs(statusBox.y - timestampBox.y)).toBeLessThanOrEqual(1); |
| 92 | + |
| 93 | + await waitForAnimations(page); |
| 94 | + await pendingRow.screenshot({ path: `${SHOTS}/pending-message-inline.png` }); |
| 95 | +}); |
| 96 | + |
| 97 | +test("profile hover uses the channel hover surface", async ({ page }) => { |
| 98 | + await installMockBridge(page); |
| 99 | + await page.goto("/"); |
| 100 | + |
| 101 | + const profile = page.getByTestId("sidebar-profile-card"); |
| 102 | + const channel = page.getByTestId("channel-random"); |
| 103 | + await channel.hover(); |
| 104 | + const channelHoverColor = await channel.evaluate( |
| 105 | + (element) => getComputedStyle(element).backgroundColor, |
| 106 | + ); |
| 107 | + await profile.hover(); |
| 108 | + await expect(profile).toHaveCSS("background-color", channelHoverColor); |
| 109 | + |
| 110 | + await waitForAnimations(page); |
| 111 | + await page |
| 112 | + .getByTestId("app-sidebar") |
| 113 | + .screenshot({ path: `${SHOTS}/profile-hover.png` }); |
| 114 | +}); |
0 commit comments