31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { describe, test, expect } from 'vitest';
|
|||
|
|
import { DEFAULT_HEADER_STATE } from './PageContext';
|
||
|
|
import { exportBodyHtml } from '../utils/html-export';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The default header is seeded as a hand-authored serialized Craft state. A
|
||
|
|
* malformed node map would not fail typecheck but would break the header on
|
||
|
|
* every new site at runtime, so we validate it deserializes + exports through
|
||
|
|
* the same path the editor preview and the WHP publish step use.
|
||
|
|
*/
|
||
|
|
describe('DEFAULT_HEADER_STATE seed', () => {
|
||
|
|
test('is valid JSON with a ROOT header + a Navbar child', () => {
|
||
|
|
const parsed = JSON.parse(DEFAULT_HEADER_STATE);
|
||
|
|
expect(parsed.ROOT).toBeDefined();
|
||
|
|
expect(parsed.ROOT.type.resolvedName).toBe('Container');
|
||
|
|
expect(parsed.ROOT.props.tag).toBe('header');
|
||
|
|
expect(parsed.ROOT.nodes).toContain('header-navbar');
|
||
|
|
expect(parsed['header-navbar'].type.resolvedName).toBe('Navbar');
|
||
|
|
expect(parsed['header-navbar'].parent).toBe('ROOT');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('exports to header HTML containing the nav and its default links', () => {
|
||
|
|
const { html } = exportBodyHtml(DEFAULT_HEADER_STATE);
|
||
|
|
expect(html).toContain('<nav');
|
||
|
|
expect(html).toContain('MySite');
|
||
|
|
for (const link of ['Home', 'About', 'Services', 'Contact']) {
|
||
|
|
expect(html).toContain(link);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|