mirror of
https://github.com/bitbaum/sitekit.git
synced 2026-12-04 04:57:10 +01:00
AOZ's public masthead (brand, "Zur Anmeldung", "Menü") needs 369px; at 320px the page scrolled sideways by 49px. Up to 380px (which takes in 360px Android) the action is now hidden in the row and shown at the foot of the mobile menu, one tap away, and only where a menu exists: a masthead with no nav items keeps its action in the row. SiteNav takes the actions as `menuActions`; SiteMasthead passes them. Measured in AOZ's production build with this package: 0px sideways at 320, 390 and 1280px, the action reachable in the open menu. Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9 Co-authored-by: Claude <noreply@anthropic.com>
114 lines
4.4 KiB
JavaScript
114 lines
4.4 KiB
JavaScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { createElement as h } from 'react';
|
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
import { readFileSync } from 'node:fs';
|
|
import { SiteMasthead, SiteFooter } from '@bitbaum/sitekit/react';
|
|
const chrome = { name: 'Example', tagline: 'Investigate', footerNote: 'Source evidence.' };
|
|
|
|
test('application shell composes brand/account slots, skip target and accessible mobile navigation', () => {
|
|
const html = renderToStaticMarkup(
|
|
h(SiteMasthead, {
|
|
chrome,
|
|
appearance: 'application',
|
|
mainId: 'content',
|
|
currentPath: 'analyze',
|
|
navItems: [
|
|
{ path: 'analyze', label: 'Examine' },
|
|
{ path: 'roadmap', label: 'Roadmap' },
|
|
],
|
|
brand: h('span', null, 'Example brand'),
|
|
actions: h('a', { href: '/account' }, 'Account'),
|
|
}),
|
|
);
|
|
assert.ok(html.includes('href="#content"'));
|
|
assert.ok(html.includes('Example brand'));
|
|
assert.ok(html.includes('href="/account"'));
|
|
assert.ok(html.includes('<details'));
|
|
assert.ok(html.includes('<summary>Menu'));
|
|
assert.equal((html.match(/aria-current="page"/g) || []).length, 2);
|
|
assert.ok(html.includes('aria-label="Main navigation"'));
|
|
});
|
|
test('empty navigation has no dead menu control', () => {
|
|
const html = renderToStaticMarkup(
|
|
h(SiteMasthead, { chrome, appearance: 'application', currentPath: '', navItems: [] }),
|
|
);
|
|
assert.ok(!html.includes('<summary>'));
|
|
});
|
|
test('shared footer includes configured navigation and supplied additional content', () => {
|
|
const html = renderToStaticMarkup(
|
|
h(SiteFooter, {
|
|
chrome,
|
|
appearance: 'application',
|
|
links: [
|
|
{ href: '/roadmap', label: 'Roadmap' },
|
|
{ href: '/blog', label: 'Journal' },
|
|
],
|
|
extra: 'Beta',
|
|
}),
|
|
);
|
|
assert.ok(html.includes('href="/roadmap"'));
|
|
assert.ok(html.includes('Journal'));
|
|
assert.ok(html.includes('Beta'));
|
|
assert.ok(html.includes(String(new Date().getFullYear())));
|
|
});
|
|
test('standalone styles ship through the public package and define touch and keyboard floors', () => {
|
|
const css = readFileSync(new URL('../styles.css', import.meta.url), 'utf8');
|
|
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
assert.equal(pkg.exports['./styles.css'], './styles.css');
|
|
assert.ok(pkg.files.includes('styles.css'));
|
|
assert.match(css, /min-height:\s*44px/);
|
|
assert.ok(css.includes(':focus-visible'));
|
|
assert.match(css, /@media\s*\(max-width:\s*1100px\)/);
|
|
});
|
|
|
|
test('footer groups have semantic labels and retain the legacy flat link contract', () => {
|
|
const html = renderToStaticMarkup(
|
|
h(SiteFooter, {
|
|
chrome,
|
|
appearance: 'application',
|
|
groups: [
|
|
{ label: 'Product', links: [{ href: '/analyze', label: 'Examine text' }] },
|
|
{ label: 'Resources', links: [{ href: '/method', label: 'Our method' }] },
|
|
],
|
|
}),
|
|
);
|
|
assert.ok(html.includes('<h2>Product</h2>'));
|
|
assert.ok(html.includes('<h2>Resources</h2>'));
|
|
assert.ok(html.includes('--sk-footer-columns:2'));
|
|
assert.ok(html.includes('href="/analyze"'));
|
|
assert.ok(html.includes('aria-label="Footer navigation"'));
|
|
});
|
|
|
|
test('on the narrowest phones the account action moves into the menu, never off the screen', () => {
|
|
const html = renderToStaticMarkup(
|
|
h(SiteMasthead, {
|
|
chrome,
|
|
appearance: 'application',
|
|
currentPath: '',
|
|
navItems: [{ path: 'blog', label: 'Blog' }],
|
|
actions: h('a', { href: '/login' }, 'Sign in'),
|
|
}),
|
|
);
|
|
const menu = html.slice(html.indexOf('sk-mobile-menu'), html.indexOf('</details>'));
|
|
assert.ok(menu.includes('sk-menu-actions'), 'the menu carries the actions');
|
|
assert.ok(menu.includes('href="/login"'), 'the same action, one tap away');
|
|
const css = readFileSync(new URL('../styles.css', import.meta.url), 'utf8');
|
|
assert.match(
|
|
css,
|
|
/@media \(max-width: 380px\)[\s\S]*\.sk-masthead-row:has\(\.sk-mobile-menu\) > \.sk-account-actions \{\s*display: none;/,
|
|
'the row drops its action only where a menu holds it',
|
|
);
|
|
// Without nav items there is no menu, and the action stays in the row.
|
|
const bare = renderToStaticMarkup(
|
|
h(SiteMasthead, {
|
|
chrome,
|
|
appearance: 'application',
|
|
currentPath: '',
|
|
navItems: [],
|
|
actions: h('a', { href: '/login' }, 'Sign in'),
|
|
}),
|
|
);
|
|
assert.ok(!bare.includes('sk-menu-actions') && bare.includes('sk-account-actions'));
|
|
});
|