ShtukbaseStandard
archivo del paquete→ .shtukbase/packages/shtukbase-ui-react/test/parity.test.ts

test/parity.test.ts

49 líneas, 2.5 KB.

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

  1. // The React library against the HTML library: the same ids, the same headers, and for every state and status of every
  2. // component the React markup carries the markup of the HTML template (tags, text, attributes, classes, custom properties).
  3. // The HTML library is the package shtukbase-ui-html (task DSN-4); these tests read its component files from there.
  4. import { describe, expect, test } from 'bun:test';
  5. import { HTML_COMPONENTS, LEVEL_DIRS, compareFragment, htmlComponents, libraryComponents, load, renderState } from './lib.ts';
  6. const html = htmlComponents();
  7. // The package shtukbase-ui-html is built in parallel (DSN-4); until its components are on main there is nothing to compare with.
  8. // Set SB_UI_HTML_COMPONENTS to the folder of its components to run these tests against a working copy.
  9. if (html.length === 0) test.todo(`compare with the HTML library: no components found in ${HTML_COMPONENTS}`);
  10. describe.skipIf(html.length === 0)('the same set of components', () => {
  11. const mine = libraryComponents().map((c) => c.id).sort();
  12. const theirs = html.map((c) => c.id).sort();
  13. test('every HTML component has a React component', () => {
  14. expect(theirs.filter((id) => !mine.includes(id))).toEqual([]);
  15. });
  16. test('every React component is in the HTML library', () => {
  17. expect(mine.filter((id) => !theirs.includes(id))).toEqual([]);
  18. });
  19. test('each lies in the folder of its level', () => {
  20. const lib = libraryComponents();
  21. for (const c of html) expect(lib.find((l) => l.id === c.id)?.dir, c.id).toBe(LEVEL_DIRS[c.header.level]);
  22. });
  23. });
  24. for (const c of html) {
  25. describe(`${c.id}: the same as the HTML template`, async () => {
  26. const mine = await load(c.id);
  27. test('the header is the same', () => {
  28. for (const f of ['level', 'controls', 'states', 'status', 'uses', 'parts'] as const)
  29. expect(mine.header[f], `${c.id} header ${f}`).toEqual(c.header[f]);
  30. });
  31. test('a state for every state and status of the header, and no other', () => {
  32. const wanted = [...c.header.states, ...c.header.status].sort();
  33. expect([...mine.states.names].sort()).toEqual(wanted);
  34. });
  35. test('the templates are the states and statuses of the header', () => {
  36. expect(Object.keys(c.templates).sort()).toEqual([...c.header.states, ...c.header.status].sort());
  37. });
  38. for (const [name, template] of Object.entries(c.templates)) {
  39. test(`state ${name}`, () => {
  40. const diff = compareFragment(template, renderState(mine, name));
  41. expect(diff, diff.join('\n')).toEqual([]);
  42. });
  43. }
  44. });
  45. }