|
| 1 | +import type { ElectronApplication, Page } from "playwright"; |
| 2 | +import { test, expect } from "./fixtures"; |
| 3 | + |
| 4 | +/** |
| 5 | + * E2E: Notification history bell button in the footer. |
| 6 | + * |
| 7 | + * The history panel is now a separate always-on-top BrowserWindow managed by |
| 8 | + * the main process (NotificationHistoryWindowManager). Clicking the bell |
| 9 | + * button in the footer opens/closes that window. |
| 10 | + * |
| 11 | + * Prerequisites: run `pnpm run build` before executing these tests. |
| 12 | + */ |
| 13 | + |
| 14 | +/** |
| 15 | + * Click the bell button and wait for the newly-created history BrowserWindow |
| 16 | + * to appear. The history window is created lazily on first click. |
| 17 | + */ |
| 18 | +async function openHistoryWindow(electronApp: ElectronApplication, window: Page): Promise<Page> { |
| 19 | + const bellBtn = window.locator("#footer-notification-bell-btn"); |
| 20 | + await expect(bellBtn).toBeVisible({ timeout: 15_000 }); |
| 21 | + |
| 22 | + const historyWindowPromise = electronApp.waitForEvent("window", { timeout: 10_000 }); |
| 23 | + await bellBtn.click(); |
| 24 | + const historyWindow = await historyWindowPromise; |
| 25 | + await historyWindow.waitForLoadState("domcontentloaded"); |
| 26 | + return historyWindow; |
| 27 | +} |
| 28 | + |
| 29 | +/** Check whether the Notification History BrowserWindow is currently visible. */ |
| 30 | +async function isHistoryWindowVisible(electronApp: ElectronApplication): Promise<boolean> { |
| 31 | + return electronApp.evaluate(({ BrowserWindow }) => { |
| 32 | + const win = BrowserWindow.getAllWindows().find((w) => w.getTitle() === "Notification History"); |
| 33 | + return win?.isVisible() ?? false; |
| 34 | + }); |
| 35 | +} |
| 36 | + |
| 37 | +test.describe("Notification history panel", () => { |
| 38 | + test("bell button is visible in the footer", async ({ window }) => { |
| 39 | + const bellBtn = window.locator("#footer-notification-bell-btn"); |
| 40 | + await expect(bellBtn).toBeVisible({ timeout: 15_000 }); |
| 41 | + }); |
| 42 | + |
| 43 | + test("notification badge is initially hidden", async ({ window }) => { |
| 44 | + const badge = window.locator("#notification-badge"); |
| 45 | + await expect(badge).toBeHidden({ timeout: 15_000 }); |
| 46 | + }); |
| 47 | + |
| 48 | + test("bell button aria-pressed is false initially", async ({ window }) => { |
| 49 | + const bellBtn = window.locator("#footer-notification-bell-btn"); |
| 50 | + await expect(bellBtn).toBeVisible({ timeout: 15_000 }); |
| 51 | + await expect(bellBtn).toHaveAttribute("aria-pressed", "false"); |
| 52 | + }); |
| 53 | + |
| 54 | + test("clicking the bell button opens the history window", async ({ electronApp, window }) => { |
| 55 | + await openHistoryWindow(electronApp, window); |
| 56 | + |
| 57 | + const isVisible = await isHistoryWindowVisible(electronApp); |
| 58 | + expect(isVisible).toBe(true); |
| 59 | + }); |
| 60 | + |
| 61 | + test("clicking the bell button again closes the history window", async ({ electronApp, window }) => { |
| 62 | + const bellBtn = window.locator("#footer-notification-bell-btn"); |
| 63 | + await expect(bellBtn).toBeVisible({ timeout: 15_000 }); |
| 64 | + |
| 65 | + // Open the history window |
| 66 | + await openHistoryWindow(electronApp, window); |
| 67 | + await expect(bellBtn).toHaveAttribute("aria-pressed", "true", { timeout: 5_000 }); |
| 68 | + |
| 69 | + // Click bell again to close |
| 70 | + await bellBtn.click(); |
| 71 | + await expect(bellBtn).toHaveAttribute("aria-pressed", "false", { timeout: 5_000 }); |
| 72 | + |
| 73 | + const isVisible = await isHistoryWindowVisible(electronApp); |
| 74 | + expect(isVisible).toBe(false); |
| 75 | + }); |
| 76 | + |
| 77 | + test("pressing Escape in the history window closes it", async ({ electronApp, window }) => { |
| 78 | + const bellBtn = window.locator("#footer-notification-bell-btn"); |
| 79 | + await expect(bellBtn).toBeVisible({ timeout: 15_000 }); |
| 80 | + |
| 81 | + const historyWindow = await openHistoryWindow(electronApp, window); |
| 82 | + await expect(bellBtn).toHaveAttribute("aria-pressed", "true", { timeout: 5_000 }); |
| 83 | + |
| 84 | + await historyWindow.keyboard.press("Escape"); |
| 85 | + await expect(bellBtn).toHaveAttribute("aria-pressed", "false", { timeout: 5_000 }); |
| 86 | + }); |
| 87 | + |
| 88 | + test("empty state is shown when there are no notifications", async ({ electronApp, window }) => { |
| 89 | + const historyWindow = await openHistoryWindow(electronApp, window); |
| 90 | + |
| 91 | + const emptyState = historyWindow.locator("#notification-history-empty"); |
| 92 | + await expect(emptyState).toBeVisible({ timeout: 5_000 }); |
| 93 | + await expect(emptyState).toHaveText(/no notifications yet/i); |
| 94 | + }); |
| 95 | + |
| 96 | + test("history window has a Clear All button", async ({ electronApp, window }) => { |
| 97 | + const historyWindow = await openHistoryWindow(electronApp, window); |
| 98 | + |
| 99 | + const clearBtn = historyWindow.locator("#notification-clear-all-btn"); |
| 100 | + await expect(clearBtn).toBeVisible({ timeout: 5_000 }); |
| 101 | + }); |
| 102 | + |
| 103 | + test("bell button aria-pressed reflects window open state", async ({ electronApp, window }) => { |
| 104 | + const bellBtn = window.locator("#footer-notification-bell-btn"); |
| 105 | + await expect(bellBtn).toBeVisible({ timeout: 15_000 }); |
| 106 | + |
| 107 | + await expect(bellBtn).toHaveAttribute("aria-pressed", "false"); |
| 108 | + |
| 109 | + await openHistoryWindow(electronApp, window); |
| 110 | + await expect(bellBtn).toHaveAttribute("aria-pressed", "true", { timeout: 5_000 }); |
| 111 | + |
| 112 | + await bellBtn.click(); |
| 113 | + await expect(bellBtn).toHaveAttribute("aria-pressed", "false", { timeout: 5_000 }); |
| 114 | + }); |
| 115 | + |
| 116 | + test("notification list is present inside the history window", async ({ electronApp, window }) => { |
| 117 | + const historyWindow = await openHistoryWindow(electronApp, window); |
| 118 | + |
| 119 | + const list = historyWindow.locator("#notification-history-list"); |
| 120 | + await expect(list).toBeAttached({ timeout: 5_000 }); |
| 121 | + }); |
| 122 | +}); |
0 commit comments