Island markers rendered during SX navigation responses had no data-sx-state attribute, so hydration found empty kwargs and path was nil in the copyright display. Now adapter-dom.sx serializes keyword args into data-sx-state on island markers, matching what adapter-html.sx does for SSR. Also fix post-swap to use parent element for outerHTML swaps in SX responses (was using detached old target). Add SX source file hashes to wasm_hash for proper browser cache busting — changing any .sx file now busts the cache. Remove stale .sxbc bytecode cache files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
142 lines
4.8 KiB
JavaScript
142 lines
4.8 KiB
JavaScript
// Navigation tests for sx-docs
|
|
// Verifies navigation works correctly with the OCaml sx-host.
|
|
|
|
const { test, expect } = require('playwright/test');
|
|
const BASE_URL = process.env.SX_TEST_URL || 'http://localhost:8013';
|
|
|
|
test.describe('Page Navigation', () => {
|
|
|
|
test('clicking nav button navigates to new page', async ({ page }) => {
|
|
const errors = [];
|
|
page.on('console', msg => {
|
|
if (msg.type() === 'error') errors.push(msg.text());
|
|
});
|
|
|
|
await page.goto(BASE_URL + '/sx/(geography)', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Click "Reactive Islands" nav link
|
|
await page.click('a[href*="geography.(reactive)"]:not([href*="runtime"])');
|
|
await page.waitForTimeout(3000);
|
|
|
|
// Should have navigated — URL must contain reactive
|
|
expect(page.url()).toContain('reactive');
|
|
|
|
// Page should show Reactive Islands content
|
|
const body = await page.textContent('body');
|
|
expect(body).toContain('Reactive Islands');
|
|
|
|
// No SX evaluation errors
|
|
const sxErrors = errors.filter(e => e.includes('Undefined symbol'));
|
|
expect(sxErrors).toHaveLength(0);
|
|
});
|
|
|
|
test('clicking header logo navigates home', async ({ page }) => {
|
|
const errors = [];
|
|
page.on('console', msg => {
|
|
if (msg.type() === 'error') errors.push(msg.text());
|
|
});
|
|
|
|
await page.goto(BASE_URL + '/sx/(geography)', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Click the logo in the header island
|
|
await page.click('[data-sx-island="layouts/header"] a[href="/sx/"]');
|
|
await page.waitForTimeout(3000);
|
|
|
|
// Should have navigated to home
|
|
expect(page.url()).toMatch(/\/sx\/?$/);
|
|
|
|
// No SX evaluation errors
|
|
const sxErrors = errors.filter(e => e.includes('Undefined symbol'));
|
|
expect(sxErrors).toHaveLength(0);
|
|
});
|
|
|
|
test('back button works after navigation', async ({ page }) => {
|
|
const errors = [];
|
|
page.on('console', msg => {
|
|
if (msg.type() === 'error') errors.push(msg.text());
|
|
});
|
|
|
|
await page.goto(BASE_URL + '/sx/(geography)', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(2000);
|
|
|
|
// Navigate to Reactive Islands
|
|
await page.click('a[href*="geography.(reactive)"]:not([href*="runtime"])');
|
|
await page.waitForTimeout(3000);
|
|
expect(page.url()).toContain('reactive');
|
|
|
|
// Go back
|
|
await page.goBack();
|
|
await page.waitForTimeout(3000);
|
|
|
|
// Should be back at Geography
|
|
expect(page.url()).toContain('geography');
|
|
expect(page.url()).not.toContain('reactive');
|
|
|
|
// Geography heading should be visible
|
|
const heading = await page.locator('h1, h2').first();
|
|
await expect(heading).toContainText('Geography', { timeout: 5000 });
|
|
|
|
// No SX errors
|
|
const sxErrors = errors.filter(e => e.includes('Undefined symbol'));
|
|
expect(sxErrors).toHaveLength(0);
|
|
});
|
|
|
|
test('no console errors on page load', async ({ page }) => {
|
|
const errors = [];
|
|
page.on('console', msg => {
|
|
if (msg.type() === 'error' && !msg.text().includes('404'))
|
|
errors.push(msg.text());
|
|
});
|
|
|
|
await page.goto(BASE_URL + '/sx/(geography)', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(3000);
|
|
|
|
// No JIT or SX errors
|
|
const sxErrors = errors.filter(e =>
|
|
e.includes('Undefined symbol') || e.includes('Not callable'));
|
|
expect(sxErrors).toHaveLength(0);
|
|
});
|
|
|
|
test('copyright shows current route after SX navigation', async ({ page }) => {
|
|
await page.goto(BASE_URL + '/sx/', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(3000);
|
|
|
|
// Mark the page to verify SX navigation (not full reload)
|
|
await page.evaluate(() => window.__sx_nav_marker = true);
|
|
|
|
// Before: copyright shows the current path
|
|
const before = await page.evaluate(() =>
|
|
document.querySelector('[data-sx-lake="copyright"]')?.textContent);
|
|
expect(before).toContain('/sx/');
|
|
|
|
// Navigate via SX (sx-get link)
|
|
await page.click('a[sx-get*="(geography)"]');
|
|
await page.waitForTimeout(3000);
|
|
|
|
// Verify SX navigation (marker survives SX nav, lost on reload)
|
|
const marker = await page.evaluate(() => window.__sx_nav_marker);
|
|
expect(marker).toBe(true);
|
|
|
|
// After: copyright must still show a route path
|
|
const after = await page.evaluate(() =>
|
|
document.querySelector('[data-sx-lake="copyright"]')?.textContent);
|
|
expect(after).toContain('geography');
|
|
});
|
|
|
|
test('header island renders with SSR', async ({ page }) => {
|
|
await page.goto(BASE_URL + '/sx/(geography)', { waitUntil: 'networkidle' });
|
|
|
|
// Header should be visible
|
|
const header = page.locator('[data-sx-island="layouts/header"]');
|
|
await expect(header).toBeVisible();
|
|
|
|
// Should contain the logo
|
|
await expect(header).toContainText('sx');
|
|
|
|
// Should contain copyright
|
|
await expect(header).toContainText('Giles Bradshaw');
|
|
});
|
|
});
|