包文件→ .shtukbase/packages/shtukbase-ui-html/test/overflow.test.ts
test/overflow.test.ts
35 行, 2.2 KB.
文件按包中的原样显示:代码及其注释不做翻译。
- // Text never leaves a component: every state and data state of every component, with its texts replaced by long Russian
- // text, in a cell as narrow as its level allows, measured in headless Chrome (lib/overflow.ts). Skipped where no Chrome
- // or Chromium is installed (set CHROME to its path).
- import { describe, expect, test } from 'bun:test';
- import { readFileSync } from 'node:fs';
- import { join } from 'node:path';
- import { CONTROL_SKIP, uiCss, variants } from '../lib/build.ts';
- import { LIB_DIR, scan } from '../lib/components.ts';
- import { type Cell, findChrome, longText, MEASURED_LEVELS, overflowPage, runChrome, RU_LONG, RU_SHORT } from '../lib/overflow.ts';
- const PAGES = join(import.meta.dir, '..', 'pages');
- const chrome = findChrome();
- test('longText replaces words, keeps keys, numbers, initials and svg', () => {
- const m = '<button class="b">Install</button><kbd>⌘K</kbd><b>14</b><span>KE</span><svg><text>abc</text></svg><p>A folder of pages of one type</p>';
- expect(longText(m)).toBe(`<button class="b">${RU_SHORT}</button><kbd>⌘K</kbd><b>14</b><span>KE</span><svg><text>abc</text></svg><p>${RU_LONG}</p>`);
- });
- describe.skipIf(!chrome)('no text overflows, in any state, with long Russian text', () => {
- const comps = scan(PAGES).filter((c) => MEASURED_LEVELS.includes(c.header.level));
- const css = readFileSync(join(PAGES, LIB_DIR, 'demo-tokens.css'), 'utf8') + uiCss(PAGES, scan(PAGES));
- // every state and data state, and one picture per value of each control (sizes, variants, presets)
- const cells: Cell[] = comps.flatMap((c) => [
- ...Object.entries(c.templates).map(([state, markup]) => ({ id: c.header.id, state, level: c.header.level, markup })),
- ...Object.entries(c.header.controls).filter(([name]) => !(CONTROL_SKIP[c.header.id] ?? []).includes(name)).flatMap(([name, ctl]) =>
- variants(c, name, ctl).map(([value, markup]) => ({ id: c.header.id, state: `${name}=${value}`, level: c.header.level, markup }))),
- ]);
- const failures = runChrome(chrome!, overflowPage(cells, css));
- for (const c of comps) {
- test(c.header.id, () => {
- const mine = failures.filter((f) => f.id === c.header.id).map((f) => `${f.state}: ${f.what}`);
- expect(mine).toEqual([]);
- });
- }
- });