Skip to content

Commit ed34980

Browse files
committed
Add Toasts/NetworkError e2e test and page fixture
1 parent 0fa529b commit ed34980

2 files changed

Lines changed: 99 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
import NetworkStatusComponent from '@components/Toasts/NetworkStatus/index.astro'
3+
import '@styles/index.css'
4+
5+
export const prerender = true
6+
7+
const pageTitle = 'Network Status Component Fixture'
8+
const fixtureDescription = 'Sandbox route dedicated to validating the NetworkStatus toast web component and its connection indicator.'
9+
---
10+
<!DOCTYPE html>
11+
<html lang="en" data-theme="light">
12+
<head>
13+
<meta charset="utf-8">
14+
<title>{pageTitle}</title>
15+
<meta name="robots" content="noindex, nofollow">
16+
</head>
17+
<body class="bg-bg text-text">
18+
<main class="min-h-screen flex flex-col items-center gap-8 py-16 px-4">
19+
<header class="max-w-3xl text-center space-y-4">
20+
<p class="text-xs uppercase tracking-widest text-text-offset">Testing Fixture</p>
21+
<h1 class="text-3xl font-semibold leading-tight">{pageTitle}</h1>
22+
<p class="text-text-offset" data-testid="network-status-test-description">
23+
{fixtureDescription}
24+
</p>
25+
</header>
26+
27+
<section class="w-full max-w-3xl space-y-6 bg-bg-offset rounded-lg p-6 shadow-sm" aria-label="Network status component fixture">
28+
<div class="space-y-4">
29+
<NetworkStatusComponent />
30+
<div class="border border-border rounded-lg p-4 space-y-3" data-testid="network-status-indicator-panel">
31+
<p class="text-sm text-text-offset">Connection Indicator</p>
32+
<div class="connection-status text-green-600 font-semibold" data-testid="connection-indicator">
33+
Online
34+
</div>
35+
<p class="text-xs text-text-offset">
36+
The indicator above is updated by NetworkStatus when window online/offline events fire. Tests can dispatch those
37+
events to simulate connectivity changes and verify toast behavior.
38+
</p>
39+
</div>
40+
</div>
41+
</section>
42+
</main>
43+
</body>
44+
</html>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* Network Status Component Tests
3+
* Validates toast behavior and connection indicator updates using the testing fixture route
4+
* @see src/pages/testing/network-status.astro
5+
*/
6+
7+
import type { Page } from '@playwright/test'
8+
import { BasePage, expect, test } from '@test/e2e/helpers'
9+
10+
const NETWORK_STATUS_FIXTURE = {
11+
path: '/testing/network-status',
12+
toastSelector: '#network-status-toast',
13+
indicatorSelector: '[data-testid="connection-indicator"]',
14+
}
15+
16+
async function loadNetworkStatusFixture(playwrightPage: Page) {
17+
const page = await BasePage.init(playwrightPage)
18+
await page.goto(NETWORK_STATUS_FIXTURE.path)
19+
await page.waitForLoadState('networkidle')
20+
return page
21+
}
22+
23+
async function dispatchConnectionEvent(page: BasePage, eventName: 'online' | 'offline') {
24+
await page.evaluate(name => {
25+
window.dispatchEvent(new Event(name))
26+
}, eventName)
27+
}
28+
29+
test.describe('Network Status Component', () => {
30+
test('renders toast host and connection indicator in testing fixture', async ({ page: playwrightPage }) => {
31+
const page = await loadNetworkStatusFixture(playwrightPage)
32+
const toast = page.locator(NETWORK_STATUS_FIXTURE.toastSelector)
33+
const indicator = page.locator(NETWORK_STATUS_FIXTURE.indicatorSelector)
34+
35+
await expect(toast).toHaveClass(/hidden/)
36+
await expect(indicator).toHaveText('Online')
37+
await expect(indicator).toHaveClass(/text-green-600/)
38+
})
39+
40+
test('updates connection status and shows toast after reconnection', async ({ page: playwrightPage }) => {
41+
const page = await loadNetworkStatusFixture(playwrightPage)
42+
const toast = page.locator(NETWORK_STATUS_FIXTURE.toastSelector)
43+
const indicator = page.locator(NETWORK_STATUS_FIXTURE.indicatorSelector)
44+
45+
await dispatchConnectionEvent(page, 'offline')
46+
await expect(indicator).toHaveText('Offline')
47+
await expect(indicator).toHaveClass(/text-red-600/)
48+
await expect(toast).toHaveClass(/hidden/)
49+
50+
await dispatchConnectionEvent(page, 'online')
51+
await expect(indicator).toHaveText('Online')
52+
await expect(indicator).toHaveClass(/text-green-600/)
53+
await expect(toast).not.toHaveClass(/hidden/)
54+
})
55+
})

0 commit comments

Comments
 (0)