Debian Codegraph @

www/tests/e2e/morph-navigation.ts

raw symbols SCIP
1 import { test, expect } from './_fixtures';
2
3 const START = '/reference/attributes/hx-get';
4 const TARGET_HREF = '/reference/attributes/hx-post';
5 const TARGET_URL = /hx-post/;
6
7 async function navigateToTarget(page: any) {
8 const sidebarToggle = page.locator('label[for="sidebar-toggle-mobile"]');
9 if (await sidebarToggle.isVisible()) {
10 await sidebarToggle.click();
11 }
12 await page.locator(`#sidebar-nav a[href="${TARGET_HREF}"]`).click();
13 }
14
15 test.describe('Morph navigation', () => {
16 test('sidebar link navigates without full reload', async ({ page }) => {
17 await page.goto(START, { waitUntil: 'networkidle' });
18
19 await page.evaluate(() => {
20 const el = document.querySelector('search-index');
21 if (el) (el as any).__morphTest = true;
22 });
23
24 await navigateToTarget(page);
25 await expect(page).toHaveURL(TARGET_URL);
26
27 const survived = await page.evaluate(() => {
28 const el = document.querySelector('search-index');
29 return el && (el as any).__morphTest === true;
30 });
31 expect(survived).toBe(true);
32 });
33
34 test('content updates after morph navigation', async ({ page }) => {
35 await page.goto(START, { waitUntil: 'networkidle' });
36
37 const initialContent = await page.locator('.prose').textContent();
38
39 await navigateToTarget(page);
40 await expect(page).toHaveURL(TARGET_URL);
41
42 const newContent = await page.locator('.prose').textContent();
43 expect(newContent).not.toBe(initialContent);
44 });
45
46 test('no errors after morph navigation', async ({ page }) => {
47 const errors: string[] = [];
48 page.on('pageerror', (err: Error) => errors.push(err.message));
49 page.on('console', (msg: any) => {
50 if (msg.type() === 'error') errors.push(msg.text());
51 });
52
53 await page.goto(START, { waitUntil: 'networkidle' });
54
55 await navigateToTarget(page);
56 await expect(page).toHaveURL(TARGET_URL);
57 await page.waitForTimeout(500);
58
59 const realErrors = errors.filter(e =>
60 !e.includes('init is not defined') &&
61 !e.includes('favicon')
62 );
63 expect(realErrors).toEqual([]);
64 });
65
66 test('browser back works after morph navigation', async ({ page }) => {
67 await page.goto(START, { waitUntil: 'networkidle' });
68
69 await navigateToTarget(page);
70 await expect(page).toHaveURL(TARGET_URL);
71
72 await page.goBack();
73 await expect(page).toHaveURL(/hx-get/);
74 });
75
76 test('morph navigation scrolls to top', async ({ page }) => {
77 await page.goto(START, { waitUntil: 'networkidle' });
78
79 await page.evaluate(() => window.scrollTo(0, document.body.scrollHeight));
80 const scrolledY = await page.evaluate(() => window.scrollY);
81 expect(scrolledY).toBeGreaterThan(100);
82
83 await navigateToTarget(page);
84 await expect(page).toHaveURL(TARGET_URL);
85
86 const topY = await page.evaluate(() => window.scrollY);
87 expect(topY).toBeLessThan(50);
88 });
89 });