ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/shtukbase-ui-html/test/overflow.test.ts

test/overflow.test.ts

35 líneas, 2.2 KB.

El archivo tal como está en el paquete: el código y sus comentarios no se traducen.

  1. // Text never leaves a component: every state and data state of every component, with its texts replaced by long Russian
  2. // text, in a cell as narrow as its level allows, measured in headless Chrome (lib/overflow.ts). Skipped where no Chrome
  3. // or Chromium is installed (set CHROME to its path).
  4. import { describe, expect, test } from 'bun:test';
  5. import { readFileSync } from 'node:fs';
  6. import { join } from 'node:path';
  7. import { CONTROL_SKIP, uiCss, variants } from '../lib/build.ts';
  8. import { LIB_DIR, scan } from '../lib/components.ts';
  9. import { type Cell, findChrome, longText, MEASURED_LEVELS, overflowPage, runChrome, RU_LONG, RU_SHORT } from '../lib/overflow.ts';
  10. const PAGES = join(import.meta.dir, '..', 'pages');
  11. const chrome = findChrome();
  12. test('longText replaces words, keeps keys, numbers, initials and svg', () => {
  13. 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>';
  14. 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>`);
  15. });
  16. describe.skipIf(!chrome)('no text overflows, in any state, with long Russian text', () => {
  17. const comps = scan(PAGES).filter((c) => MEASURED_LEVELS.includes(c.header.level));
  18. const css = readFileSync(join(PAGES, LIB_DIR, 'demo-tokens.css'), 'utf8') + uiCss(PAGES, scan(PAGES));
  19. // every state and data state, and one picture per value of each control (sizes, variants, presets)
  20. const cells: Cell[] = comps.flatMap((c) => [
  21. ...Object.entries(c.templates).map(([state, markup]) => ({ id: c.header.id, state, level: c.header.level, markup })),
  22. ...Object.entries(c.header.controls).filter(([name]) => !(CONTROL_SKIP[c.header.id] ?? []).includes(name)).flatMap(([name, ctl]) =>
  23. variants(c, name, ctl).map(([value, markup]) => ({ id: c.header.id, state: `${name}=${value}`, level: c.header.level, markup }))),
  24. ]);
  25. const failures = runChrome(chrome!, overflowPage(cells, css));
  26. for (const c of comps) {
  27. test(c.header.id, () => {
  28. const mine = failures.filter((f) => f.id === c.header.id).map((f) => `${f.state}: ${f.what}`);
  29. expect(mine).toEqual([]);
  30. });
  31. }
  32. });