@simplix-react-ui-kits/site-core 0.1.0 → 0.1.1

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.
Files changed (112) hide show
  1. package/README.md +4 -3
  2. package/dist/account/index.d.ts +1 -1
  3. package/dist/account/index.js +3 -3
  4. package/dist/action/index.d.ts +59 -3
  5. package/dist/action/index.js +82 -0
  6. package/dist/action/index.js.map +1 -1
  7. package/dist/checkout/index.d.ts +1 -1
  8. package/dist/checkout/index.js +1 -1
  9. package/dist/{chunk-BJUU2WTX.js → chunk-EELJOGWB.js} +12 -5
  10. package/dist/chunk-EELJOGWB.js.map +1 -0
  11. package/dist/{chunk-7K476KMZ.js → chunk-EOTYGKKM.js} +3 -3
  12. package/dist/{chunk-7K476KMZ.js.map → chunk-EOTYGKKM.js.map} +1 -1
  13. package/dist/{chunk-FKC262N4.js → chunk-EWBTUSZY.js} +9 -3
  14. package/dist/chunk-EWBTUSZY.js.map +1 -0
  15. package/dist/{chunk-5TFLOQT6.js → chunk-HRRP6HMF.js} +10 -5
  16. package/dist/chunk-HRRP6HMF.js.map +1 -0
  17. package/dist/{chunk-4KFQ26JW.js → chunk-HZGBIIGN.js} +27 -6
  18. package/dist/chunk-HZGBIIGN.js.map +1 -0
  19. package/dist/{chunk-JJQJFRBI.js → chunk-OWQVRM4W.js} +3 -3
  20. package/dist/{chunk-JJQJFRBI.js.map → chunk-OWQVRM4W.js.map} +1 -1
  21. package/dist/{chunk-6S23FFBB.js → chunk-TGG4ZKPG.js} +3 -3
  22. package/dist/{chunk-6S23FFBB.js.map → chunk-TGG4ZKPG.js.map} +1 -1
  23. package/dist/{chunk-JVMJF5JJ.js → chunk-UF2MDCWB.js} +5 -5
  24. package/dist/chunk-UF2MDCWB.js.map +1 -0
  25. package/dist/{chunk-EG6GE3YS.js → chunk-YXASVWY7.js} +3 -3
  26. package/dist/{chunk-EG6GE3YS.js.map → chunk-YXASVWY7.js.map} +1 -1
  27. package/dist/content/index.d.ts +95 -0
  28. package/dist/content/index.js +85 -0
  29. package/dist/content/index.js.map +1 -0
  30. package/dist/form/index.d.ts +229 -8
  31. package/dist/form/index.js +150 -10
  32. package/dist/form/index.js.map +1 -1
  33. package/dist/help/index.d.ts +1 -1
  34. package/dist/help/index.js +6 -6
  35. package/dist/install/index.d.ts +1 -1
  36. package/dist/install/index.js +4 -4
  37. package/dist/legal/index.d.ts +2 -2
  38. package/dist/legal/index.js +5 -5
  39. package/dist/link/index.d.ts +14 -1
  40. package/dist/link/index.js +8 -1
  41. package/dist/link/index.js.map +1 -1
  42. package/dist/marketing/index.d.ts +1 -1
  43. package/dist/page/index.d.ts +2 -2
  44. package/dist/page/index.js +4 -4
  45. package/dist/pricing/index.d.ts +1 -1
  46. package/dist/pricing/index.js +2 -2
  47. package/dist/shell/index.d.ts +1 -1
  48. package/dist/{site-action-B79fuwMb.d.ts → site-action-CPpf8JZl.d.ts} +1 -1
  49. package/dist/{site-page-Dl0A5T1N.d.ts → site-page-DKcjqh9y.d.ts} +7 -2
  50. package/package.json +10 -3
  51. package/src/action/action-tile.style.ts +63 -0
  52. package/src/action/action-tile.tsx +83 -0
  53. package/src/action/index.ts +11 -0
  54. package/src/content/content.style.ts +72 -0
  55. package/src/content/content.tsx +124 -0
  56. package/src/content/index.ts +12 -0
  57. package/src/form/choices.style.ts +16 -0
  58. package/src/form/choices.tsx +28 -5
  59. package/src/form/country-field.tsx +61 -0
  60. package/src/form/date-time.style.ts +26 -0
  61. package/src/form/date-time.tsx +123 -0
  62. package/src/form/dialog.style.ts +4 -2
  63. package/src/form/errors.tsx +16 -4
  64. package/src/form/form.style.ts +8 -0
  65. package/src/form/index.ts +11 -1
  66. package/src/form/phone-field.tsx +98 -0
  67. package/src/form/select.style.ts +6 -1
  68. package/src/form/select.tsx +13 -3
  69. package/src/form/signature.style.ts +20 -0
  70. package/src/form/signature.tsx +46 -0
  71. package/src/link/index.ts +1 -0
  72. package/src/link/mounted-href.ts +16 -0
  73. package/src/page/site-page.style.ts +13 -4
  74. package/src/page/site-page.tsx +8 -3
  75. package/src/styles/designs/base.css +121 -4
  76. package/templates/app-shell.hbs +5 -4
  77. package/dist/chunk-4KFQ26JW.js.map +0 -1
  78. package/dist/chunk-5TFLOQT6.js.map +0 -1
  79. package/dist/chunk-BJUU2WTX.js.map +0 -1
  80. package/dist/chunk-FKC262N4.js.map +0 -1
  81. package/dist/chunk-JVMJF5JJ.js.map +0 -1
  82. package/src/account/account.test.tsx +0 -186
  83. package/src/action/site-action.test.tsx +0 -154
  84. package/src/auth/auth.test.tsx +0 -132
  85. package/src/checkout/checkout.test.tsx +0 -187
  86. package/src/form/choices-field.test.tsx +0 -20
  87. package/src/form/errors.test.tsx +0 -49
  88. package/src/form/form.test.tsx +0 -275
  89. package/src/form/question-focus.test.ts +0 -182
  90. package/src/form/slider.test.tsx +0 -148
  91. package/src/form/typed-text.test.ts +0 -52
  92. package/src/help/article.test.tsx +0 -189
  93. package/src/help/help.test.tsx +0 -215
  94. package/src/help/screen-sketch.test.tsx +0 -59
  95. package/src/install/install.test.tsx +0 -177
  96. package/src/legal/legal.test.tsx +0 -161
  97. package/src/legal/policy.test.tsx +0 -137
  98. package/src/legal/refund.test.tsx +0 -148
  99. package/src/link/routes-in-page.test.ts +0 -26
  100. package/src/link/site-link.test.ts +0 -10
  101. package/src/marketing/marketing.test.tsx +0 -221
  102. package/src/page/site-failure.test.tsx +0 -65
  103. package/src/page/site-page.test.tsx +0 -109
  104. package/src/page/site-read.test.tsx +0 -41
  105. package/src/pricing/pack-card.test.tsx +0 -107
  106. package/src/pricing/pricing.test.tsx +0 -261
  107. package/src/shell/refusal-page.test.ts +0 -19
  108. package/src/shell/site-scheme-param.test.ts +0 -53
  109. package/src/shell/site-scheme-switch.test.ts +0 -80
  110. package/src/shell/site-scheme.test.ts +0 -149
  111. package/src/shell/site-shell.test.tsx +0 -401
  112. package/src/testing/markup.ts +0 -65
@@ -1,80 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import { applySiteScheme, markSiteScheme, SCHEME_SWITCH_ATTRIBUTE, type SchemeQuery, type SchemeTarget } from "./site-scheme";
4
-
5
- /**
6
- * A document element that records, in order, what is done to it, and answers the way a browser
7
- * does: the mark is on the element exactly between its set and its removal.
8
- */
9
- function recordingTarget(dark: boolean) {
10
- const calls: string[] = [];
11
- const attributes = new Map<string, string>();
12
- let isDark = dark;
13
- const target: SchemeTarget = {
14
- classList: {
15
- toggle: (token, force) => {
16
- calls.push(`toggle ${token} ${String(force)} (mark ${attributes.has(SCHEME_SWITCH_ATTRIBUTE) ? "on" : "off"})`);
17
- isDark = force;
18
- return force;
19
- },
20
- contains: () => isDark,
21
- },
22
- style: { colorScheme: "" },
23
- setAttribute: (name, value) => {
24
- calls.push(`set ${name}`);
25
- attributes.set(name, value);
26
- },
27
- removeAttribute: (name) => {
28
- calls.push(`remove ${name}`);
29
- attributes.delete(name);
30
- },
31
- getBoundingClientRect: () => {
32
- calls.push("flush");
33
- return {};
34
- },
35
- };
36
- return { calls, attributes, target };
37
- }
38
-
39
- const quietQuery = (matches: boolean): SchemeQuery => ({ matches, addEventListener: () => {}, removeEventListener: () => {} });
40
-
41
- describe("a change of scheme", () => {
42
- it("is drawn in one frame: marked, swapped, flushed with the mark on, then unmarked", () => {
43
- const light = recordingTarget(false);
44
- markSiteScheme(light.target, true);
45
- expect(light.calls).toEqual([`set ${SCHEME_SWITCH_ATTRIBUTE}`, "toggle dark true (mark on)", "flush", `remove ${SCHEME_SWITCH_ATTRIBUTE}`]);
46
- expect(light.attributes.size).toBe(0);
47
- expect(light.target.style?.colorScheme).toBe("dark");
48
- });
49
-
50
- it("is drawn the same way going back to light", () => {
51
- const dark = recordingTarget(true);
52
- markSiteScheme(dark.target, false);
53
- expect(dark.calls).toEqual([`set ${SCHEME_SWITCH_ATTRIBUTE}`, "toggle dark false (mark on)", "flush", `remove ${SCHEME_SWITCH_ATTRIBUTE}`]);
54
- expect(dark.target.style?.colorScheme).toBe("light");
55
- });
56
-
57
- it("leaves a document that already carries the scheme as it is, with no mark and no flush", () => {
58
- const already = recordingTarget(true);
59
- markSiteScheme(already.target, true);
60
- expect(already.calls).toEqual(["toggle dark true (mark off)"]);
61
- });
62
-
63
- it("marks the change that following the system makes, not the first reading that agrees with the document", () => {
64
- const system = recordingTarget(true);
65
- const stop = applySiteScheme("system", quietQuery(true), system.target);
66
- expect(system.calls.some((call) => call.startsWith("set "))).toBe(false);
67
- stop();
68
- const fixed = recordingTarget(true);
69
- applySiteScheme("light", quietQuery(true), fixed.target);
70
- expect(fixed.calls[0]).toBe(`set ${SCHEME_SWITCH_ATTRIBUTE}`);
71
- });
72
-
73
- it("still marks a target that has no mark to set, which a head script's fake or a minimal target is", () => {
74
- const classes = new Set<string>();
75
- const minimal: SchemeTarget = { classList: { toggle: (token, force) => (force ? classes.add(token) : classes.delete(token), force) }, style: { colorScheme: "" } };
76
- markSiteScheme(minimal, true);
77
- expect(classes.has("dark")).toBe(true);
78
- expect(minimal.style?.colorScheme).toBe("dark");
79
- });
80
- });
@@ -1,149 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import {
4
- applySiteScheme,
5
- followSystemScheme,
6
- parseSiteScheme,
7
- readSiteScheme,
8
- SITE_SCHEME_KEY,
9
- siteSchemeBootstrap,
10
- writeSiteScheme,
11
- type SchemeQuery,
12
- type SchemeStorage,
13
- } from "./site-scheme";
14
-
15
- describe("followSystemScheme", () => {
16
- function fakes(matches: boolean) {
17
- const listeners = new Set<(event: { readonly matches: boolean }) => void>();
18
- const query: SchemeQuery = {
19
- matches,
20
- addEventListener: (_type, listener) => listeners.add(listener),
21
- removeEventListener: (_type, listener) => listeners.delete(listener),
22
- };
23
- const classes = new Set<string>();
24
- const target = { classList: { toggle: (token: string, force: boolean) => (force ? classes.add(token) : classes.delete(token), force) } };
25
- return { query, target, classes, listeners, change: (dark: boolean) => listeners.forEach((listener) => listener({ matches: dark })) };
26
- }
27
-
28
- it("draws the dark scheme exactly while the system asks for it, and follows a later change", () => {
29
- const dark = fakes(true);
30
- followSystemScheme(dark.query, dark.target);
31
- expect(dark.classes.has("dark")).toBe(true);
32
- dark.change(false);
33
- expect(dark.classes.has("dark")).toBe(false);
34
- const light = fakes(false);
35
- light.classes.add("dark");
36
- followSystemScheme(light.query, light.target);
37
- expect(light.classes.has("dark")).toBe(false);
38
- });
39
-
40
- it("stops following once the returned function runs", () => {
41
- const scheme = fakes(false);
42
- const stop = followSystemScheme(scheme.query, scheme.target);
43
- expect(scheme.listeners.size).toBe(1);
44
- stop();
45
- expect(scheme.listeners.size).toBe(0);
46
- scheme.change(true);
47
- expect(scheme.classes.has("dark")).toBe(false);
48
- });
49
- });
50
-
51
- describe("the reader's scheme choice", () => {
52
- function target() {
53
- const classes = new Set<string>();
54
- return { classes, classList: { toggle: (token: string, force: boolean) => (force ? classes.add(token) : classes.delete(token), force) } };
55
- }
56
- function query(matches: boolean): SchemeQuery & { readonly count: () => number } {
57
- const listeners = new Set<unknown>();
58
- return {
59
- matches,
60
- addEventListener: (_type, listener) => listeners.add(listener),
61
- removeEventListener: (_type, listener) => listeners.delete(listener),
62
- count: () => listeners.size,
63
- };
64
- }
65
- function memory(initial: Record<string, string> = {}): SchemeStorage & { readonly values: Map<string, string> } {
66
- const values = new Map(Object.entries(initial));
67
- return {
68
- values,
69
- getItem: (key) => values.get(key) ?? null,
70
- setItem: (key, value) => void values.set(key, value),
71
- removeItem: (key) => void values.delete(key),
72
- };
73
- }
74
-
75
- it("reads only light and dark as a fixed choice; nothing stored, or anything else, is the system's", () => {
76
- expect([parseSiteScheme("light"), parseSiteScheme("dark"), parseSiteScheme(null), parseSiteScheme("true"), parseSiteScheme("")]).toEqual(["light", "dark", "system", "system", "system"]);
77
- });
78
-
79
- it("keeps a fixed choice under its own key and the system's as no value at all", () => {
80
- const storage = memory();
81
- writeSiteScheme(storage, "dark");
82
- expect(storage.values.get(SITE_SCHEME_KEY)).toBe("dark");
83
- expect(readSiteScheme(storage)).toBe("dark");
84
- writeSiteScheme(storage, "system");
85
- expect(storage.values.has(SITE_SCHEME_KEY)).toBe(false);
86
- expect(readSiteScheme(storage)).toBe("system");
87
- expect(SITE_SCHEME_KEY).not.toMatch(/:$/);
88
- });
89
-
90
- it("answers the system's when the store refuses to be read or written", () => {
91
- const refusing: SchemeStorage = {
92
- getItem: () => {
93
- throw new Error("blocked");
94
- },
95
- setItem: () => {
96
- throw new Error("blocked");
97
- },
98
- removeItem: () => {
99
- throw new Error("blocked");
100
- },
101
- };
102
- expect(readSiteScheme(refusing)).toBe("system");
103
- expect(() => writeSiteScheme(refusing, "dark")).not.toThrow();
104
- });
105
-
106
- it("draws a fixed choice whatever the system says, and follows the system only for the system's", () => {
107
- const darkSystem = query(true);
108
- const light = target();
109
- applySiteScheme("light", darkSystem, light);
110
- expect(light.classes.has("dark")).toBe(false);
111
- expect(darkSystem.count()).toBe(0);
112
- const lightSystem = query(false);
113
- const dark = target();
114
- applySiteScheme("dark", lightSystem, dark);
115
- expect(dark.classes.has("dark")).toBe(true);
116
- const followed = target();
117
- const stop = applySiteScheme("system", darkSystem, followed);
118
- expect(followed.classes.has("dark")).toBe(true);
119
- expect(darkSystem.count()).toBe(1);
120
- stop();
121
- expect(darkSystem.count()).toBe(0);
122
- });
123
-
124
- it("opens the page before the first paint exactly as the choice draws it, from the same key", () => {
125
- // The bootstrap is the text a page puts in its head; it runs here against fakes of what it reads.
126
- const run = (stored: string | null, systemDark: boolean, key?: string) => {
127
- const html = target();
128
- const storage = memory(stored === null ? {} : { [key ?? SITE_SCHEME_KEY]: stored });
129
- new Function("localStorage", "window", "document", siteSchemeBootstrap(key))(storage, { matchMedia: () => ({ matches: systemDark }) }, { documentElement: html });
130
- return html.classes.has("dark");
131
- };
132
- for (const stored of ["light", "dark", null, "stale"]) {
133
- for (const systemDark of [true, false]) {
134
- const drawn = target();
135
- applySiteScheme(parseSiteScheme(stored), query(systemDark), drawn);
136
- expect(run(stored, systemDark)).toBe(drawn.classes.has("dark"));
137
- }
138
- }
139
- expect(siteSchemeBootstrap()).toContain(JSON.stringify(SITE_SCHEME_KEY));
140
- expect(run("dark", false, "other.prefs:scheme")).toBe(true);
141
- const unreadable = target();
142
- new Function("localStorage", "window", "document", siteSchemeBootstrap())(
143
- { getItem: () => { throw new Error("blocked"); } },
144
- { matchMedia: () => ({ matches: true }) },
145
- { documentElement: unreadable },
146
- );
147
- expect(unreadable.classes.has("dark")).toBe(true);
148
- });
149
- });
@@ -1,401 +0,0 @@
1
- import { renderToStaticMarkup } from "react-dom/server";
2
- import { describe, expect, it } from "vitest";
3
-
4
- import type { SiteLinkProps } from "../link/site-link";
5
- import { bySlot, tabStops, unmarked } from "../testing/markup";
6
- import { avatarInitial, barMenuActions, menuKeyTarget, SiteBar, SiteBarMenuItems, type SiteBarProps } from "./site-bar";
7
- import { siteActionStyle } from "../action/site-action.style";
8
- import {
9
- siteFooterLinkStyle,
10
- siteBarAccountNameStyle,
11
- siteBarMenuStyle,
12
- siteBarMoreStyle,
13
- siteBarNavStyle,
14
- siteBarStyle,
15
- siteFooterStyle,
16
- siteWindowStyle,
17
- } from "./site-shell.style";
18
- import { SiteFooter } from "./site-footer";
19
- import { followHeading, pageHeading, SiteBand, SiteWindow, type HeadingObserver } from "./site-window";
20
-
21
- const links: SiteBarProps["links"] = [
22
- { key: "intro", label: "Product", href: "/" },
23
- { key: "pricing", label: "Pricing", href: "/pricing", current: true },
24
- { key: "download", label: "Download", href: "/download" },
25
- { key: "help", label: "Help", href: "/help" },
26
- ];
27
-
28
- const bar = (props: Partial<SiteBarProps> = {}) => (
29
- <SiteBar
30
- brand={<svg aria-hidden="true" data-slot="brand-mark" />}
31
- brandHref="/"
32
- brandLabel="Home"
33
- links={links}
34
- navLabel="Site"
35
- moreLabel="More pages"
36
- actions={[{ id: "start", label: "Start free", href: "/signup" }]}
37
- {...props}
38
- />
39
- );
40
-
41
- const footer = (
42
- <SiteFooter
43
- owner="© Owner Inc."
44
- linksLabel="Legal"
45
- links={[
46
- { key: "terms", label: "Terms of use", href: "/terms" },
47
- { key: "privacy", label: "Privacy policy", href: "/privacy", emphasis: true },
48
- { key: "business", label: "Business information", href: "/business", current: true },
49
- ]}
50
- language={<button type="button" data-slot="language-picker">English</button>}
51
- />
52
- );
53
-
54
- describe("SiteWindow", () => {
55
- it("draws the bar, the page and the footer in order inside the page container", () => {
56
- const html = renderToStaticMarkup(
57
- <SiteWindow page="pricing" bar={bar()} footer={footer}>
58
- <p data-slot="page-body">body</p>
59
- </SiteWindow>,
60
- );
61
- expect(html.startsWith('<div data-slot="site-window"')).toBe(true);
62
- expect(html).toContain('data-page="pricing"');
63
- const order = ["site-bar", "site-main", "page-body", "site-footer"].map((slot) => html.indexOf(`data-slot="${slot}"`));
64
- expect(order.every((at, i) => at > -1 && (i === 0 || at > (order[i - 1] ?? 0)))).toBe(true);
65
- expect(siteWindowStyle.base).toContain("@container/page");
66
- expect(unmarked(html)).toEqual([]);
67
- });
68
-
69
- it("hands its link component to every link inside", () => {
70
- const Routed = (props: SiteLinkProps) => <a {...props} data-router="yes" />;
71
- const html = renderToStaticMarkup(
72
- <SiteWindow page="pricing" bar={bar()} footer={footer} linkComponent={Routed}>
73
- <span data-slot="page-body" />
74
- </SiteWindow>,
75
- );
76
- const anchors = html.match(/<a /g)?.length ?? 0;
77
- expect(anchors).toBeGreaterThan(0);
78
- expect(html.match(/data-router="yes"/g)?.length).toBe(anchors);
79
- });
80
-
81
- it("marks a dark band so the band's values take over inside it", () => {
82
- const html = renderToStaticMarkup(
83
- <SiteBand tone="dark">
84
- <span data-slot="hero" />
85
- </SiteBand>,
86
- );
87
- expect(html).toContain('data-slot="site-band"');
88
- expect(html).toContain('data-band="dark"');
89
- });
90
- });
91
-
92
- describe("SiteBar", () => {
93
- it("draws the brand home, every page with the current one marked, and the visitor's action", () => {
94
- const html = renderToStaticMarkup(bar());
95
- const brand = bySlot(html, "site-bar-brand")[0];
96
- expect(brand?.attributes.href).toBe("/");
97
- expect(brand?.attributes["aria-label"]).toBe("Home");
98
- const pageLinks = bySlot(html, "site-bar-link");
99
- expect(pageLinks.map((link) => link.attributes.href)).toEqual(["/", "/pricing", "/download", "/help"]);
100
- expect(pageLinks.map((link) => link.attributes["aria-current"] ?? "")).toEqual(["", "page", "", ""]);
101
- expect(pageLinks.map((link) => link.attributes["data-current"])).toEqual(["false", "true", "false", "false"]);
102
- const action = bySlot(html, "site-action")[0];
103
- expect(action?.name).toBe("a");
104
- expect(action?.attributes["data-tone"]).toBe("primary");
105
- expect(bySlot(html, "site-bar-account")).toEqual([]);
106
- expect(unmarked(html)).toEqual([]);
107
- });
108
-
109
- it("draws no page landmark and no more menu when the site has no pages and no menu action", () => {
110
- const html = renderToStaticMarkup(bar({ links: [], actions: [{ id: "start", label: "Start free", href: "/signup" }] }));
111
- expect(html).not.toContain("<nav");
112
- expect(bySlot(html, "site-bar-nav")).toEqual([]);
113
- expect(bySlot(html, "site-bar-more")).toEqual([]);
114
- expect(bySlot(html, "site-action")).toHaveLength(1);
115
- expect(unmarked(html)).toEqual([]);
116
- });
117
-
118
- it("keeps the more menu for a menu action when there are no pages", () => {
119
- const html = renderToStaticMarkup(bar({ links: [], actions: [{ id: "start", label: "Start free", href: "/signup", narrow: "menu" }] }));
120
- expect(bySlot(html, "site-bar-nav")).toEqual([]);
121
- expect(bySlot(html, "site-bar-more")).toHaveLength(1);
122
- });
123
-
124
- it("draws the visitor's actions in reading order, each in its own tone, the first without one as the primary", () => {
125
- const html = renderToStaticMarkup(
126
- bar({
127
- actions: [
128
- { id: "signIn", label: "Sign in", href: "/login", tone: "quiet", narrow: "menu" },
129
- { id: "start", label: "Start free", href: "/signup" },
130
- ],
131
- }),
132
- );
133
- const actions = bySlot(html, "site-action");
134
- expect(actions.map((action) => [action.attributes["data-action"], action.attributes["data-tone"], action.attributes.href])).toEqual([
135
- ["signIn", "quiet", "/login"],
136
- ["start", "primary", "/signup"],
137
- ]);
138
- expect(actions.map((action) => action.attributes["data-narrow"])).toEqual(["hidden", "shown"]);
139
- expect(siteActionStyle.variants.narrow.hidden).toContain("@max-page-narrow/page:hidden");
140
- expect(siteActionStyle.variants.narrow.shown).not.toContain("hidden");
141
- const stops = tabStops(html).map((tag) => tag.attributes["data-action"] ?? tag.attributes["data-slot"]);
142
- expect(stops.slice(-3)).toEqual(["signIn", "start", "site-bar-more"]);
143
- expect(unmarked(html)).toEqual([]);
144
- });
145
-
146
- it("lists the pages and then only the actions that leave the bar in the open more menu", () => {
147
- const html = renderToStaticMarkup(
148
- <SiteBarMenuItems
149
- links={links}
150
- actions={[
151
- { id: "signIn", label: "Sign in", href: "/login", narrow: "menu" },
152
- { id: "notify", label: "Tell me", narrow: "menu" },
153
- ]}
154
- onClose={() => {}}
155
- />,
156
- );
157
- const items = bySlot(html, "site-bar-menu-item");
158
- expect(items.map((item) => [item.name, item.attributes.href ?? "", item.attributes["data-action"] ?? ""])).toEqual([
159
- ["a", "/", ""],
160
- ["a", "/pricing", ""],
161
- ["a", "/download", ""],
162
- ["a", "/help", ""],
163
- ["a", "/login", "signIn"],
164
- ["button", "", "notify"],
165
- ]);
166
- expect(html).toContain(">Sign in</a>");
167
- });
168
-
169
- it("moves only the actions marked for the menu into it, and none once an account is signed in", () => {
170
- const actions = [
171
- { id: "signIn", label: "Sign in", href: "/login", narrow: "menu" as const },
172
- { id: "start", label: "Start free", href: "/signup" },
173
- { id: "demo", label: "Book a demo", href: "/demo", narrow: "bar" as const },
174
- ];
175
- expect(barMenuActions(actions, false).map((action) => action.id)).toEqual(["signIn"]);
176
- expect(barMenuActions(actions, true)).toEqual([]);
177
- });
178
-
179
- it("draws no visitor action once an account is signed in", () => {
180
- const html = renderToStaticMarkup(
181
- bar({
182
- actions: [{ id: "signIn", label: "Sign in", href: "/login", tone: "quiet", narrow: "menu" }],
183
- account: { label: "My account", name: "Taylor", href: "/account" },
184
- }),
185
- );
186
- expect(bySlot(html, "site-action")).toEqual([]);
187
- });
188
-
189
- it("draws the signed-in account with its initial in place of the visitor's action", () => {
190
- const html = renderToStaticMarkup(bar({ account: { label: "My account", name: " taylor", href: "/account", current: true } }));
191
- expect(bySlot(html, "site-action")).toEqual([]);
192
- const account = bySlot(html, "site-bar-account")[0];
193
- expect(account?.attributes["aria-current"]).toBe("page");
194
- expect(html).toContain(">My account</span>");
195
- expect(html).toMatch(/data-slot="site-avatar"[^>]*>T</);
196
- });
197
-
198
- it("reaches every page, the brand, the action and the more menu with Tab, in reading order", () => {
199
- const stops = tabStops(renderToStaticMarkup(bar())).map((tag) => tag.attributes["data-slot"]);
200
- expect(stops).toEqual(["site-bar-brand", "site-bar-link", "site-bar-link", "site-bar-link", "site-bar-link", "site-action", "site-bar-more"]);
201
- });
202
-
203
- it("closes the more menu until it is opened, and names what it opens", () => {
204
- const more = bySlot(renderToStaticMarkup(bar()), "site-bar-more")[0];
205
- expect(more?.attributes["aria-expanded"]).toBe("false");
206
- expect(more?.attributes["aria-label"]).toBe("More pages");
207
- expect(more?.attributes["aria-controls"]).toBeTruthy();
208
- expect(bySlot(renderToStaticMarkup(bar()), "site-bar-menu")).toEqual([]);
209
- });
210
-
211
- it("draws a page that is not open yet as plain text in its place, reached by no Tab", () => {
212
- const pending = links.map((link) => (link.key === "download" || link.key === "help" ? { ...link, href: undefined } : link));
213
- const html = renderToStaticMarkup(bar({ links: pending }));
214
- const pageLinks = bySlot(html, "site-bar-link");
215
- expect(pageLinks.map((link) => link.name)).toEqual(["a", "a", "span", "span"]);
216
- expect(pageLinks.map((link) => link.attributes["data-pending"])).toEqual(["false", "false", "true", "true"]);
217
- expect(pageLinks.slice(2).every((link) => link.attributes.href === undefined && link.attributes["aria-current"] === undefined)).toBe(true);
218
- expect(html).toContain(">Download</span>");
219
- const stops = tabStops(html).map((tag) => tag.attributes["data-slot"]);
220
- expect(stops).toEqual(["site-bar-brand", "site-bar-link", "site-bar-link", "site-action", "site-bar-more"]);
221
- expect(unmarked(html)).toEqual([]);
222
- });
223
-
224
- it("continues a dark band into the bar", () => {
225
- const dark = bySlot(renderToStaticMarkup(bar({ tone: "dark" })), "site-bar")[0];
226
- expect(dark?.attributes["data-band"]).toBe("dark");
227
- expect(dark?.attributes["data-tone"]).toBe("dark");
228
- const light = bySlot(renderToStaticMarkup(bar()), "site-bar")[0];
229
- expect(light?.attributes["data-band"]).toBeUndefined();
230
- });
231
-
232
- it("moves the pages into the more menu below the narrow tier", () => {
233
- expect(siteBarNavStyle.base).toContain("@max-page-narrow/page:hidden");
234
- expect(siteBarMoreStyle.base).toMatch(/(^| )hidden( |$)/);
235
- expect(siteBarMoreStyle.base).toContain("@max-page-narrow/page:inline-flex");
236
- expect(siteBarMenuStyle.base).toContain("@max-page-narrow/page:flex");
237
- expect(siteBarAccountNameStyle.base).toContain("@max-page-narrow/page:sr-only");
238
- expect(siteBarStyle.base).toContain("@max-page-narrow/page:px-4");
239
- expect(siteFooterStyle.base).toContain("@max-page-narrow/page:px-4");
240
- });
241
- });
242
-
243
- describe("the more menu's keys", () => {
244
- it("opens on the first or last item from the trigger, walks and wraps, and closes on Escape", () => {
245
- expect(menuKeyTarget("ArrowDown", -1, 4)).toBe(0);
246
- expect(menuKeyTarget("ArrowUp", -1, 4)).toBe(3);
247
- expect(menuKeyTarget("ArrowDown", 3, 4)).toBe(0);
248
- expect(menuKeyTarget("ArrowUp", 0, 4)).toBe(3);
249
- expect(menuKeyTarget("Home", 2, 4)).toBe(0);
250
- expect(menuKeyTarget("End", 0, 4)).toBe(3);
251
- expect(menuKeyTarget("Escape", 1, 4)).toBe("close");
252
- });
253
-
254
- it("leaves every other key alone", () => {
255
- expect(menuKeyTarget("a", 1, 4)).toBeNull();
256
- expect(menuKeyTarget("Tab", 1, 4)).toBeNull();
257
- expect(menuKeyTarget("ArrowDown", -1, 0)).toBeNull();
258
- });
259
- });
260
-
261
- describe("avatarInitial", () => {
262
- it("takes the first grapheme of the trimmed name, upper-cased", () => {
263
- expect(avatarInitial(" taylor ")).toBe("T");
264
- expect(avatarInitial("\uAE40\uD558\uB298")).toBe("\uAE40");
265
- expect(avatarInitial("")).toBe("");
266
- });
267
- });
268
-
269
- describe("SiteFooter", () => {
270
- it("draws the owner, the legal links with the emphasised and current ones marked, then the language picker", () => {
271
- const html = renderToStaticMarkup(footer);
272
- expect(bySlot(html, "site-footer-owner")).toHaveLength(1);
273
- const legal = bySlot(html, "site-footer-link");
274
- expect(legal.map((link) => link.attributes["data-emphasis"])).toEqual(["false", "true", "false"]);
275
- expect(legal.map((link) => link.attributes["aria-current"] ?? "")).toEqual(["", "", "page"]);
276
- expect(html.indexOf("site-footer-links")).toBeLessThan(html.indexOf("site-footer-language"));
277
- expect(bySlot(html, "site-footer-links")[0]?.attributes["aria-label"]).toBe("Legal");
278
- });
279
-
280
- it("draws a legal page that is not open yet as plain text in its place, reached by no Tab", () => {
281
- const html = renderToStaticMarkup(
282
- <SiteFooter
283
- owner="©"
284
- linksLabel="Legal"
285
- links={[
286
- { key: "terms", label: "Terms of use" },
287
- { key: "privacy", label: "Privacy policy", emphasis: true },
288
- { key: "business", label: "Business information", href: "/business" },
289
- ]}
290
- />,
291
- );
292
- const legal = bySlot(html, "site-footer-link");
293
- expect(legal.map((link) => [link.name, link.attributes["data-pending"], link.attributes["data-emphasis"]])).toEqual([
294
- ["span", "true", "false"],
295
- ["span", "true", "true"],
296
- ["a", "false", "false"],
297
- ]);
298
- expect(tabStops(html).map((tag) => tag.attributes.href)).toEqual(["/business"]);
299
- });
300
-
301
- it("draws no legal landmark when the site has no legal links", () => {
302
- const html = renderToStaticMarkup(<SiteFooter owner="©" links={[]} linksLabel="Legal" />);
303
- expect(html).not.toContain("<nav");
304
- expect(bySlot(html, "site-footer-links")).toEqual([]);
305
- expect(bySlot(html, "site-footer-owner")).toHaveLength(1);
306
- });
307
-
308
- it("draws no language place when the product hands no picker", () => {
309
- const html = renderToStaticMarkup(<SiteFooter owner="©" links={[]} linksLabel="Legal" />);
310
- expect(bySlot(html, "site-footer-language")).toEqual([]);
311
- });
312
-
313
- it("draws the theme control in its own place after the language picker, and no place without one", () => {
314
- const html = renderToStaticMarkup(
315
- <SiteFooter owner="©" links={[]} linksLabel="Legal" language={<span data-slot="language-picker" />} theme={<span data-slot="theme-control" />} />,
316
- );
317
- const language = html.indexOf('data-slot="site-footer-language"');
318
- const theme = html.indexOf('data-slot="site-footer-theme"');
319
- expect(language).toBeGreaterThan(-1);
320
- expect(theme).toBeGreaterThan(language);
321
- expect(html.indexOf('data-slot="theme-control"')).toBeGreaterThan(theme);
322
- expect(bySlot(renderToStaticMarkup(footer), "site-footer-theme")).toEqual([]);
323
- });
324
- });
325
-
326
- describe("pageHeading", () => {
327
- const root = (h1: string | null) => ({ querySelector: (selector: string) => (selector === "h1" && h1 !== null ? ({ textContent: h1 } as Element) : null) });
328
-
329
- it("reads the page's heading with its spaces folded, for the document's title", () => {
330
- expect(pageHeading(root(" Terms of\n use "))).toBe("Terms of use");
331
- });
332
-
333
- it("answers empty for a page without a heading and for a window not drawn yet", () => {
334
- expect(pageHeading(root(null))).toBe("");
335
- expect(pageHeading(null)).toBe("");
336
- });
337
- });
338
-
339
-
340
- describe("followHeading", () => {
341
- /** A page box whose heading text can change, and an observer the test fires by hand. */
342
- function page(first: string) {
343
- const heading = { innerText: first };
344
- const root = { querySelector: (selector: string) => (selector === "h1" ? heading : null) } as unknown as Parameters<typeof followHeading>[0];
345
- let fire = () => undefined as void;
346
- let watched = false;
347
- let stopped = false;
348
- const watch = (onChange: () => void): HeadingObserver => {
349
- fire = onChange;
350
- return { observe: () => void (watched = true), disconnect: () => void (stopped = true) };
351
- };
352
- return { heading, root, watch, fire: () => fire(), state: () => ({ watched, stopped }) };
353
- }
354
-
355
- it("rewrites the title when the page's own heading changes, without the window drawing again", () => {
356
- const shown = page("Confirming your payment");
357
- const sink = { title: "StageVoice" };
358
- followHeading(shown.root, () => (heading) => `${heading} - StageVoice`, sink, shown.watch);
359
- expect(shown.state().watched).toBe(true);
360
- shown.heading.innerText = "Payment received";
361
- shown.fire();
362
- expect(sink.title).toBe("Payment received - StageVoice");
363
- shown.heading.innerText = "Receipt";
364
- shown.fire();
365
- expect(sink.title).toBe("Receipt - StageVoice");
366
- });
367
-
368
- it("reads the latest title function at each change and leaves the title alone while there is none", () => {
369
- const shown = page("One");
370
- const sink = { title: "Untouched" };
371
- let named: ((heading: string) => string) | undefined;
372
- followHeading(shown.root, () => named, sink, shown.watch);
373
- shown.fire();
374
- expect(sink.title).toBe("Untouched");
375
- named = (heading) => `[${heading}]`;
376
- shown.fire();
377
- expect(sink.title).toBe("[One]");
378
- });
379
-
380
- it("stops watching when disposed", () => {
381
- const shown = page("One");
382
- const stop = followHeading(shown.root, () => undefined, { title: "" }, shown.watch);
383
- stop();
384
- expect(shown.state().stopped).toBe(true);
385
- });
386
- });
387
-
388
-
389
- describe("a footer link", () => {
390
- it("is at least 24px tall below the narrow tier, centring its words, where the small print wraps onto rows a thumb must tell apart (WCAG 2.2)", () => {
391
- const below = (utility: string) => siteFooterLinkStyle.base.split(/\s+/).includes(`@max-page-narrow/page:${utility}`);
392
- expect(below("inline-flex")).toBe(true);
393
- expect(below("min-h-6")).toBe(true);
394
- expect(below("items-center")).toBe(true);
395
- });
396
-
397
- it("keeps the line's own height in one row, where the criterion's spacing exception holds", () => {
398
- expect(siteFooterLinkStyle.base.split(/\s+/)).not.toContain("min-h-6");
399
- expect(siteFooterLinkStyle.base.split(/\s+/)).not.toContain("inline-flex");
400
- });
401
- });