|
| 1 | +import { test, expect, stubApis, STOPPED_GAME } from '../fixtures/index.js'; |
| 2 | + |
| 3 | +/** |
| 4 | + * Specs for the polling indicator + top-bar Refresh introduced in #65. The |
| 5 | + * shared {@link PollingProvider} runs the status poll above the router, so |
| 6 | + * every primary route should display "Updated …" and the top-bar Refresh |
| 7 | + * button should trigger a fresh `/api/status` call on demand. |
| 8 | + */ |
| 9 | + |
| 10 | +test.describe('polling indicator', () => { |
| 11 | + test('should render the "Updated …" label on the dashboard', async ({ dashboard }) => { |
| 12 | + await stubApis(dashboard.page, { statuses: [STOPPED_GAME] }); |
| 13 | + await dashboard.goto(); |
| 14 | + |
| 15 | + await expect(dashboard.page.getByText(/updated\s+\S+\s+ago/i).first()).toBeVisible(); |
| 16 | + }); |
| 17 | + |
| 18 | + test('should keep the indicator visible after navigating to /logs', async ({ dashboard, layout }) => { |
| 19 | + // Use an empty statuses list so the GameCard's per-card Logs link doesn't |
| 20 | + // collide with the sidebar's "Logs" nav link (Playwright strict mode). |
| 21 | + await stubApis(dashboard.page, { statuses: [] }); |
| 22 | + await dashboard.goto(); |
| 23 | + await expect(dashboard.page.getByText(/updated\s+\S+\s+ago/i).first()).toBeVisible(); |
| 24 | + |
| 25 | + await layout.navigateTo('Logs', '/logs'); |
| 26 | + await expect(dashboard.page.getByText(/updated\s+\S+\s+ago/i).first()).toBeVisible(); |
| 27 | + }); |
| 28 | + |
| 29 | + test('should keep the indicator visible after navigating to /discord', async ({ dashboard, layout }) => { |
| 30 | + await stubApis(dashboard.page, { statuses: [STOPPED_GAME] }); |
| 31 | + await dashboard.goto(); |
| 32 | + |
| 33 | + await layout.navigateTo('Discord', '/discord'); |
| 34 | + await expect(dashboard.page.getByText(/updated\s+\S+\s+ago/i).first()).toBeVisible(); |
| 35 | + }); |
| 36 | + |
| 37 | + test('should keep the indicator visible after navigating to /settings', async ({ dashboard, layout }) => { |
| 38 | + await stubApis(dashboard.page, { statuses: [STOPPED_GAME] }); |
| 39 | + await dashboard.goto(); |
| 40 | + |
| 41 | + await layout.navigateTo('Settings', '/settings'); |
| 42 | + await expect(dashboard.page.getByText(/updated\s+\S+\s+ago/i).first()).toBeVisible(); |
| 43 | + }); |
| 44 | +}); |
| 45 | + |
| 46 | +test.describe('top-bar refresh', () => { |
| 47 | + test('should re-fetch /api/status when the Refresh button is clicked', async ({ dashboard }) => { |
| 48 | + await stubApis(dashboard.page, { statuses: [STOPPED_GAME] }); |
| 49 | + |
| 50 | + // stubApis already registered a catch-all for /api/status; this later |
| 51 | + // registration wins (Playwright matches routes in REVERSE order) and lets |
| 52 | + // us count GETs against the endpoint. |
| 53 | + let statusGetCount = 0; |
| 54 | + await dashboard.page.route('**/api/status', (route) => { |
| 55 | + if (route.request().method() === 'GET') statusGetCount += 1; |
| 56 | + return route.fulfill({ json: [STOPPED_GAME] }); |
| 57 | + }); |
| 58 | + |
| 59 | + await dashboard.goto(); |
| 60 | + // Wait for the initial mount + first poll to settle so we can compare. |
| 61 | + await expect(dashboard.statusBadge('STOPPED')).toBeVisible(); |
| 62 | + const before = statusGetCount; |
| 63 | + |
| 64 | + await dashboard.page.getByRole('button', { name: 'Refresh all' }).click(); |
| 65 | + |
| 66 | + await expect.poll(() => statusGetCount).toBeGreaterThan(before); |
| 67 | + }); |
| 68 | +}); |
0 commit comments