@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,187 +0,0 @@
1
- import { renderToStaticMarkup } from "react-dom/server";
2
- import { describe, expect, it } from "vitest";
3
-
4
- import { bySlot, tabStops, tagsOf, unmarked } from "../testing/markup";
5
- import { CheckoutHead, CheckoutLayout, ConsentAgain, ConsentChecklist, DonePanel, MethodGrid, OrderSummary, ProgressChain, ProviderFrame, ProviderTarget, ProviderWaiting, Stepper } from "./checkout";
6
- import { ChoiceCards } from "./choice-cards";
7
- import { siteStepHeadingStyle, siteStepperStyle } from "./checkout.style";
8
-
9
- const byPart = (html: string, part: string) => tagsOf(html).filter((tag) => tag.attributes["data-part"] === part);
10
- const frameworkOwned = (html: string) => new Set(tagsOf(html).filter((tag) => tag.name === "svg" || (tag.name === "input" && tag.attributes["aria-hidden"] === "true")).map((tag) => `<${tag.name}>`));
11
- const ownUnmarked = (html: string) => unmarked(html).filter((tag) => !frameworkOwned(html).has(tag));
12
-
13
- describe("Stepper", () => {
14
- it("marks the steps before the current one done and the current one as the step, joined by lines", () => {
15
- const html = renderToStaticMarkup(
16
- <Stepper
17
- label="Checkout steps"
18
- current={1}
19
- doneMark={<svg data-slot="glyph" />}
20
- caption="Enter your details"
21
- steps={[
22
- { key: "plan", label: "Plan" },
23
- { key: "details", label: "Your details" },
24
- { key: "pay", label: "Payment" },
25
- ]}
26
- />,
27
- );
28
- const steps = bySlot(html, "site-stepper-step");
29
- expect(steps.map((step) => step.attributes["data-state"])).toEqual(["done", "current", "next"]);
30
- expect(steps[1]?.attributes["aria-current"]).toBe("step");
31
- expect(bySlot(html, "site-stepper-line").map((line) => line.attributes["data-reached"])).toEqual(["true", "false"]);
32
- expect(bySlot(html, "site-stepper-caption")).toHaveLength(1);
33
- expect(unmarked(html)).toEqual([]);
34
- });
35
-
36
- it("draws the page's title before the steps for a screen reader and the tab, only where it is handed one", () => {
37
- const steps = [{ key: "plan", label: "Plan" }, { key: "details", label: "Your details" }];
38
- const titled = renderToStaticMarkup(<Stepper label="Checkout steps" current={1} steps={steps} heading="Your details" />);
39
- const heading = bySlot(titled, "site-stepper-heading")[0];
40
- expect(heading?.name).toBe("h1");
41
- expect(titled.indexOf("site-stepper-heading")).toBeLessThan(titled.indexOf("site-stepper\""));
42
- expect(siteStepHeadingStyle.base).toBe("sr-only");
43
- expect(bySlot(renderToStaticMarkup(<Stepper label="Checkout steps" current={1} steps={steps} />), "site-stepper-heading")).toEqual([]);
44
- expect(unmarked(titled)).toEqual([]);
45
- });
46
-
47
- it("gives every step a column of the row, however many there are", () => {
48
- const html = renderToStaticMarkup(<Stepper label="Checkout steps" current={0} steps={[{ key: "plan", label: "Plan" }, { key: "done", label: "Done" }]} />);
49
- expect(bySlot(html, "site-stepper-step")).toHaveLength(2);
50
- // A fixed column count would leave a two-step purchase in half of the row.
51
- expect(siteStepperStyle.base).not.toMatch(/\bgrid-cols-\d/);
52
- expect(siteStepperStyle.base).toMatch(/\bgrid-flow-col\b/);
53
- expect(siteStepperStyle.base).toMatch(/\bauto-cols-fr\b/);
54
- });
55
- });
56
-
57
- describe("ChoiceCards", () => {
58
- const options = [
59
- { value: "pro", title: "Pro", price: "₩14,900", unit: "/mo", body: "For people who present often", badge: "Most chosen" },
60
- { value: "plus", title: "Pro+", price: "₩29,900", unit: "/mo" },
61
- { value: "pack", title: "Presentation pack", disabled: true },
62
- ] as const;
63
-
64
- it("is a radio group with one tab stop on the chosen card, the mark beside its title", () => {
65
- const html = renderToStaticMarkup(<ChoiceCards label="Plans" value="plus" options={options} onValueChange={() => {}} mark={<svg data-slot="glyph" />} />);
66
- expect(bySlot(html, "site-choice-cards")[0]?.attributes.role).toBe("radiogroup");
67
- expect(tabStops(html).map((tag) => tag.attributes["data-value"])).toEqual(["plus"]);
68
- const cards = bySlot(html, "site-choice-card");
69
- expect(cards.map((card) => card.attributes["data-hover"])).toEqual(["lift", "none", "lift"]);
70
- expect(bySlot(html, "glyph")).toHaveLength(1);
71
- expect(bySlot(html, "site-choice-badge")).toHaveLength(1);
72
- expect(unmarked(html)).toEqual([]);
73
- });
74
-
75
- it("draws a plan change's small cards, the pointer drawing the control line", () => {
76
- const html = renderToStaticMarkup(<ChoiceCards size="sm" label="Which plan?" value="b" options={[{ value: "a", title: "Free", meta: "Free" }, { value: "b", title: "Pro+", meta: "₩29,900/mo" }]} onValueChange={() => {}} />);
77
- expect(bySlot(html, "site-choice-card").map((card) => card.attributes["data-hover"])).toEqual(["line", "none"]);
78
- expect(bySlot(html, "site-choice-meta")).toHaveLength(2);
79
- });
80
- });
81
-
82
- describe("checkout layout", () => {
83
- it("draws our side, then the payment side in the provider's frame with its name", () => {
84
- const html = renderToStaticMarkup(
85
- <CheckoutLayout main={<CheckoutHead title="What are you presenting?" lede="Choose a plan" />} summary={<ProviderFrame label="Paddle checkout" owner="Paddle">frame</ProviderFrame>} />,
86
- );
87
- const order = tagsOf(html).map((tag) => tag.attributes["data-slot"]).filter(Boolean);
88
- expect(order.indexOf("site-checkout-main")).toBeLessThan(order.indexOf("site-provider-frame"));
89
- expect(bySlot(html, "site-provider-frame")[0]?.attributes["aria-label"]).toBe("Paddle checkout");
90
- expect(unmarked(html)).toEqual([]);
91
- });
92
-
93
- it("draws the receipt's lines, the tax ruled dashed and the total", () => {
94
- const html = renderToStaticMarkup(
95
- <OrderSummary
96
- title="Receipt preview"
97
- live="Follows the payment window"
98
- lines={[{ key: "plan", label: "Pro · monthly", amount: "₩13,545" }]}
99
- tax={{ key: "tax", label: "VAT 10% included", amount: "₩1,355" }}
100
- total={{ key: "total", label: "Due today", amount: "₩14,900" }}
101
- note="Next payment Nov 14"
102
- />,
103
- );
104
- expect(bySlot(html, "site-order-line").map((line) => line.attributes["data-kind"])).toEqual(["line", "tax", "total"]);
105
- expect(bySlot(html, "site-order-amount").map((amount) => amount.attributes["data-total"])).toEqual(["false", "false", "true"]);
106
- expect(unmarked(html)).toEqual([]);
107
- });
108
-
109
- it("draws the consents required, agreeing to all first, and a consent asked again", () => {
110
- const html = renderToStaticMarkup(
111
- <ConsentChecklist
112
- all={{ label: "Agree to all", checked: false }}
113
- badge="Required"
114
- items={[{ key: "terms", label: "The terms of use", checked: true, view: <a data-slot="site-text-action" href="/terms">View</a> }]}
115
- onAllChange={() => {}}
116
- onItemChange={() => {}}
117
- />,
118
- );
119
- const boxes = byPart(html, "site-checkbox");
120
- expect(boxes).toHaveLength(2);
121
- expect(boxes[1]?.attributes["aria-required"]).toBe("true");
122
- expect(bySlot(html, "site-checkbox-badge")).toHaveLength(1);
123
- expect(bySlot(html, "site-consent-view")).toHaveLength(1);
124
- expect(ownUnmarked(html)).toEqual([]);
125
- const again = renderToStaticMarkup(<ConsentAgain note="The total changed">consent</ConsentAgain>);
126
- expect(bySlot(again, "site-consent-again-note")).toHaveLength(1);
127
- });
128
- });
129
-
130
- describe("payment and after", () => {
131
- it("draws ways to pay as toggles, a one-off one disabled for a subscription", () => {
132
- const html = renderToStaticMarkup(
133
- <MethodGrid
134
- methods={[
135
- { key: "card", name: "Card", mark: "CA", pressed: true, wide: true },
136
- { key: "bank", name: "Bank transfer", mark: "BA", about: "One-off only", disabled: true },
137
- ]}
138
- />,
139
- );
140
- const methods = bySlot(html, "site-method");
141
- expect(methods.map((method) => method.attributes["aria-pressed"])).toEqual(["true", "false"]);
142
- expect(methods[0]?.attributes["data-wide"]).toBe("true");
143
- expect(methods[1]?.attributes.disabled).toBeDefined();
144
- expect(unmarked(html)).toEqual([]);
145
- });
146
-
147
- it("marks the chain's steps done, running and waiting", () => {
148
- const html = renderToStaticMarkup(
149
- <ProgressChain
150
- title="Switching on Pro"
151
- done={1}
152
- steps={[
153
- { key: "paid", label: "Paid" },
154
- { key: "confirmed", label: "Confirmed" },
155
- { key: "on", label: "Plan on" },
156
- ]}
157
- actions={[{ id: "back", label: "Back to PowerPoint", tone: "primary" }]}
158
- />,
159
- );
160
- expect(bySlot(html, "site-chain-step").map((step) => step.attributes["data-state"])).toEqual(["done", "running", "waiting"]);
161
- expect(unmarked(html)).toEqual([]);
162
- });
163
-
164
- it("draws the done page's one h1 and its large actions centred", () => {
165
- const html = renderToStaticMarkup(<DonePanel mark={<svg data-slot="glyph" />} title="Pro is on" body="50,000 characters are ready" actions={[{ id: "back", label: "Back", tone: "primary" }]} notice="A receipt went to t@example.com" />);
166
- expect(bySlot(html, "site-done-title")[0]?.name).toBe("h1");
167
- expect(bySlot(html, "site-action")[0]?.attributes["data-size"]).toBe("lg");
168
- expect(bySlot(html, "site-checkout-actions")[0]?.attributes["data-align"]).toBe("center");
169
- expect(tagsOf(html)[0]?.attributes["data-slot"]).toBe("site-done-mark");
170
- expect(unmarked(html)).toEqual([]);
171
- });
172
-
173
- it("says in the provider's place what happens there, with its glyph above the sentence", () => {
174
- const html = renderToStaticMarkup(<ProviderWaiting mark={<svg data-slot="glyph" />}>Agree and the payment window opens here</ProviderWaiting>);
175
- expect(tagsOf(html)[0]?.attributes["data-slot"]).toBe("site-provider-waiting");
176
- expect(bySlot(html, "site-provider-waiting-text")[0]?.name).toBe("p");
177
- expect(html.indexOf('data-slot="glyph"')).toBeLessThan(html.indexOf("site-provider-waiting-text"));
178
- expect(unmarked(html)).toEqual([]);
179
- });
180
-
181
- it("gives the provider's script the element it draws into, found by the class it is told", () => {
182
- const html = renderToStaticMarkup(<ProviderTarget targetClass="provider-frame" />);
183
- const [target] = bySlot(html, "site-provider-target");
184
- expect(target?.attributes.class).toBe("provider-frame");
185
- expect(unmarked(html)).toEqual([]);
186
- });
187
- });
@@ -1,20 +0,0 @@
1
- import { renderToStaticMarkup } from "react-dom/server";
2
- import { describe, expect, it } from "vitest";
3
-
4
- import { SiteCheckbox } from "./choices";
5
-
6
- describe("SiteCheckbox field", () => {
7
- it("posts its field while checked, as a native box posts rememberMe=on", () => {
8
- const html = renderToStaticMarkup(<SiteCheckbox checked onCheckedChange={() => {}} label="Remember me" field={{ name: "rememberMe", value: "on" }} />);
9
- expect(html).toMatch(/<input type="hidden" name="rememberMe" value="on"\/?>/);
10
- });
11
-
12
- it("posts nothing while unchecked, and nothing without a field", () => {
13
- expect(renderToStaticMarkup(<SiteCheckbox checked={false} onCheckedChange={() => {}} label="Remember me" field={{ name: "rememberMe", value: "on" }} />)).not.toContain("rememberMe");
14
- expect(renderToStaticMarkup(<SiteCheckbox checked onCheckedChange={() => {}} label="Remember me" />)).not.toContain('type="hidden"');
15
- });
16
-
17
- it("posts its field from a box with no words beside it too", () => {
18
- expect(renderToStaticMarkup(<SiteCheckbox checked onCheckedChange={() => {}} name="Terms" field={{ name: "termsAccepted", value: "on" }} />)).toContain('name="termsAccepted"');
19
- });
20
- });
@@ -1,49 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
-
3
- import { siteErrorKind, siteErrorView, type SiteErrorEvent, type SiteErrorsCopy } from "./errors";
4
- import { siteErrorReasonStyle } from "./errors.style";
5
-
6
- const copy: SiteErrorsCopy = {
7
- titles: { validation: "Check what you entered", auth: "Not allowed", client: "Not sent", server: "Something went wrong", network: "No connection", unknown: "Something went wrong", gateway: "Service unavailable" },
8
- unavailable: "The service is not answering. Try again in a moment.",
9
- fallback: "The request could not be finished.",
10
- close: "Close",
11
- closeAll: (count) => `Close all (${count})`,
12
- };
13
-
14
- const event = (over: Partial<SiteErrorEvent>): SiteErrorEvent => ({ category: "server", message: "", raw: undefined, ...over });
15
-
16
- describe("siteErrorView", () => {
17
- it("says nothing while no failure waits", () => {
18
- expect(siteErrorView([], copy)).toBeUndefined();
19
- });
20
-
21
- it("titles the first failure by its kind and leads with the server's own sentence", () => {
22
- expect(siteErrorView([event({ category: "client", status: 409, message: "The plan is already yours" })], copy)).toEqual({
23
- title: "Not sent",
24
- description: "The plan is already yours",
25
- fields: [],
26
- });
27
- });
28
-
29
- it("names each field's reason a rejected request carries", () => {
30
- const view = siteErrorView([event({ category: "validation", message: "Check the form", validationErrors: [{ field: "email", message: "Enter an email address" }] })], copy);
31
- expect(view?.fields).toEqual(["Enter an email address"]);
32
- });
33
-
34
- it("tells a server that is not answering calmly, never with the bare status it sent", () => {
35
- const view = siteErrorView([event({ status: 503, message: "HTTP 503", validationErrors: [{ field: "x", message: "y" }] })], copy);
36
- expect(view).toEqual({ title: "Service unavailable", description: copy.unavailable, fields: [] });
37
- expect(siteErrorKind(event({ status: 500 }))).toBe("server");
38
- });
39
-
40
- it("falls back to the product's sentence for a failure without one, and offers to close them all when more wait", () => {
41
- const view = siteErrorView([event({}), event({ message: "Second" })], copy);
42
- expect(view?.description).toBe(copy.fallback);
43
- expect(view?.closeAll).toBe("Close all (2)");
44
- });
45
-
46
- it("draws each field reason as a list item", () => {
47
- expect(siteErrorReasonStyle.base).toContain("list-disc");
48
- });
49
- });
@@ -1,275 +0,0 @@
1
- import { renderToStaticMarkup } from "react-dom/server";
2
- import { Dialog } from "@simplix-react/ui";
3
- import { describe, expect, it } from "vitest";
4
-
5
- import { bySlot, silentRefusals, tabStops, tagsOf, unmarked } from "../testing/markup";
6
- import { RadioCards, SiteCheckbox, SiteSwitch } from "./choices";
7
- import { CodeField, focusFirstCell } from "./code-field";
8
- import { ConfirmByTyping, typedConfirms } from "./confirm-by-typing";
9
- import { SiteDialogFrame } from "./dialog";
10
- import { FieldNote, FormField, SiteInput, SiteTextarea } from "./fields";
11
- import { radioKeyTarget, radioTabStop } from "./radio-keys";
12
- import { SiteSelect } from "./select";
13
-
14
- import { SiteToastList } from "./toasts";
15
- import { siteCheckboxStyle } from "./choices.style";
16
-
17
- const byPart = (html: string, part: string) => tagsOf(html).filter((tag) => tag.attributes["data-part"] === part);
18
- // A framework part draws its own glyph and, for a form, a hidden native control beside it.
19
- const frameworkOwned = (html: string) =>
20
- new Set(tagsOf(html).filter((tag) => tag.name === "svg" || (["input", "select", "option"].includes(tag.name) && (tag.attributes["aria-hidden"] === "true" || tag.attributes.value === ""))).map((tag) => `<${tag.name}>`));
21
- const ownUnmarked = (html: string) => unmarked(html).filter((tag) => !frameworkOwned(html).has(tag));
22
-
23
- describe("fields", () => {
24
- it("draws a field's name over its control, muted on request, with a note under it", () => {
25
- const html = renderToStaticMarkup(
26
- <FormField label="Email" muted>
27
- <SiteInput value="a@b.c" readOnly />
28
- <FieldNote tone="bad">Enter an email address</FieldNote>
29
- </FormField>,
30
- );
31
- const field = bySlot(html, "site-field")[0];
32
- expect(field?.name).toBe("label");
33
- expect(field?.attributes["data-muted"]).toBe("true");
34
- expect(bySlot(html, "site-field-note")[0]?.attributes["data-tone"]).toBe("bad");
35
- expect(bySlot(html, "site-field-note")[0]?.name).toBe("small");
36
- expect(ownUnmarked(html)).toEqual([]);
37
- });
38
-
39
- it("draws a text input at the control height by default and reports a refused value", () => {
40
- const plain = bySlot(renderToStaticMarkup(<SiteInput value="" readOnly />), "site-input")[0];
41
- expect(plain?.attributes["data-size"]).toBe("md");
42
- expect(plain?.attributes.type).toBe("text");
43
- expect(plain?.attributes["aria-invalid"]).toBeUndefined();
44
- const refused = bySlot(renderToStaticMarkup(<SiteInput value="x" readOnly invalid size="sm" />), "site-input")[0];
45
- expect(refused?.attributes["aria-invalid"]).toBe("true");
46
- expect(refused?.attributes["data-size"]).toBe("sm");
47
- expect(bySlot(renderToStaticMarkup(<SiteTextarea value="" readOnly />), "site-textarea")).toHaveLength(1);
48
- });
49
- });
50
-
51
- describe("choices", () => {
52
- it("draws the framework checkbox as a site part inside a label, the badge for the eye only", () => {
53
- const html = renderToStaticMarkup(<SiteCheckbox checked onCheckedChange={() => {}} label="I agree to the terms" required badge="Required" />);
54
- const box = byPart(html, "site-checkbox")[0];
55
- expect(box?.name).toBe("button");
56
- expect(box?.attributes.role).toBe("checkbox");
57
- expect(box?.attributes["data-state"]).toBe("checked");
58
- expect(box?.attributes["aria-required"]).toBe("true");
59
- expect(bySlot(html, "site-checkbox-row")[0]?.name).toBe("label");
60
- expect(bySlot(html, "site-checkbox-badge")[0]?.attributes["aria-hidden"]).toBe("true");
61
- expect(ownUnmarked(html)).toEqual([]);
62
- });
63
-
64
- it("names a checkbox without words by its name", () => {
65
- const html = renderToStaticMarkup(<SiteCheckbox checked={false} onCheckedChange={() => {}} name="Select all" />);
66
- expect(byPart(html, "site-checkbox")[0]?.attributes["aria-label"]).toBe("Select all");
67
- expect(bySlot(html, "site-checkbox-row")).toHaveLength(0);
68
- });
69
-
70
- it("names the line that says why a disabled checkbox cannot be changed", () => {
71
- const html = renderToStaticMarkup(<SiteCheckbox checked={false} onCheckedChange={() => {}} label="Attach the record" disabled describedBy="why" />);
72
- expect(byPart(html, "site-checkbox")[0]?.attributes["aria-describedby"]).toBe("why");
73
- expect(byPart(renderToStaticMarkup(<SiteCheckbox checked={false} onCheckedChange={() => {}} label="Attach" />), "site-checkbox")[0]?.attributes["aria-describedby"]).toBeUndefined();
74
- });
75
-
76
- it("draws a checked or partly checked box's mark in the site's ink on the accent, over the framework checkbox's own ink", () => {
77
- expect(siteCheckboxStyle.base).toContain("data-[state=checked]:text-(--site-on-accent)");
78
- expect(siteCheckboxStyle.base).toContain("data-[state=indeterminate]:text-(--site-on-accent)");
79
- });
80
-
81
- it("draws the framework switch as a site part", () => {
82
- const html = renderToStaticMarkup(<SiteSwitch checked onCheckedChange={() => {}} label="Marketing mail" />);
83
- const control = byPart(html, "site-toggle")[0];
84
- expect(control?.attributes.role).toBe("switch");
85
- expect(control?.attributes["data-state"]).toBe("checked");
86
- expect(bySlot(html, "site-toggle-row")[0]?.name).toBe("label");
87
- });
88
-
89
- it("makes a radio group one tab stop on the chosen card, or on the first open one when none is", () => {
90
- const options = [
91
- { value: "a", title: "A", body: "first", disabled: true },
92
- { value: "b", title: "B" },
93
- { value: "c", title: "C" },
94
- ] as const;
95
- const chosen = renderToStaticMarkup(<RadioCards label="Plan" value="c" options={options} onValueChange={() => {}} />);
96
- expect(tabStops(chosen).map((tag) => tag.attributes["data-value"])).toEqual(["c"]);
97
- expect(bySlot(chosen, "site-radio-dot")).toHaveLength(1);
98
- const none = renderToStaticMarkup(<RadioCards label="Plan" value={null} options={options} onValueChange={() => {}} />);
99
- expect(tabStops(none).map((tag) => tag.attributes["data-value"])).toEqual(["b"]);
100
- expect(radioTabStop(options, null)).toBe("b");
101
- expect(ownUnmarked(chosen)).toEqual([]);
102
- });
103
-
104
- it("walks the arrows past disabled options and wraps", () => {
105
- const options = [{ value: "a" }, { value: "b", disabled: true }, { value: "c" }];
106
- expect(radioKeyTarget(options, "a", "ArrowRight")).toBe("c");
107
- expect(radioKeyTarget(options, "c", "ArrowDown")).toBe("a");
108
- expect(radioKeyTarget(options, "a", "End")).toBe("c");
109
- expect(radioKeyTarget(options, "a", "Enter")).toBeNull();
110
- });
111
- });
112
-
113
- describe("SiteSelect", () => {
114
- const options = [
115
- { value: "KR", label: "Korea" },
116
- { value: "US", label: "United States" },
117
- ] as const;
118
-
119
- it("draws the framework trigger as a site part showing the chosen option's words", () => {
120
- const html = renderToStaticMarkup(<SiteSelect label="Country" options={options} value="US" onValueChange={() => {}} block />);
121
- const trigger = byPart(html, "site-select")[0];
122
- expect(trigger?.name).toBe("button");
123
- expect(trigger?.attributes["aria-label"]).toBe("Country");
124
- expect(trigger?.attributes["data-part-block"]).toBe("true");
125
- expect(html).toContain("United States");
126
- expect(bySlot(html, "site-select-value")[0]?.attributes["data-placeholder"]).toBe("false");
127
- });
128
-
129
- it("shows the placeholder in the muted ink while nothing is chosen", () => {
130
- const html = renderToStaticMarkup(<SiteSelect label="Reason" placeholder="Choose one" options={options} value={null} onValueChange={() => {}} />);
131
- expect(html).toContain("Choose one");
132
- expect(bySlot(html, "site-select-value")[0]?.attributes["data-placeholder"]).toBe("true");
133
- });
134
- });
135
-
136
- describe("CodeField", () => {
137
- it("draws six cells marked as the site's cells, all marked refused for a refused code", () => {
138
- const html = renderToStaticMarkup(<CodeField label="Code" value="12" onValueChange={() => {}} invalid cellLabel={(at, of) => `${at}/${of}`} />);
139
- expect(byPart(html, "site-code")).toHaveLength(1);
140
- const cells = byPart(html, "site-code-cell");
141
- expect(cells).toHaveLength(6);
142
- expect(cells.every((cell) => cell.attributes["data-part-invalid"] === "true" && cell.attributes["aria-invalid"] === "true")).toBe(true);
143
- expect(cells[0]?.attributes.value).toBe("1");
144
- expect(cells[0]?.attributes["aria-label"]).toBe("1/6");
145
- });
146
-
147
- it("is described by the refusal line it names, and by nothing without one", () => {
148
- const refused = renderToStaticMarkup(<CodeField label="Code" value="" onValueChange={() => {}} invalid describedBy="code-error" />);
149
- expect(byPart(refused, "site-code")[0]?.attributes["aria-describedby"]).toBe("code-error");
150
- const plain = renderToStaticMarkup(<CodeField label="Code" value="" onValueChange={() => {}} />);
151
- expect(byPart(plain, "site-code")[0]?.attributes["aria-describedby"]).toBeUndefined();
152
- });
153
-
154
- it("is named by the visible title it points at, in place of its own label, and by the label without one", () => {
155
- const titled = renderToStaticMarkup(
156
- <>
157
- <span id="code-title">Authenticator code</span>
158
- <CodeField label="Code" labelledBy="code-title" value="" onValueChange={() => {}} />
159
- </>,
160
- );
161
- const group = byPart(titled, "site-code")[0];
162
- expect(group?.attributes["aria-labelledby"]).toBe("code-title");
163
- expect(group?.attributes["aria-label"]).toBeUndefined();
164
- const plain = renderToStaticMarkup(<CodeField label="Code" value="" onValueChange={() => {}} />);
165
- expect(byPart(plain, "site-code")[0]?.attributes["aria-label"]).toBe("Code");
166
- expect(byPart(plain, "site-code")[0]?.attributes["aria-labelledby"]).toBeUndefined();
167
- });
168
-
169
- it("takes the group's id from the caller, and generates one otherwise", () => {
170
- const named = renderToStaticMarkup(<CodeField label="Code" id="otp-row" value="" onValueChange={() => {}} />);
171
- expect(byPart(named, "site-code")[0]?.attributes.id).toBe("otp-row");
172
- const generated = renderToStaticMarkup(<CodeField label="Code" value="" onValueChange={() => {}} />);
173
- expect(byPart(generated, "site-code")[0]?.attributes.id).toBeTruthy();
174
- });
175
-
176
- it("puts the focus in the first cell of the row, and does nothing for a row with no cell", () => {
177
- const focused: string[] = [];
178
- focusFirstCell({ querySelector: ((selector: string) => (selector === "input" ? { focus: () => focused.push("first") } : null)) as ParentNode["querySelector"] });
179
- expect(focused).toEqual(["first"]);
180
- expect(() => focusFirstCell({ querySelector: (() => null) as ParentNode["querySelector"] })).not.toThrow();
181
- expect(() => focusFirstCell(null)).not.toThrow();
182
- });
183
- });
184
-
185
- describe("ConfirmByTyping", () => {
186
- const actions = { confirm: { id: "delete", label: "Delete", reason: "Type DELETE to delete" }, cancel: { id: "cancel", label: "Cancel" } };
187
-
188
- it("confirms only on the word, ignoring the space around it", () => {
189
- expect(typedConfirms(" DELETE ", "DELETE")).toBe(true);
190
- expect(typedConfirms("delete", "DELETE")).toBe(false);
191
- expect(typedConfirms("", "")).toBe(false);
192
- });
193
-
194
- it("keeps the deletion disabled until the word is typed, as an alert dialog on the danger ground", () => {
195
- const waiting = renderToStaticMarkup(<ConfirmByTyping title="Delete my voice" body="It cannot be undone." label="Type DELETE" word="DELETE" value="DEL" onValueChange={() => {}} {...actions} />);
196
- const root = bySlot(waiting, "site-confirm")[0];
197
- expect(root?.attributes.role).toBe("alertdialog");
198
- // Named by its title, and the target of the focus when it opens, never a Tab stop.
199
- expect(bySlot(waiting, "site-confirm-title")[0]?.attributes.id).toBe(root?.attributes["aria-labelledby"]);
200
- expect(bySlot(waiting, "site-confirm-title")[0]?.attributes.id).toBeTruthy();
201
- expect(root?.attributes.tabindex).toBe("-1");
202
- const confirm = bySlot(waiting, "site-action").find((tag) => tag.attributes["data-action"] === "delete");
203
- expect(confirm?.attributes.disabled).toBeDefined();
204
- expect(confirm?.attributes["data-tone"]).toBe("danger");
205
- const ready = renderToStaticMarkup(<ConfirmByTyping title="Delete my voice" label="Type DELETE" word="DELETE" value="DELETE" onValueChange={() => {}} {...actions} />);
206
- expect(bySlot(ready, "site-action").find((tag) => tag.attributes["data-action"] === "delete")?.attributes.disabled).toBeUndefined();
207
- expect(ownUnmarked(waiting)).toEqual([]);
208
- });
209
-
210
- it("describes the waiting deletion by its reason, and drops the reason once the word is typed", () => {
211
- const waiting = renderToStaticMarkup(<ConfirmByTyping title="Delete my voice" label="Type DELETE" word="DELETE" value="" onValueChange={() => {}} {...actions} />);
212
- const confirm = bySlot(waiting, "site-action").find((tag) => tag.attributes["data-action"] === "delete");
213
- expect(confirm?.attributes["aria-describedby"]).toBe(bySlot(waiting, "site-action-reason")[0]?.attributes.id);
214
- expect(waiting).toContain(">Type DELETE to delete</span>");
215
- expect(silentRefusals(waiting)).toEqual([]);
216
- const ready = renderToStaticMarkup(<ConfirmByTyping title="Delete my voice" label="Type DELETE" word="DELETE" value="DELETE" onValueChange={() => {}} {...actions} />);
217
- expect(bySlot(ready, "site-action-reason")).toEqual([]);
218
- // @ts-expect-error the deletion carries the reason it waits for
219
- expect(<ConfirmByTyping title="T" label="L" word="W" value="" onValueChange={() => {}} confirm={{ id: "delete", label: "Delete" }} cancel={{ id: "cancel", label: "Cancel" }} />).toBeDefined();
220
- });
221
-
222
- it("draws a plain card with its points as a list and the field's name muted", () => {
223
- const html = renderToStaticMarkup(
224
- <ConfirmByTyping tone="plain" title="Delete the account" points={[{ key: "a", text: "Voices go" }, { key: "b", text: "Receipts stay" }]} label="Type your email" word="t@example.com" value="" onValueChange={() => {}} {...actions} />,
225
- );
226
- expect(bySlot(html, "site-confirm")[0]?.attributes.role).toBe("group");
227
- expect(bySlot(html, "site-confirm")[0]?.attributes["aria-labelledby"]).toBe(bySlot(html, "site-confirm-title")[0]?.attributes.id);
228
- expect(bySlot(html, "site-confirm-point")).toHaveLength(2);
229
- expect(bySlot(html, "site-field")[0]?.attributes["data-muted"]).toBe("true");
230
- });
231
-
232
- it("draws what else it asks between the points and the typed field", () => {
233
- const html = renderToStaticMarkup(
234
- <ConfirmByTyping tone="plain" title="Delete the account" points={[{ key: "a", text: "Voices go" }]} label="Type your email" word="t@example.com" value="" onValueChange={() => {}} {...actions}>
235
- <p data-slot="site-caption">Deleted after a waiting period</p>
236
- <span data-slot="site-field" data-reason="true" />
237
- </ConfirmByTyping>,
238
- );
239
- const order = [...html.matchAll(/data-slot="(site-confirm-body|site-caption|site-field)"/g)].map((match) => match[1]);
240
- expect(order).toEqual(["site-confirm-body", "site-caption", "site-field", "site-field"]);
241
- expect(html.indexOf("data-reason")).toBeLessThan(html.lastIndexOf('data-slot="site-field"'));
242
- });
243
- });
244
-
245
- describe("SiteDialogFrame", () => {
246
- it("names the dialog by the framework title and description, with a close button named for it", () => {
247
- const html = renderToStaticMarkup(
248
- <Dialog open>
249
- <SiteDialogFrame title="Change plan" description="Pro+ from today" close={{ name: "Close Change plan", glyph: <svg data-slot="glyph" /> }} footer={<button data-slot="site-action" type="button">Change</button>} />
250
- </Dialog>,
251
- );
252
- expect(byPart(html, "site-dialog-title")[0]?.name).toBe("h2");
253
- expect(byPart(html, "site-dialog-description")).toHaveLength(1);
254
- expect(bySlot(html, "site-dialog-close")[0]?.attributes["aria-label"]).toBe("Close Change plan");
255
- expect(bySlot(html, "site-dialog-foot")).toHaveLength(1);
256
- });
257
- });
258
-
259
- describe("SiteToastList", () => {
260
- it("draws each toast on one line with a dot in its tone and at most one action", () => {
261
- const html = renderToStaticMarkup(
262
- <SiteToastList
263
- toasts={[
264
- { id: "1", type: "success", message: "Plan changed" },
265
- { id: "2", type: "error", message: "Not sent", action: { label: "Try again", run: () => {} } },
266
- ]}
267
- />,
268
- );
269
- expect(bySlot(html, "site-toasts")[0]?.attributes.role).toBe("status");
270
- expect(bySlot(html, "site-toast").map((tag) => tag.attributes["data-action"])).toEqual(["false", "true"]);
271
- expect(bySlot(html, "site-toast-dot").map((tag) => tag.attributes["data-tone"])).toEqual(["good", "bad"]);
272
- expect(bySlot(html, "site-toast-action")).toHaveLength(1);
273
- expect(ownUnmarked(html)).toEqual([]);
274
- });
275
- });