@terpjs/react-core 0.21.0 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,14 +9,23 @@ import type { DataViewPaginationState } from "./hooks/useDataViewState";
9
9
 
10
10
  export interface DataViewPaginationProps {
11
11
  pagination: DataViewPaginationState;
12
- totalCount: number;
12
+ /** How many rows match, or `undefined` while that is not known yet. */
13
+ totalCount: number | undefined;
13
14
  onPaginationChange: (pagination: DataViewPaginationState) => void;
14
15
  }
15
16
 
16
17
  /**
17
- * The footer pagination bar: "X–Y of Z results", the current page / page count, and
18
+ * The footer pagination bar: "X-Y of Z results", the current page / page count, and
18
19
  * first / prev / next / last controls (disabled at bounds; page controls hidden when
19
20
  * there is only one page).
21
+ *
22
+ * **An unknown total renders as nothing, never as zero.** The bar used to compute its
23
+ * range from a `totalCount` that was `0` until the first query answered, so a fresh view
24
+ * asserted "0-0 of 0 results" underneath its own loading skeleton -- a count stated with
25
+ * authority, next to a placeholder admitting there is no data yet, and wrong as often as
26
+ * not. `useResource` drew this distinction in 0.17.0 ("unknown is a real answer and must
27
+ * not render as zero"); this is the same one, one component over. The bar keeps its box
28
+ * either way, so nothing moves when the number arrives.
20
29
  */
21
30
  export function DataViewPagination({
22
31
  pagination,
@@ -25,10 +34,11 @@ export function DataViewPagination({
25
34
  }: DataViewPaginationProps) {
26
35
  const { strings, format } = useDataViewText();
27
36
 
28
- const pageCount = Math.max(1, Math.ceil(totalCount / pagination.pageSize));
37
+ const known = totalCount !== undefined;
38
+ const pageCount = Math.max(1, Math.ceil((totalCount ?? 0) / pagination.pageSize));
29
39
  const pageIndex = Math.min(pagination.pageIndex, pageCount - 1);
30
- const from = totalCount === 0 ? 0 : pageIndex * pagination.pageSize + 1;
31
- const to = Math.min(totalCount, (pageIndex + 1) * pagination.pageSize);
40
+ const from = !known || totalCount === 0 ? 0 : pageIndex * pagination.pageSize + 1;
41
+ const to = Math.min(totalCount ?? 0, (pageIndex + 1) * pagination.pageSize);
32
42
 
33
43
  const goTo = (index: number) => onPaginationChange({ ...pagination, pageIndex: index });
34
44
  const atFirst = pageIndex === 0;
@@ -36,7 +46,7 @@ export function DataViewPagination({
36
46
 
37
47
  return (
38
48
  <div data-terp="dataview-pagination">
39
- <span>{format(strings.resultsRange, { from, to, total: totalCount })}</span>
49
+ <span>{known ? format(strings.resultsRange, { from, to, total: totalCount }) : null}</span>
40
50
  {/* aria-disabled, not disabled, and the difference is where focus goes. Each of these
41
51
  four buttons has a bound condition recomputed from what its own click just changed, so
42
52
  pressing "next" until the last page disabled the very control the user was operating —
@@ -44,7 +54,7 @@ export function DataViewPagination({
44
54
  keyboard user paging to the end lost their place in the document at the exact moment
45
55
  they arrived. Kept focusable and announced as disabled instead, with the handler inert
46
56
  on the bound; the sheet paints [aria-disabled="true"] identically to :disabled. */}
47
- {pageCount > 1 && (
57
+ {known && pageCount > 1 && (
48
58
  <span data-terp="dataview-pager">
49
59
  <span>{format(strings.pageOf, { page: pageIndex + 1, pages: pageCount })}</span>
50
60
  <button
@@ -4,7 +4,16 @@ import type { DataViewQuery, DataViewRepository } from "../types";
4
4
 
5
5
  export interface UseDataViewQueryResult<T> {
6
6
  rows: T[];
7
- totalCount: number;
7
+ /**
8
+ * How many rows match, or `undefined` while that is genuinely not known yet -- before
9
+ * the first query answers, and after one fails.
10
+ *
11
+ * Not `0`, which is a different answer and a wrong one: a footer reading "0-0 of 0
12
+ * results" beside a loading skeleton states a fact the app has not been told. This is
13
+ * the same distinction `Resource.total` draws for `useResource` (0.17.0), one component
14
+ * over, and for the same reason -- unknown is a real answer and must not render as zero.
15
+ */
16
+ totalCount: number | undefined;
8
17
  /** True until the first page for this repository has resolved (skeleton state). */
9
18
  isLoading: boolean;
10
19
  /** True while any query is in flight (subtle refresh indicator; stale data stays). */
@@ -24,7 +33,7 @@ export function useDataViewQuery<T>(
24
33
  query: DataViewQuery,
25
34
  ): UseDataViewQueryResult<T> {
26
35
  const [rows, setRows] = useState<T[]>([]);
27
- const [totalCount, setTotalCount] = useState(0);
36
+ const [totalCount, setTotalCount] = useState<number | undefined>(undefined);
28
37
  const [isLoading, setIsLoading] = useState(true);
29
38
  const [isFetching, setIsFetching] = useState(true);
30
39
  const [error, setError] = useState<unknown>(null);
@@ -56,6 +65,10 @@ export function useDataViewQuery<T>(
56
65
  if (!active || controller.signal.aborted) {
57
66
  return;
58
67
  }
68
+ // The count is not carried over from a previous success: a failed refetch knows
69
+ // nothing about how many rows match now, and saying the old number would be a
70
+ // guess presented as a fact.
71
+ setTotalCount(undefined);
59
72
  setError(caught);
60
73
  setIsLoading(false);
61
74
  setIsFetching(false);
@@ -0,0 +1,54 @@
1
+ import { describe, expect, it } from "vitest";
2
+
3
+ import { routeFieldErrors } from "./fieldErrors";
4
+ import { ApiError } from "./unwrap";
5
+
6
+ function failure(fields: Record<string, string>): ApiError {
7
+ return new ApiError("Kan niet opslaan.", { status: 422, code: "validation_failed", fields });
8
+ }
9
+
10
+ describe("routeFieldErrors", () => {
11
+ it("hands back the reasons this form actually renders", () => {
12
+ const { shown, leftover } = routeFieldErrors(
13
+ failure({ name: "Naam is verplicht.", description: "Te lang." }),
14
+ ["name", "description"],
15
+ );
16
+ expect(shown).toEqual({ name: "Naam is verplicht.", description: "Te lang." });
17
+ expect(leftover).toBe(false);
18
+ });
19
+
20
+ it("reports a reason naming a field the form has no input for", () => {
21
+ // The whole point of the second return value. Without it a caller writes "if there
22
+ // are fields, set them and return", and a reason it cannot show sets state nobody
23
+ // reads AND suppresses the toast — the user presses Save and nothing happens at all.
24
+ const { shown, leftover } = routeFieldErrors(
25
+ failure({ name: "Naam is verplicht.", tenant_id: "Onbekende organisatie." }),
26
+ ["name"],
27
+ );
28
+ expect(shown).toEqual({ name: "Naam is verplicht." });
29
+ expect(leftover).toBe(true);
30
+ });
31
+
32
+ it("reports leftover even when it can show nothing at all", () => {
33
+ // The worst case for the naive version: every reason is unshowable, so `shown` is
34
+ // empty and a caller keying off "did we set any fields" falls through correctly only
35
+ // because `leftover` said so.
36
+ const { shown, leftover } = routeFieldErrors(failure({ tenant_id: "Onbekend." }), ["name"]);
37
+ expect(shown).toEqual({});
38
+ expect(leftover).toBe(true);
39
+ });
40
+
41
+ it("treats a failure that names no field as nothing to route", () => {
42
+ const { shown, leftover } = routeFieldErrors(failure({}), ["name"]);
43
+ expect(shown).toEqual({});
44
+ expect(leftover).toBe(false);
45
+ });
46
+
47
+ it("is inert for anything that is not an ApiError", () => {
48
+ // A thrown string, a TypeError from the caller's own code: there is nothing to read,
49
+ // and guessing would put a message under a field the server never mentioned.
50
+ for (const thrown of [new Error("boom"), "boom", null, undefined]) {
51
+ expect(routeFieldErrors(thrown, ["name"])).toEqual({ shown: {}, leftover: false });
52
+ }
53
+ });
54
+ });
@@ -1,4 +1,4 @@
1
- import { ApiError } from "../unwrap";
1
+ import { ApiError } from "./unwrap";
2
2
 
3
3
  /** What a form should do with a failure: what to put on inputs, and whether anything is left over. */
4
4
  export interface RoutedFieldErrors {
@@ -24,7 +24,24 @@ export interface RoutedFieldErrors {
24
24
  * copy. `GroupDetail` already had it right by naming its one key and falling through to the toast
25
25
  * when the server named a different one; this is that discipline, for a form with several.
26
26
  *
27
- * Not exported from the package. It becomes public API when something outside `admin/` needs it.
27
+ * Public since 0.22.0, on the condition its previous note set: it becomes package surface when
28
+ * something outside `admin/` needs it, and an app wiring `ApiError.fields` into its own forms is
29
+ * that. Copying it is what produces the hole above, because the leftover branch is the half a
30
+ * reader does not know to write.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const RENDERED = ["name", "description"];
35
+ * try {
36
+ * await unwrap(client.POST("/api/v1/groups/", { body }));
37
+ * } catch (error) {
38
+ * const { shown, leftover } = routeFieldErrors(error, RENDERED);
39
+ * setFieldErrors(shown);
40
+ * if (leftover || Object.keys(shown).length === 0) {
41
+ * toast.error(message(error)); // never leave the user with nothing
42
+ * }
43
+ * }
44
+ * ```
28
45
  */
29
46
  export function routeFieldErrors(
30
47
  error: unknown,
package/src/index.ts CHANGED
@@ -158,6 +158,9 @@ export { Markdown } from "./ui/Markdown";
158
158
  export type { MarkdownProps } from "./ui/Markdown";
159
159
  export { saveBlob, useEndpointDownload, fetchDownload, downloadUrl } from "./download";
160
160
  export { copyText, useCopyToClipboard, COPIED_FEEDBACK_MS } from "./clipboard";
161
+ export { routeFieldErrors } from "./fieldErrors";
162
+ export type { RoutedFieldErrors } from "./fieldErrors";
163
+ export { randomUuid, RandomUuidUnavailableError } from "./randomUuid";
161
164
  export type { CopyToClipboard } from "./clipboard";
162
165
  export type { DownloadTarget } from "./download";
163
166
  export { Heading, Text, Code, Link } from "./typography";
@@ -168,6 +171,7 @@ export type {
168
171
  TextProps,
169
172
  TextTone,
170
173
  TextSize,
174
+ TextWeight,
171
175
  CodeProps,
172
176
  LinkProps,
173
177
  } from "./typography";
@@ -207,6 +207,7 @@ const MARKERS = [
207
207
  "page-description",
208
208
  "page-header",
209
209
  "page-heading",
210
+ "page-meta",
210
211
  "page-title",
211
212
  "popover",
212
213
  "popover-panel",
@@ -0,0 +1,78 @@
1
+ import { afterEach, describe, expect, it, vi } from "vitest";
2
+
3
+ import { randomUuid, RandomUuidUnavailableError } from "./randomUuid";
4
+
5
+ const V4 = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
6
+
7
+ /** Swap the ambient `crypto` for the duration of a case. */
8
+ function withCrypto(replacement: unknown): void {
9
+ vi.stubGlobal("crypto", replacement);
10
+ }
11
+
12
+ afterEach(() => {
13
+ vi.unstubAllGlobals();
14
+ });
15
+
16
+ describe("randomUuid", () => {
17
+ it("uses the native generator where the context is secure", () => {
18
+ const randomUUID = vi.fn(() => "11111111-2222-4333-8444-555555555555");
19
+ withCrypto({ randomUUID, getRandomValues: vi.fn() });
20
+ expect(randomUuid()).toBe("11111111-2222-4333-8444-555555555555");
21
+ expect(randomUUID).toHaveBeenCalledOnce();
22
+ });
23
+
24
+ it("produces a well-formed v4 with randomUUID absent, as on an http origin", () => {
25
+ // The case the whole module exists for. crypto.randomUUID is secure-context-only and
26
+ // lib.dom declares it unconditionally, so this shape type-checks and throws a
27
+ // synchronous TypeError in a browser -- and never on localhost, so no test sees it.
28
+ const real = globalThis.crypto;
29
+ withCrypto({ getRandomValues: real.getRandomValues.bind(real) });
30
+ for (let i = 0; i < 50; i += 1) {
31
+ expect(randomUuid()).toMatch(V4);
32
+ }
33
+ });
34
+
35
+ it("pins the version and variant bits rather than emitting 128 loose bits", () => {
36
+ // Without the two masks the value merely looks like a UUID, and anything reading its
37
+ // version field gets a nonsense answer. Feed all-zero and all-one bytes: the only
38
+ // digits that must not follow the input are those two.
39
+ for (const fill of [0x00, 0xff]) {
40
+ withCrypto({
41
+ getRandomValues: (array: Uint8Array) => {
42
+ array.fill(fill);
43
+ return array;
44
+ },
45
+ });
46
+ const value = randomUuid();
47
+ expect(value).toMatch(V4);
48
+ expect(value[14], "the version nibble is always 4").toBe("4");
49
+ expect("89ab", "the variant nibble is 8, 9, a or b").toContain(value[19]);
50
+ }
51
+ });
52
+
53
+ it("does not repeat itself", () => {
54
+ const real = globalThis.crypto;
55
+ withCrypto({ getRandomValues: real.getRandomValues.bind(real) });
56
+ const seen = new Set(Array.from({ length: 500 }, () => randomUuid()));
57
+ expect(seen.size).toBe(500);
58
+ });
59
+
60
+ it("refuses rather than falling back to a weaker source", () => {
61
+ // No Math.random path, deliberately: a UUID standing in for an idempotency key is a
62
+ // value a collision corrupts, so quietly degrading its entropy to keep the call site
63
+ // quiet is the "it worked" this seam exists to refuse.
64
+ withCrypto(undefined);
65
+ expect(() => randomUuid()).toThrow(RandomUuidUnavailableError);
66
+
67
+ withCrypto({});
68
+ expect(() => randomUuid()).toThrow(RandomUuidUnavailableError);
69
+
70
+ withCrypto({ randomUUID: "not a function", getRandomValues: undefined });
71
+ expect(() => randomUuid()).toThrow(RandomUuidUnavailableError);
72
+ });
73
+
74
+ it("says why it refused", () => {
75
+ withCrypto(undefined);
76
+ expect(() => randomUuid()).toThrow(/crypto.randomUUID nor crypto.getRandomValues/);
77
+ });
78
+ });
@@ -0,0 +1,111 @@
1
+ /**
2
+ * Generating a UUID, once, for everyone.
3
+ *
4
+ * `crypto.randomUUID` is not the API it looks like. `lib.dom` declares it
5
+ * unconditionally on `Crypto`, and it exists only in a **secure context** — so on a
6
+ * plain-http origin that is not localhost, `crypto.randomUUID()` is a call on
7
+ * `undefined`. That throws a **synchronous** `TypeError`, TypeScript reports nothing
8
+ * because as far as its type says the method is there, and a test suite running on
9
+ * localhost never sees it either: localhost *is* a secure context, so the whole class is
10
+ * invisible to the type checker, to review, and to CI at once.
11
+ *
12
+ * Same shape as the clipboard seam, and the same argument (ADR 0096 §3): a browser API
13
+ * with a footgun, wrapped once. What makes it worth a seam rather than a lesson is that
14
+ * the platform routes you here — the idempotency capability's contract is a
15
+ * **client-generated** `Idempotency-Key` header, so an app wiring retry-safety reaches
16
+ * for exactly this method — and the topology it breaks in is the one Terp itself ships:
17
+ * the compose files publish plain http, so any deployment reached by hostname rather than
18
+ * localhost is an insecure context.
19
+ *
20
+ * **The fallback never weakens the value.** `crypto.getRandomValues` is *not*
21
+ * secure-context-gated and is available wherever `crypto` is, so an insecure context
22
+ * still gets a cryptographically random v4 — assembled here rather than by the missing
23
+ * method. There is deliberately no `Math.random` path: a UUID standing in for an
24
+ * idempotency key or an optimistic row id is a value collisions corrupt, and silently
25
+ * degrading its entropy to keep a call site quiet is the kind of "it worked" the clipboard
26
+ * seam exists to refuse. With no `crypto` at all this throws, because there is nothing
27
+ * honest left to return.
28
+ */
29
+
30
+ /** Two hex digits per byte, precomputed: the formatting is 16 lookups, not 16 `padStart`s. */
31
+ const HEX_BYTE = Array.from({ length: 256 }, (_, byte) => (byte + 0x100).toString(16).slice(1));
32
+
33
+ /**
34
+ * No source of cryptographic randomness is reachable, so no UUID can be produced.
35
+ *
36
+ * Thrown rather than papered over with `Math.random`: see the module docstring. In a
37
+ * browser this means `crypto` itself is missing, which is a far older environment than the
38
+ * insecure-context case this module exists for — that one is handled and never reaches
39
+ * here.
40
+ */
41
+ export class RandomUuidUnavailableError extends Error {
42
+ constructor() {
43
+ super(
44
+ "No cryptographic randomness is available: neither crypto.randomUUID nor " +
45
+ "crypto.getRandomValues could be reached. A UUID is not generated from a weaker " +
46
+ "source, because the values it stands in for are ones a collision corrupts.",
47
+ );
48
+ this.name = "RandomUuidUnavailableError";
49
+ }
50
+ }
51
+
52
+ /**
53
+ * A cryptographically random v4 UUID, in every context — secure or not.
54
+ *
55
+ * Use it instead of `crypto.randomUUID()`:
56
+ *
57
+ * ```ts
58
+ * const key = randomUuid();
59
+ * await unwrap(client.POST("/api/v1/invoices/", { body, headers: { "Idempotency-Key": key } }));
60
+ * ```
61
+ *
62
+ * Uses `crypto.randomUUID` where it exists and assembles the same thing from
63
+ * `crypto.getRandomValues` where it does not, so the entropy is identical either way and
64
+ * only the assembly moves. Throws {@link RandomUuidUnavailableError} when neither is
65
+ * reachable.
66
+ */
67
+ export function randomUuid(): string {
68
+ // Read through globalThis: `crypto` as a bare global is a ReferenceError where it is
69
+ // absent, and the point of this function is to answer that question rather than raise it.
70
+ const source: Crypto | undefined = globalThis.crypto;
71
+ if (source === undefined) {
72
+ throw new RandomUuidUnavailableError();
73
+ }
74
+ if (typeof source.randomUUID === "function") {
75
+ return source.randomUUID();
76
+ }
77
+ if (typeof source.getRandomValues !== "function") {
78
+ throw new RandomUuidUnavailableError();
79
+ }
80
+
81
+ const bytes = source.getRandomValues(new Uint8Array(16));
82
+ // The two fields RFC 9562 fixes: version 4 in the high nibble of octet 6, and the
83
+ // variant's `10` in the top bits of octet 8. Without these the value is 128 random bits
84
+ // that merely look like a UUID, and anything parsing its version reads a nonsense one.
85
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
86
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
87
+
88
+ const hex = (index: number): string => HEX_BYTE[bytes[index]];
89
+ return (
90
+ hex(0) +
91
+ hex(1) +
92
+ hex(2) +
93
+ hex(3) +
94
+ "-" +
95
+ hex(4) +
96
+ hex(5) +
97
+ "-" +
98
+ hex(6) +
99
+ hex(7) +
100
+ "-" +
101
+ hex(8) +
102
+ hex(9) +
103
+ "-" +
104
+ hex(10) +
105
+ hex(11) +
106
+ hex(12) +
107
+ hex(13) +
108
+ hex(14) +
109
+ hex(15)
110
+ );
111
+ }
@@ -1,6 +1,7 @@
1
1
  // @vitest-environment jsdom
2
2
  import { afterEach, describe, expect, it } from "vitest";
3
3
 
4
+ import { ROOMY_VIEWPORT_QUERY } from "./breakpoints";
4
5
  import { TERP_STYLES_ID, TERP_STYLES_CSS, injectTerpStyles } from "./styles";
5
6
 
6
7
  /** The sheet with comments removed — prose must not satisfy a structural assertion. */
@@ -946,6 +947,22 @@ describe("cascade structure", () => {
946
947
  expect(base.slice(termAt, base.indexOf("}", termAt))).not.toContain("color:");
947
948
  });
948
949
 
950
+ it("gives body copy an emphasis step without re-weighting the copy that asks for none", () => {
951
+ const base = layerBody("terp.base");
952
+ // Both steps read the published weight tokens rather than a literal.
953
+ expect(base).toContain(
954
+ '[data-terp="text"][data-weight="medium"] { font-weight: var(--font-weight-medium); }',
955
+ );
956
+ expect(base).toContain(
957
+ '[data-terp="text"][data-weight="semibold"] { font-weight: var(--font-weight-semibold); }',
958
+ );
959
+ // The base rule states no weight on purpose: a Text that asks for none keeps
960
+ // inheriting what it inherited before the axis existed, so nothing re-renders.
961
+ const textAt = base.indexOf('[data-terp="text"] {');
962
+ expect(textAt, "the base text rule should exist").toBeGreaterThan(-1);
963
+ expect(base.slice(textAt, base.indexOf("}", textAt))).not.toContain("font-weight");
964
+ });
965
+
949
966
  it("keeps a Card's actions slot on the title's line, description or not", () => {
950
967
  // The measured inconsistency: `actions` is documented as a header-row slot and delivered
951
968
  // one only while `description` was unset. The heading declared min-width: 0 alone, so it
@@ -986,6 +1003,89 @@ describe("cascade structure", () => {
986
1003
  expect(base.slice(headerAt, base.indexOf("}", headerAt))).toContain("align-items: center");
987
1004
  });
988
1005
 
1006
+ it("lays the page band out in areas, and spends a second row only when one is earned", () => {
1007
+ // What this replaced, and why the argument had to change shape. The band was a wrapping
1008
+ // flex row, and the bug it kept producing was always the same one: flex collects items
1009
+ // into lines using HYPOTHETICAL main sizes and only shrinks what is already on a line, so
1010
+ // any item whose max-content was wide -- a deep trail, an unwrapped sentence -- took the
1011
+ // line and pushed the action cluster onto the next one. A zero basis bought the single
1012
+ // row back, and measured 48px against 76px, which is why it was pinned here.
1013
+ //
1014
+ // Two things that basis could never fix, both of which arrive the moment the band DOES
1015
+ // wrap. Wrap order follows source order, so the meta group and the cluster cannot share a
1016
+ // row while staying two groups. And justify-content: space-between then has free space to
1017
+ // distribute, which scatters a page's buttons across the full width -- or left-aligns a
1018
+ // single cluster on the row whose whole job was to right-align it.
1019
+ //
1020
+ // Areas answer both by construction: nothing is placed by flow and no free space is
1021
+ // distributed anywhere, so neither failure has a place to happen.
1022
+ const base = layerBody("terp.base");
1023
+ const headerAt = base.indexOf('[data-terp="page-header"] {');
1024
+ expect(headerAt, "page-header should have a base rule").toBeGreaterThan(-1);
1025
+ const header = base.slice(headerAt, base.indexOf("}", headerAt));
1026
+ expect(header, "the band places by area, never by flow").toContain("display: grid");
1027
+ // minmax(0, 1fr) rather than 1fr: a grid track's automatic minimum is its content's, so a
1028
+ // long unbreakable title would refuse to shrink past it and push the cluster out of the
1029
+ // band. This is the same job the old zero flex basis did, done by the track instead.
1030
+ expect(header, "the trail column must be allowed to shrink below its content").toContain(
1031
+ "grid-template-columns: minmax(0, 1fr) auto",
1032
+ );
1033
+ expect(header, "with nothing else to show, the band is one row").toContain(
1034
+ 'grid-template-areas: "trail actions"',
1035
+ );
1036
+ // The second row, and the reason it is conditional. A page with badges or a lead line
1037
+ // already spends a row on them, so the cluster joining them costs no height at all -- and
1038
+ // it buys the trail the whole first row, which is what stops a deep trail truncating. A
1039
+ // page with neither keeps the single row, and with it the measurement the chrome is held
1040
+ // to further down this file: the band matches the app header above it.
1041
+ const metaAt = base.indexOf('[data-terp="page-header"][data-has-meta] {');
1042
+ expect(metaAt, "the two-row band should have a rule of its own").toBeGreaterThan(-1);
1043
+ const withMeta = base.slice(metaAt, base.indexOf("}", metaAt));
1044
+ expect(withMeta, "the trail owns the first row outright once there is a second").toContain(
1045
+ '"trail trail"',
1046
+ );
1047
+ expect(withMeta, "meta sits left of the cluster on the second row").toContain(
1048
+ '"meta actions"',
1049
+ );
1050
+ // Same-height lines. 1fr rather than auto, and in a box whose height nobody declared that
1051
+ // is not a share of anything: fr rows in an indefinite container resolve to the LARGEST
1052
+ // row's content, so both lines come out at the taller one. Two content-sized rows would be
1053
+ // a short trail line above a tall control line, which reads as two bands rather than one
1054
+ // of two lines. The computed half is next door in the workbench, which measures the
1055
+ // resolved tracks rather than the box: a total carries the gap and the border too, so only
1056
+ // the tracks can say whether the two lines actually agree.
1057
+ expect(withMeta, "a band of two lines gives them the same height").toContain(
1058
+ "grid-auto-rows: 1fr",
1059
+ );
1060
+ // The left group generates no box, which is what lets its two children be grid items of
1061
+ // the BAND and therefore sit on different rows. The marker survives for the scanner.
1062
+ const headingAt = base.indexOf('[data-terp="page-heading"] {');
1063
+ expect(headingAt, "page-heading should have a base rule").toBeGreaterThan(-1);
1064
+ const heading = base.slice(headingAt, base.indexOf("}", headingAt));
1065
+ expect(heading, "a boxed wrapper would put the trail and the meta in one cell").toContain(
1066
+ "display: contents",
1067
+ );
1068
+ // The lead line is written as a correction, not a rule: hidden everywhere, shown again
1069
+ // above the SECOND cutover. That is what makes three regions out of two queries -- the
1070
+ // middle one is the width at which this correction has not applied yet.
1071
+ const descAt = base.indexOf('[data-terp="page-description"] {');
1072
+ expect(descAt, "page-description should have a base rule").toBeGreaterThan(-1);
1073
+ const description = base.slice(descAt, base.indexOf("}", descAt));
1074
+ expect(description, "the lead line is the first thing to go when room is short").toContain(
1075
+ "display: none",
1076
+ );
1077
+ const roomy = base.indexOf(`@media ${ROOMY_VIEWPORT_QUERY}`);
1078
+ expect(roomy, "the lead line comes back above the second cutover").toBeGreaterThan(descAt);
1079
+ // And the truncation, which still matters on the row it does get: the sentence shares
1080
+ // that row with the badges, so its max-content must not decide the row's width.
1081
+ const shown = base.slice(base.indexOf('[data-terp="page-description"] {', roomy));
1082
+ expect(shown).toContain("display: block");
1083
+ const full = base.slice(base.lastIndexOf('[data-terp="page-description"] {'));
1084
+ expect(full).toContain("min-width: 0");
1085
+ expect(full).toContain("white-space: nowrap");
1086
+ expect(full).toContain("text-overflow: ellipsis");
1087
+ });
1088
+
989
1089
  it("gives the breadcrumb trail one line box, leaf included", () => {
990
1090
  // The trail is a row of items that get CENTRED, so two line heights in it are two
991
1091
  // baselines. The leaf declared 1.3 while its ancestors inherited `normal`: measured at