archivo del paquete→ .shtukbase/packages/lenses/test/design.test.ts
test/design.test.ts
86 líneas, 4.6 KB.
El archivo tal como está en el paquete: el código y sus comentarios no se traducen.
- // The build includes the style and library CSS. A separate layout supplies the frame. Run: `bun test`.
- import { afterAll, describe, expect, test } from 'bun:test';
- import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
- import { tmpdir } from 'node:os';
- import { join } from 'node:path';
- // @ts-ignore - plain JS module
- import { designFiles, kitFiles } from '../kit/src/build.js';
- const dirs: string[] = [];
- afterAll(() => dirs.forEach((d) => rmSync(d, { recursive: true, force: true })));
- function project(design: { style?: string; libraries?: string[] } | null, opts: { shell?: boolean; tokens?: boolean } = {}) {
- const d = mkdtempSync(join(tmpdir(), 'lenses-design-'));
- dirs.push(d);
- mkdirSync(join(d, 'design'), { recursive: true });
- if (design)
- writeFileSync(join(d, 'design', 'design.md'),
- `---\ntype: Page\ntitle: Design\nstyle: "${design.style ?? ''}"\nlibraries: [${(design.libraries ?? []).join(', ')}]\n---\n`);
- if (opts.tokens) {
- mkdirSync(join(d, 'design', 'my-style'), { recursive: true });
- writeFileSync(join(d, 'design', 'my-style', 'tokens.css'), ':root { --primary: #cf3a63; }\n');
- }
- mkdirSync(join(d, 'design', 'my-ui', 'components', opts.shell === false ? 'block' : 'shell', 'panel'), { recursive: true });
- writeFileSync(join(d, 'design', 'my-ui', 'ui.css'), '.panel { color: var(--foreground); } /* my-ui */\n');
- return d;
- }
- const KIT_CSS = readFileSync(join(import.meta.dir, '..', 'kit', 'kit', 'kit.css'), 'utf8');
- describe('the kit finds the style and the library', () => {
- test('passes: the chosen style and library go into kit.css with the built-in frame', () => {
- const d = project({ style: 'my-style', libraries: ['my-ui'] }, { tokens: true });
- expect(designFiles(d).library?.id).toBe('my-ui');
- expect(designFiles(d).style?.id).toBe('my-style');
- const css = kitFiles(d)['kit.css'];
- expect(css).toContain('/* my-ui */');
- expect(css).toContain('--primary: #cf3a63');
- expect(css).not.toContain('lenses kit/shell.css, the fallback');
- expect(css).toContain("the built-in layout");
- // The library comes after the kit's own CSS so its component styles win.
- expect(css.indexOf('/* my-ui */')).toBeGreaterThan(css.indexOf('---- lenses: kit.css ----'));
- });
- test('fails over: no library with the shell means the kit fallback draws the frame', () => {
- const d = project({ style: '', libraries: [] }, { shell: false });
- expect(designFiles(d).library).toBeNull();
- const css = kitFiles(d)['kit.css'];
- expect(css).toContain('lenses kit/shell.css, the fallback');
- expect(css).not.toContain('/* my-ui */');
- });
- test('an older library bundle loses its frame CSS while keeping the other parts', () => {
- const d = project({ libraries: ['my-ui'] });
- writeFileSync(join(d, 'design/my-ui/ui.css'), [
- '/* ---- shell/shell ---- */', '.shell { background: purple; }',
- '/* ---- shell/sidebar ---- */', '.sidebar { width: 100%; }',
- ].join('\n'));
- const css = designFiles(d).library?.css;
- expect(css).not.toContain('background: purple');
- expect(css).toContain('.sidebar { width: 100%; }');
- });
- test('a library named on design.md but without the shell is not taken', () => {
- expect(designFiles(project({ libraries: ['my-ui'] }, { shell: false })).library).toBeNull();
- });
- test('no design.md: the first library with the shell is taken', () => {
- expect(designFiles(project(null)).library?.id).toBe('my-ui');
- });
- test('a resolved partial library can style controls while the built-in shell supplies the frame', () => {
- const d = project({ libraries: ['my-ui'] }, { shell: false });
- mkdirSync(join(d, 'lib/design'), { recursive: true });
- writeFileSync(join(d, 'lib/design/ui.css'), '/* resolved button */\n.button { border-radius: 999px; }\n');
- const css = kitFiles(d)['kit.css'];
- expect(css).toContain('lenses kit/shell.css, the fallback');
- expect(css).toContain('the built-in layout');
- expect(css.indexOf('/* resolved button */')).toBeGreaterThan(css.indexOf('the fallback components'));
- expect(css).not.toContain('/* my-ui */');
- });
- });
- describe('the kit keeps no chrome of its own', () => {
- test('its CSS has no rules for the old header, side panel, section cards, buttons or segmented choice', () => {
- for (const cls of ['lx-top', 'lx-side', 'lx-sec', 'lx-sech', 'lx-seg', 'lx-btn', 'lx-zoomctl', 'lx-app', 'lx-skin-btn'])
- expect(new RegExp(`\\.${cls}\\b`).test(KIT_CSS), cls).toBe(false);
- });
- test('the kit names its clashing variables --lx-*, never the contract names', () => {
- expect(/--(accent|muted|card|radius)\s*:/.test(KIT_CSS)).toBe(false);
- });
- });