mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-09-14 17:42:17 +00:00
de39dc78ea
Splits testing into five layers so a failure points at the responsible one: - tests/unit isolated utility, repository and service tests - tests/data validates the tracked Pokémon, game, region and dex files - tests/integration schema, views, constraints, RLS and repositories - tests/bdd executable Gherkin for user-visible behaviour - tests/build service worker and manifest artifacts per build variant Replaces the two Playwright specs in client-test/ and the two Vitest files in test/. Adds a GitHub Actions workflow running the layers as separate jobs, a mock OAuth provider server so the Drive and Dropbox scenarios never touch real accounts, and a wrapper that reads the local Supabase keys from `supabase status` rather than hard-coding them. Extracts the pure formatting helpers out of PokedexExportService so they can be unit tested, and makes the provider endpoints configurable so the mock server can stand in for Google and Dropbox.
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { createBdd } from 'playwright-bdd';
|
|
import type { Page } from '@playwright/test';
|
|
import { test, expect } from '../fixtures';
|
|
|
|
const { Given, When, Then } = createBdd(test);
|
|
|
|
async function waitForServiceWorker(page: Page) {
|
|
return page.evaluate(async () => {
|
|
if (!('serviceWorker' in navigator)) throw new Error('Service workers are not supported');
|
|
const registration = await Promise.race([
|
|
navigator.serviceWorker.ready,
|
|
new Promise<never>((_, reject) =>
|
|
setTimeout(() => reject(new Error('Service worker registration timed out')), 15_000)
|
|
)
|
|
]);
|
|
return registration.active?.scriptURL ?? null;
|
|
});
|
|
}
|
|
|
|
When('I open the built application', async ({ page }) => {
|
|
await page.goto('/');
|
|
await waitForServiceWorker(page);
|
|
});
|
|
|
|
Given('I have opened the built application online', async ({ page }) => {
|
|
await page.context().setOffline(false);
|
|
await page.goto('/');
|
|
await waitForServiceWorker(page);
|
|
await page.reload();
|
|
});
|
|
|
|
When('I go offline and revisit the home page with a trailing slash', async ({ page }) => {
|
|
await page.context().setOffline(true);
|
|
await page.goto('/', { waitUntil: 'domcontentloaded' });
|
|
});
|
|
|
|
When('I go offline and then return online', async ({ page }) => {
|
|
await page.context().setOffline(true);
|
|
await page.reload({ waitUntil: 'domcontentloaded' });
|
|
await page.context().setOffline(false);
|
|
await page.reload({ waitUntil: 'domcontentloaded' });
|
|
});
|
|
|
|
Then('a service worker controls the page', async ({ page }) => {
|
|
expect(await waitForServiceWorker(page)).toMatch(/\/(?:sw|prompt-sw)\.js$/);
|
|
});
|
|
|
|
Then('the application cache is present', async ({ page }) => {
|
|
const cacheNames = await page.evaluate(() => caches.keys());
|
|
expect(cacheNames.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
Then('the application remains available', async ({ page }) => {
|
|
await expect(page.getByRole('heading', { name: /Start Your Pokédex Journey/ })).toBeVisible();
|
|
});
|