Files
slp-modular-cms/frontend/themes/resolveTheme.test.ts
T
SluijsensandClaude Sonnet 5.5 88f5d20a78 Voeg Api.AndreaSlopFotografie toe met setup-token, proxy-bewuste limiters en ASF-admin-thema
- Core: opt-in ForwardedHeaders:KnownProxies en rate limiters per clientadres
  (zonder configuratie ongewijzigd gedrag)
- Identity: optioneel setup-token (X-Setup-Token), beide setup-endpoints onder de
  login-limiter, beveiligingsgebeurtenis setup_token_rejected (5007)
- Nieuw client-project SlpModularCms.Api.AndreaSlopFotografie (Identity + Availability)
  met bijbehorende tests
- Frontend: thema asf (VITE_THEME), VITE_DEFAULT_LANGUAGE, tokenveld op de setup-pagina
- CI: jobs publish/deploy-asf-test achter ASF_TEST_DEPLOY_ENABLED
- Fix U1: 301-Location wordt nu percent-encoded (gevonden door de property-test)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 01:16:34 +01:00

74 lines
3.1 KiB
TypeScript

import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { describe, expect, it } from 'vitest';
import { availableThemes, resolveTheme } from './resolveTheme';
describe('resolveTheme', () => {
it.each([undefined, '', ' '])('maps %j to the empty module (the default admin)', (name) => {
const theme = resolveTheme(name);
expect(path.basename(theme.css)).toBe('none.css');
expect(theme.favicon).toBeNull();
expect(fs.readFileSync(theme.css, 'utf-8')).not.toMatch(/--[a-z-]+\s*:/);
});
it('resolves the asf theme with its stylesheet and favicon', () => {
const theme = resolveTheme('asf');
expect(fs.existsSync(theme.css)).toBe(true);
expect(theme.css.replaceAll('\\', '/')).toMatch(/themes\/asf\/theme\.css$/);
expect(theme.favicon !== null && fs.existsSync(theme.favicon)).toBe(true);
});
it('lists the available themes', () => {
expect(availableThemes()).toContain('asf');
});
it.each(['nope', '../asf', 'asf/../asf', '..', 'ASF', 'asf asf'])('rejects %j loudly, naming the real themes', (name) => {
expect(() => resolveTheme(name)).toThrow(/Unknown VITE_THEME .*Available themes: .*asf/);
});
it('reports (none) when no theme exists', () => {
const empty = fs.mkdtempSync(path.join(os.tmpdir(), 'themes-'));
try {
expect(() => resolveTheme('x', empty)).toThrow(/\(none\)/);
} finally {
fs.rmSync(empty, { recursive: true, force: true });
}
});
});
describe('asf theme tokens', () => {
const tokens = (css: string, block: string) => {
const m = css.match(new RegExp(`${block}\\s*\\{([^}]*)\\}`));
return new Set([...(m?.[1] ?? '').matchAll(/(--[a-z-]+)\s*:/g)].map((x) => x[1]));
};
const base = fs.readFileSync(path.resolve(__dirname, '../src/index.css'), 'utf-8');
const theme = fs.readFileSync(path.resolve(__dirname, 'asf/theme.css'), 'utf-8');
it('overrides every existing light and dark design token and invents no structural one', () => {
for (const block of ['\\:root', '\\.dark']) {
const existing = tokens(base, block);
const themed = tokens(theme, block);
for (const t of existing) expect(themed, `${block} ${t}`).toContain(t);
// Anything beyond the existing tokens must be the theme's own --asf-* palette or the font token.
for (const t of themed) {
if (!existing.has(t)) expect(t).toMatch(/^--(asf-|font-sans$)/);
}
}
});
it('uses the website palette colours exactly', () => {
for (const hex of ['#faf7f2', '#f1ebe2', '#e8e0d5', '#232120', '#55504b', '#8a827a', '#e2dad0', '#7f8b76', '#5f6a58', '#475042', '#d9cdbc', '#a4443a']) {
expect(theme.toLowerCase()).toContain(hex);
}
});
it('self-hosts its fonts (no remote url)', () => {
expect(theme).not.toMatch(/https?:\/\//);
expect(theme).toContain('@fontsource/jost');
expect(theme).toContain('@fontsource/marcellus');
});
});