ShtukbaseStandard
package file→ .shtukbase/packages/shtukbase-ui-react/test/overflow.test.ts

test/overflow.test.ts

24 lines, 1.5 KB.

  1. // Text never leaves a component, as React draws it: every state of every React component, rendered to markup, with its
  2. // texts replaced by long Russian text, measured in headless Chrome by the overflow page of shtukbase-ui-html (the look is
  3. // its ui.css). Skipped where no Chrome 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 { type Cell, findChrome, MEASURED_LEVELS, overflowPage, runChrome } from '../../shtukbase-ui-html/lib/overflow.ts';
  8. import { HTML_PACKAGE, libraryComponents, load, renderState } from './lib.ts';
  9. const chrome = findChrome();
  10. const DESIGN = join(HTML_PACKAGE, 'pages', 'design', 'shtukbase-ui-html');
  11. describe.skipIf(!chrome)('no text overflows in a React state, with long Russian text', async () => {
  12. const css = readFileSync(join(DESIGN, 'demo-tokens.css'), 'utf8') + readFileSync(join(DESIGN, 'ui.css'), 'utf8');
  13. const loaded = (await Promise.all(libraryComponents().map((c) => load(c.id)))).filter((c) => MEASURED_LEVELS.includes(c.header.level));
  14. const cells: Cell[] = loaded.flatMap((c) =>
  15. c.states.names.map((state) => ({ id: c.id, state, level: c.header.level, markup: renderState(c, state) })));
  16. const failures = runChrome(chrome!, overflowPage(cells, css));
  17. for (const c of loaded) {
  18. test(c.id, () => {
  19. expect(failures.filter((f) => f.id === c.id).map((f) => `${f.state}: ${f.what}`)).toEqual([]);
  20. });
  21. }
  22. });