@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.
- package/README.md +4 -3
- package/dist/account/index.d.ts +1 -1
- package/dist/account/index.js +3 -3
- package/dist/action/index.d.ts +59 -3
- package/dist/action/index.js +82 -0
- package/dist/action/index.js.map +1 -1
- package/dist/checkout/index.d.ts +1 -1
- package/dist/checkout/index.js +1 -1
- package/dist/{chunk-BJUU2WTX.js → chunk-EELJOGWB.js} +12 -5
- package/dist/chunk-EELJOGWB.js.map +1 -0
- package/dist/{chunk-7K476KMZ.js → chunk-EOTYGKKM.js} +3 -3
- package/dist/{chunk-7K476KMZ.js.map → chunk-EOTYGKKM.js.map} +1 -1
- package/dist/{chunk-FKC262N4.js → chunk-EWBTUSZY.js} +9 -3
- package/dist/chunk-EWBTUSZY.js.map +1 -0
- package/dist/{chunk-5TFLOQT6.js → chunk-HRRP6HMF.js} +10 -5
- package/dist/chunk-HRRP6HMF.js.map +1 -0
- package/dist/{chunk-4KFQ26JW.js → chunk-HZGBIIGN.js} +27 -6
- package/dist/chunk-HZGBIIGN.js.map +1 -0
- package/dist/{chunk-JJQJFRBI.js → chunk-OWQVRM4W.js} +3 -3
- package/dist/{chunk-JJQJFRBI.js.map → chunk-OWQVRM4W.js.map} +1 -1
- package/dist/{chunk-6S23FFBB.js → chunk-TGG4ZKPG.js} +3 -3
- package/dist/{chunk-6S23FFBB.js.map → chunk-TGG4ZKPG.js.map} +1 -1
- package/dist/{chunk-JVMJF5JJ.js → chunk-UF2MDCWB.js} +5 -5
- package/dist/chunk-UF2MDCWB.js.map +1 -0
- package/dist/{chunk-EG6GE3YS.js → chunk-YXASVWY7.js} +3 -3
- package/dist/{chunk-EG6GE3YS.js.map → chunk-YXASVWY7.js.map} +1 -1
- package/dist/content/index.d.ts +95 -0
- package/dist/content/index.js +85 -0
- package/dist/content/index.js.map +1 -0
- package/dist/form/index.d.ts +229 -8
- package/dist/form/index.js +150 -10
- package/dist/form/index.js.map +1 -1
- package/dist/help/index.d.ts +1 -1
- package/dist/help/index.js +6 -6
- package/dist/install/index.d.ts +1 -1
- package/dist/install/index.js +4 -4
- package/dist/legal/index.d.ts +2 -2
- package/dist/legal/index.js +5 -5
- package/dist/link/index.d.ts +14 -1
- package/dist/link/index.js +8 -1
- package/dist/link/index.js.map +1 -1
- package/dist/marketing/index.d.ts +1 -1
- package/dist/page/index.d.ts +2 -2
- package/dist/page/index.js +4 -4
- package/dist/pricing/index.d.ts +1 -1
- package/dist/pricing/index.js +2 -2
- package/dist/shell/index.d.ts +1 -1
- package/dist/{site-action-B79fuwMb.d.ts → site-action-CPpf8JZl.d.ts} +1 -1
- package/dist/{site-page-Dl0A5T1N.d.ts → site-page-DKcjqh9y.d.ts} +7 -2
- package/package.json +10 -3
- package/src/action/action-tile.style.ts +63 -0
- package/src/action/action-tile.tsx +83 -0
- package/src/action/index.ts +11 -0
- package/src/content/content.style.ts +72 -0
- package/src/content/content.tsx +124 -0
- package/src/content/index.ts +12 -0
- package/src/form/choices.style.ts +16 -0
- package/src/form/choices.tsx +28 -5
- package/src/form/country-field.tsx +61 -0
- package/src/form/date-time.style.ts +26 -0
- package/src/form/date-time.tsx +123 -0
- package/src/form/dialog.style.ts +4 -2
- package/src/form/errors.tsx +16 -4
- package/src/form/form.style.ts +8 -0
- package/src/form/index.ts +11 -1
- package/src/form/phone-field.tsx +98 -0
- package/src/form/select.style.ts +6 -1
- package/src/form/select.tsx +13 -3
- package/src/form/signature.style.ts +20 -0
- package/src/form/signature.tsx +46 -0
- package/src/link/index.ts +1 -0
- package/src/link/mounted-href.ts +16 -0
- package/src/page/site-page.style.ts +13 -4
- package/src/page/site-page.tsx +8 -3
- package/src/styles/designs/base.css +121 -4
- package/templates/app-shell.hbs +5 -4
- package/dist/chunk-4KFQ26JW.js.map +0 -1
- package/dist/chunk-5TFLOQT6.js.map +0 -1
- package/dist/chunk-BJUU2WTX.js.map +0 -1
- package/dist/chunk-FKC262N4.js.map +0 -1
- package/dist/chunk-JVMJF5JJ.js.map +0 -1
- package/src/account/account.test.tsx +0 -186
- package/src/action/site-action.test.tsx +0 -154
- package/src/auth/auth.test.tsx +0 -132
- package/src/checkout/checkout.test.tsx +0 -187
- package/src/form/choices-field.test.tsx +0 -20
- package/src/form/errors.test.tsx +0 -49
- package/src/form/form.test.tsx +0 -275
- package/src/form/question-focus.test.ts +0 -182
- package/src/form/slider.test.tsx +0 -148
- package/src/form/typed-text.test.ts +0 -52
- package/src/help/article.test.tsx +0 -189
- package/src/help/help.test.tsx +0 -215
- package/src/help/screen-sketch.test.tsx +0 -59
- package/src/install/install.test.tsx +0 -177
- package/src/legal/legal.test.tsx +0 -161
- package/src/legal/policy.test.tsx +0 -137
- package/src/legal/refund.test.tsx +0 -148
- package/src/link/routes-in-page.test.ts +0 -26
- package/src/link/site-link.test.ts +0 -10
- package/src/marketing/marketing.test.tsx +0 -221
- package/src/page/site-failure.test.tsx +0 -65
- package/src/page/site-page.test.tsx +0 -109
- package/src/page/site-read.test.tsx +0 -41
- package/src/pricing/pack-card.test.tsx +0 -107
- package/src/pricing/pricing.test.tsx +0 -261
- package/src/shell/refusal-page.test.ts +0 -19
- package/src/shell/site-scheme-param.test.ts +0 -53
- package/src/shell/site-scheme-switch.test.ts +0 -80
- package/src/shell/site-scheme.test.ts +0 -149
- package/src/shell/site-shell.test.tsx +0 -401
- package/src/testing/markup.ts +0 -65
|
@@ -1,186 +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 { AccountLayout, SectionHead, SectionNav } from "./account-layout";
|
|
6
|
-
import { siteSectionHeadStyle } from "./account.style";
|
|
7
|
-
import { dayHeight, DaySeries, PanelLine, QuotaMeter, shareWidth, SitePanel, TableActions, TableCard } from "./figures";
|
|
8
|
-
import { IdentityRow, SettingsActions, SettingsBox, SettingsRow, SettingsRows, SettingsText } from "./settings";
|
|
9
|
-
|
|
10
|
-
const sections = [
|
|
11
|
-
{ key: "sub", label: "Subscription", href: "/account/sub", current: true },
|
|
12
|
-
{ key: "credits", label: "Credits", href: "/account/credits" },
|
|
13
|
-
{ key: "leave", label: "Delete account", href: "/account/leave", danger: true },
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
describe("AccountLayout", () => {
|
|
17
|
-
it("draws the section list beside the section, the standing notice first in the section", () => {
|
|
18
|
-
const html = renderToStaticMarkup(
|
|
19
|
-
<AccountLayout nav={<SectionNav label="My account" items={sections} />} standing={<div data-slot="site-banner">failed</div>}>
|
|
20
|
-
<SectionHead>Subscription</SectionHead>
|
|
21
|
-
</AccountLayout>,
|
|
22
|
-
);
|
|
23
|
-
const order = tagsOf(html).map((tag) => tag.attributes["data-slot"]).filter(Boolean);
|
|
24
|
-
expect(order.indexOf("site-section-nav")).toBeLessThan(order.indexOf("site-account-section"));
|
|
25
|
-
expect(order.indexOf("site-banner")).toBeLessThan(order.indexOf("site-section-head"));
|
|
26
|
-
expect(unmarked(html)).toEqual([]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("marks the current section as the page, and the deleting one in the bad colour only while it is not current", () => {
|
|
30
|
-
const html = renderToStaticMarkup(<SectionNav label="My account" items={sections} />);
|
|
31
|
-
const items = bySlot(html, "site-section-nav-item");
|
|
32
|
-
expect(items.map((item) => item.attributes["data-state"])).toEqual(["current", "plain", "danger"]);
|
|
33
|
-
expect(items[0]?.attributes["aria-current"]).toBe("page");
|
|
34
|
-
expect(items.every((item) => item.name === "a" && item.attributes.href?.startsWith("/account/"))).toBe(true);
|
|
35
|
-
const leaving = bySlot(renderToStaticMarkup(<SectionNav label="My account" items={sections.map((item) => ({ ...item, current: item.key === "leave" }))} />), "site-section-nav-item");
|
|
36
|
-
expect(leaving[2]?.attributes["data-state"]).toBe("current");
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("draws a section without an address as its words in its place, with no press and the look of its state", () => {
|
|
40
|
-
const html = renderToStaticMarkup(<SectionNav label="My account" items={[...sections.slice(0, 2), { key: "receipts", label: "Receipts" }, { key: "leave", label: "Delete account", danger: true }]} />);
|
|
41
|
-
const items = bySlot(html, "site-section-nav-item");
|
|
42
|
-
expect(items.map((item) => [item.name, item.attributes["data-state"], item.attributes["data-pending"]])).toEqual([
|
|
43
|
-
["a", "current", "false"],
|
|
44
|
-
["a", "plain", "false"],
|
|
45
|
-
["span", "plain", "true"],
|
|
46
|
-
["span", "danger", "true"],
|
|
47
|
-
]);
|
|
48
|
-
expect(items.slice(2).some((item) => "href" in item.attributes || "aria-current" in item.attributes)).toBe(false);
|
|
49
|
-
expect(tabStops(html)).toHaveLength(2);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("draws a section title as h2 and a part title as h3", () => {
|
|
53
|
-
const title = bySlot(renderToStaticMarkup(<SectionHead>Credits</SectionHead>), "site-section-head")[0];
|
|
54
|
-
expect(title?.name).toBe("h2");
|
|
55
|
-
// The section title takes a focus a part of the section dropped, and is no Tab stop.
|
|
56
|
-
expect(title?.attributes.tabindex).toBe("-1");
|
|
57
|
-
const sub = bySlot(renderToStaticMarkup(<SectionHead level={3}>Credit history</SectionHead>), "site-section-head")[0];
|
|
58
|
-
expect(sub?.name).toBe("h3");
|
|
59
|
-
expect(sub?.attributes["data-level"]).toBe("3");
|
|
60
|
-
expect(sub?.attributes.tabindex).toBeUndefined();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("draws the section title as the page's h1 where nothing stands above it, looking as it does at level 2", () => {
|
|
64
|
-
const page = bySlot(renderToStaticMarkup(<SectionHead level={1}>Credits</SectionHead>), "site-section-head")[0];
|
|
65
|
-
expect(page?.name).toBe("h1");
|
|
66
|
-
expect(page?.attributes["data-level"]).toBe("1");
|
|
67
|
-
// It takes the focus a part of the section dropped, as the level 2 title does.
|
|
68
|
-
expect(page?.attributes.tabindex).toBe("-1");
|
|
69
|
-
expect(siteSectionHeadStyle.variants.level["1"]).toBe(siteSectionHeadStyle.variants.level["2"]);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe("settings", () => {
|
|
74
|
-
it("draws a row's title with its chip, its line and its small actions", () => {
|
|
75
|
-
const html = renderToStaticMarkup(
|
|
76
|
-
<SettingsRows>
|
|
77
|
-
<SettingsRow title="Pro" badge={<span data-slot="site-chip">Active</span>} meta="Next payment Nov 14" actions={[{ id: "change", label: "Change plan" }]} />
|
|
78
|
-
<SettingsRow title="Email" meta="t@example.com" />
|
|
79
|
-
</SettingsRows>,
|
|
80
|
-
);
|
|
81
|
-
expect(bySlot(html, "site-settings-row")).toHaveLength(2);
|
|
82
|
-
expect(bySlot(html, "site-settings-row-actions")).toHaveLength(1);
|
|
83
|
-
expect(bySlot(html, "site-action")[0]?.attributes["data-size"]).toBe("sm");
|
|
84
|
-
expect(unmarked(html)).toEqual([]);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("draws a question on a card in its tone, its text and its actions", () => {
|
|
88
|
-
const html = renderToStaticMarkup(
|
|
89
|
-
<SettingsBox tone="danger">
|
|
90
|
-
<SettingsText tone="muted">You keep it until Nov 14.</SettingsText>
|
|
91
|
-
<SettingsActions actions={[{ id: "cancel", label: "Cancel", tone: "danger" }, { id: "keep", label: "Keep" }]} />
|
|
92
|
-
</SettingsBox>,
|
|
93
|
-
);
|
|
94
|
-
expect(bySlot(html, "site-settings-box")[0]?.attributes["data-tone"]).toBe("danger");
|
|
95
|
-
// The question takes the focus when it opens (useQuestionFocus), as a group, and is never a Tab stop.
|
|
96
|
-
expect(bySlot(html, "site-settings-box")[0]?.attributes.tabindex).toBe("-1");
|
|
97
|
-
expect(bySlot(html, "site-settings-box")[0]?.attributes.role).toBe("group");
|
|
98
|
-
expect(bySlot(html, "site-settings-text")[0]?.attributes["data-tone"]).toBe("muted");
|
|
99
|
-
expect(bySlot(html, "site-action").map((tag) => tag.attributes["data-tone"])).toEqual(["danger", "secondary"]);
|
|
100
|
-
const alone = bySlot(renderToStaticMarkup(<SettingsActions size="md" actions={[{ id: "cancel", label: "Cancel subscription", tone: "subtle" }]} />), "site-action")[0];
|
|
101
|
-
expect(alone?.attributes["data-size"]).toBe("md");
|
|
102
|
-
expect(alone?.attributes["data-pad"]).toBe("quietMd");
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("names the identity mark only when it is given a name", () => {
|
|
106
|
-
const named = renderToStaticMarkup(<IdentityRow tone="voice" mark="V" markLabel="My voice" name="My voice" meta="Made Oct 2" />);
|
|
107
|
-
expect(bySlot(named, "site-identity-mark")[0]?.attributes.role).toBe("img");
|
|
108
|
-
expect(bySlot(named, "site-identity-mark")[0]?.attributes["data-tone"]).toBe("voice");
|
|
109
|
-
const plain = renderToStaticMarkup(<IdentityRow mark="T" name="Taylor" />);
|
|
110
|
-
expect(bySlot(plain, "site-identity-mark")[0]?.attributes["aria-hidden"]).toBe("true");
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe("figures", () => {
|
|
115
|
-
it("holds a meter's share between empty and full", () => {
|
|
116
|
-
expect(shareWidth(0.25)).toBe("25%");
|
|
117
|
-
expect(shareWidth(1.4)).toBe("100%");
|
|
118
|
-
expect(shareWidth(-1)).toBe("0%");
|
|
119
|
-
expect(shareWidth(Number.NaN)).toBe("0%");
|
|
120
|
-
const html = renderToStaticMarkup(<QuotaMeter share={0.5} label="Half used" start="This month" end={<b>Half left</b>} />);
|
|
121
|
-
expect(bySlot(html, "site-quota-track")[0]?.attributes["aria-label"]).toBe("Half used");
|
|
122
|
-
expect(html).toContain("width:50%");
|
|
123
|
-
expect(unmarked(html.replace(/<b>|<\/b>/g, ""))).toEqual([]);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("draws each day as a bar a share of the tallest high, a day without use at the floor, and reads each day out", () => {
|
|
127
|
-
expect(dayHeight(50, 100)).toBe("50%");
|
|
128
|
-
expect(dayHeight(0, 100)).toBe("2%");
|
|
129
|
-
const html = renderToStaticMarkup(
|
|
130
|
-
<DaySeries
|
|
131
|
-
days={[
|
|
132
|
-
{ key: "1", value: 0, label: "Oct 1: 0 characters" },
|
|
133
|
-
{ key: "2", value: 200, label: "Oct 2: 200 characters" },
|
|
134
|
-
]}
|
|
135
|
-
from="Oct 1"
|
|
136
|
-
to="Oct 2"
|
|
137
|
-
/>,
|
|
138
|
-
);
|
|
139
|
-
expect(bySlot(html, "site-day-bar")).toHaveLength(2);
|
|
140
|
-
expect(bySlot(html, "site-day-label").map((tag) => tag.name)).toEqual(["span", "span"]);
|
|
141
|
-
expect(html).toContain("height:100%");
|
|
142
|
-
expect(bySlot(html, "site-day-axis")[0]?.attributes["aria-hidden"]).toBe("true");
|
|
143
|
-
expect(unmarked(html)).toEqual([]);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("draws a table with the first column bold, the middle muted and the last at the end, and a pager for a growing set", () => {
|
|
147
|
-
const html = renderToStaticMarkup(
|
|
148
|
-
<TableCard
|
|
149
|
-
label="Credit history"
|
|
150
|
-
columns={[
|
|
151
|
-
{ key: "item", label: "Item" },
|
|
152
|
-
{ key: "when", label: "Date" },
|
|
153
|
-
{ key: "amount", label: "Characters" },
|
|
154
|
-
]}
|
|
155
|
-
rows={[{ key: "a", cells: { item: "Premium voice", when: "Oct 14", amount: "-640" } }]}
|
|
156
|
-
more={{ id: "more", label: "Show more" }}
|
|
157
|
-
/>,
|
|
158
|
-
);
|
|
159
|
-
expect(bySlot(html, "site-table-card-cell").map((tag) => tag.attributes["data-kind"])).toEqual(["lead", "value", "end"]);
|
|
160
|
-
expect(bySlot(html, "site-table-card-th").map((tag) => tag.attributes["data-end"])).toEqual(["false", "false", "true"]);
|
|
161
|
-
expect(bySlot(html, "site-table-card-more")).toHaveLength(1);
|
|
162
|
-
expect(bySlot(html, "site-action")[0]?.attributes["data-tone"]).toBe("quiet");
|
|
163
|
-
// Each row can take the focus `more` moves to the first row it added, and none is a Tab stop.
|
|
164
|
-
expect(bySlot(html, "site-table-card-row").map((tag) => tag.attributes.tabindex)).toEqual(["-1"]);
|
|
165
|
-
expect(tabStops(html)).toHaveLength(1);
|
|
166
|
-
expect(unmarked(html)).toEqual([]);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("draws a panel with its title, a line with its action and a row's actions", () => {
|
|
170
|
-
const html = renderToStaticMarkup(
|
|
171
|
-
<SitePanel title="Last 14 days" label="Last 14 days">
|
|
172
|
-
<PanelLine action={{ id: "top-up", label: "Top up credits", href: "/checkout" }}>Extra credits 0</PanelLine>
|
|
173
|
-
<TableActions actions={[{ id: "pdf", label: "PDF" }]} />
|
|
174
|
-
</SitePanel>,
|
|
175
|
-
);
|
|
176
|
-
expect(bySlot(html, "site-panel")[0]?.attributes["aria-label"]).toBe("Last 14 days");
|
|
177
|
-
expect(bySlot(html, "site-panel-title")[0]?.name).toBe("h3");
|
|
178
|
-
expect(tabStops(html)).toHaveLength(2);
|
|
179
|
-
expect(unmarked(html)).toEqual([]);
|
|
180
|
-
});
|
|
181
|
-
it("draws a row's state before its actions", () => {
|
|
182
|
-
const html = renderToStaticMarkup(<TableActions badge={<span data-slot="site-chip">Refund requested</span>} actions={[{ id: "pdf", label: "PDF" }]} />);
|
|
183
|
-
expect(html.indexOf('data-slot="site-chip"')).toBeGreaterThan(-1);
|
|
184
|
-
expect(html.indexOf('data-slot="site-chip"')).toBeLessThan(html.indexOf('data-slot="site-action"'));
|
|
185
|
-
});
|
|
186
|
-
});
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { PlainSiteLink, SiteLinkProvider, type SiteLinkProps } from "../link/site-link";
|
|
5
|
-
import { bySlot, silentRefusals, tabStops, unmarked } from "../testing/markup";
|
|
6
|
-
import { SiteAction, type SiteActionSpec } from "./site-action";
|
|
7
|
-
import { siteActionStyle } from "./site-action.style";
|
|
8
|
-
|
|
9
|
-
describe("SiteAction", () => {
|
|
10
|
-
it("draws an action with an address as a link and one without as a button", () => {
|
|
11
|
-
const link = bySlot(renderToStaticMarkup(<SiteAction id="go" label="Go" href="/go" />), "site-action")[0];
|
|
12
|
-
expect(link?.name).toBe("a");
|
|
13
|
-
expect(link?.attributes.href).toBe("/go");
|
|
14
|
-
const button = bySlot(renderToStaticMarkup(<SiteAction id="go" label="Go" />), "site-action")[0];
|
|
15
|
-
expect(button?.name).toBe("button");
|
|
16
|
-
expect(button?.attributes.type).toBe("button");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("draws a disabled action as a disabled button even when it has an address", () => {
|
|
20
|
-
const html = renderToStaticMarkup(<SiteAction id="top-up" label="Top up" href="/checkout" disabled reason="Pick a plan first" />);
|
|
21
|
-
const action = bySlot(html, "site-action")[0];
|
|
22
|
-
expect(action?.name).toBe("button");
|
|
23
|
-
expect(action?.attributes.disabled).toBeDefined();
|
|
24
|
-
expect(html).not.toContain("href=");
|
|
25
|
-
expect(tabStops(html)).toEqual([]);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("draws a pending action as a disabled button that says what it waits for, even with an address or a line of its own", () => {
|
|
29
|
-
const html = renderToStaticMarkup(<SiteAction id="send" label="Send" href="/send" describedBy="note" onSelect={() => undefined} pending="Sending the request" />);
|
|
30
|
-
const action = bySlot(html, "site-action")[0];
|
|
31
|
-
const reason = bySlot(html, "site-action-reason")[0];
|
|
32
|
-
expect(action?.name).toBe("button");
|
|
33
|
-
expect(action?.attributes.disabled).toBeDefined();
|
|
34
|
-
expect(action?.attributes["aria-describedby"]).toBe(reason?.attributes.id);
|
|
35
|
-
expect(html).toContain(">Sending the request</span>");
|
|
36
|
-
expect(html).not.toContain("href=");
|
|
37
|
-
// It is marked busy, which the design draws in the action's own tone and not in the disabled grey.
|
|
38
|
-
expect(action?.attributes["aria-busy"]).toBe("true");
|
|
39
|
-
// Without a wait the same spec presses again, with no reason drawn.
|
|
40
|
-
const idle = renderToStaticMarkup(<SiteAction id="send" label="Send" onSelect={() => undefined} pending={undefined} />);
|
|
41
|
-
expect(bySlot(idle, "site-action")[0]?.attributes.disabled).toBeUndefined();
|
|
42
|
-
expect(bySlot(idle, "site-action")[0]?.attributes["aria-busy"]).toBeUndefined();
|
|
43
|
-
expect(bySlot(idle, "site-action-reason")).toEqual([]);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("draws a refused action that is not waiting without the busy mark, so it keeps the disabled look", () => {
|
|
47
|
-
const refused = bySlot(renderToStaticMarkup(<SiteAction id="a" label="A" disabled reason="Pick a plan first" />), "site-action")[0];
|
|
48
|
-
expect(refused?.attributes.disabled).toBeDefined();
|
|
49
|
-
expect(refused?.attributes["aria-busy"]).toBeUndefined();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it("writes its tone, size and width as the variants the design draws, secondary and medium by default", () => {
|
|
53
|
-
const plain = bySlot(renderToStaticMarkup(<SiteAction id="a" label="A" />), "site-action")[0];
|
|
54
|
-
expect(plain?.attributes["data-tone"]).toBe("secondary");
|
|
55
|
-
expect(plain?.attributes["data-size"]).toBe("md");
|
|
56
|
-
expect(plain?.attributes["data-block"]).toBe("false");
|
|
57
|
-
const set = bySlot(renderToStaticMarkup(<SiteAction id="a" label="A" tone="quiet" size="sm" block />), "site-action")[0];
|
|
58
|
-
expect(set?.attributes["data-tone"]).toBe("quiet");
|
|
59
|
-
expect(set?.attributes["data-size"]).toBe("sm");
|
|
60
|
-
expect(set?.attributes["data-block"]).toBe("true");
|
|
61
|
-
expect(set?.attributes["data-action"]).toBe("a");
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("lets a block action wrap a label too long for its column, and keeps every other action on one line at least as tall as its size", () => {
|
|
65
|
-
expect(siteActionStyle.base).toContain("whitespace-nowrap");
|
|
66
|
-
expect(siteActionStyle.variants.block.true).toContain("whitespace-normal");
|
|
67
|
-
expect(siteActionStyle.variants.block.true).toContain("[overflow-wrap:anywhere]");
|
|
68
|
-
expect(siteActionStyle.variants.block.false).toBe("");
|
|
69
|
-
for (const size of ["md", "sm", "lg"] as const) {
|
|
70
|
-
expect(siteActionStyle.variants.size[size]).toMatch(/(?:^|\s)min-h-\(--site-control/);
|
|
71
|
-
expect(siteActionStyle.variants.size[size]).not.toMatch(/(?:^|\s)h-\(--site-control/);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("is described by the line it names, as a link and as a disabled button", () => {
|
|
76
|
-
const button = bySlot(renderToStaticMarkup(<SiteAction id="a" label="Top up" disabled reason="Pick a plan first" describedBy="why" />), "site-action")[0];
|
|
77
|
-
expect(button?.attributes["aria-describedby"]).toBe("why");
|
|
78
|
-
const link = bySlot(renderToStaticMarkup(<SiteAction id="a" label="Open" href="/a" describedBy="about" />), "site-action")[0];
|
|
79
|
-
expect(link?.attributes["aria-describedby"]).toBe("about");
|
|
80
|
-
expect(bySlot(renderToStaticMarkup(<SiteAction id="a" label="A" />), "site-action")[0]?.attributes["aria-describedby"]).toBeUndefined();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("draws a disabled action's reason for a screen reader beside it and is described by it, when no line says why", () => {
|
|
84
|
-
const html = renderToStaticMarkup(<SiteAction id="top-up" label="Top up" disabled reason="Extra credits need a paid plan" />);
|
|
85
|
-
const action = bySlot(html, "site-action")[0];
|
|
86
|
-
const reason = bySlot(html, "site-action-reason")[0];
|
|
87
|
-
expect(reason?.name).toBe("span");
|
|
88
|
-
expect(reason?.attributes.id).toBeTruthy();
|
|
89
|
-
expect(action?.attributes["aria-describedby"]).toBe(reason?.attributes.id);
|
|
90
|
-
expect(html).toContain(">Extra credits need a paid plan</span>");
|
|
91
|
-
expect(silentRefusals(html)).toEqual([]);
|
|
92
|
-
expect(unmarked(html)).toEqual([]);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("is described by the line a part names instead of its hidden reason, and draws no reason while it can run", () => {
|
|
96
|
-
const lined = renderToStaticMarkup(<SiteAction id="a" label="Top up" disabled reason="Pick a plan first" describedBy="why" />);
|
|
97
|
-
expect(bySlot(lined, "site-action-reason")).toEqual([]);
|
|
98
|
-
const open = renderToStaticMarkup(<SiteAction id="a" label="Top up" disabled={false} reason="Pick a plan first" />);
|
|
99
|
-
expect(bySlot(open, "site-action-reason")).toEqual([]);
|
|
100
|
-
expect(bySlot(open, "site-action")[0]?.attributes["aria-describedby"]).toBeUndefined();
|
|
101
|
-
const linked = renderToStaticMarkup(<SiteAction id="a" label="Top up" href="/top-up" reason="Pick a plan first" />);
|
|
102
|
-
expect(bySlot(linked, "site-action-reason")).toEqual([]);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("refuses by type a disabled action without its reason, a computed flag included", () => {
|
|
106
|
-
const paid = false as boolean;
|
|
107
|
-
const spec = (action: SiteActionSpec) => action;
|
|
108
|
-
// @ts-expect-error a disabled action carries the reason it cannot run
|
|
109
|
-
expect(spec({ id: "a", label: "A", disabled: true })).toBeDefined();
|
|
110
|
-
// @ts-expect-error a flag computed at the call site needs the reason beside it too
|
|
111
|
-
expect(spec({ id: "a", label: "A", disabled: !paid })).toBeDefined();
|
|
112
|
-
// @ts-expect-error the reason is words, never an empty value
|
|
113
|
-
expect(spec({ id: "a", label: "A", disabled: true, reason: undefined })).toBeDefined();
|
|
114
|
-
expect(spec({ id: "a", label: "A", disabled: !paid, reason: "Pick a plan first" })).toBeDefined();
|
|
115
|
-
expect(spec({ id: "a", label: "A" })).toBeDefined();
|
|
116
|
-
expect(spec({ id: "a", label: "A", disabled: false })).toBeDefined();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it("carries the element id a server script finds it by, and a pressed submit's own field", () => {
|
|
120
|
-
const passkey = bySlot(renderToStaticMarkup(<SiteAction id="passkey" elementId="authenticateWebAuthnButton" label="Passkey" />), "site-action")[0];
|
|
121
|
-
expect(passkey?.attributes.id).toBe("authenticateWebAuthnButton");
|
|
122
|
-
const cancel = bySlot(renderToStaticMarkup(<SiteAction id="cancel" submit field={{ name: "cancel-aia", value: "true" }} label="Cancel" />), "site-action")[0];
|
|
123
|
-
expect([cancel?.attributes.type, cancel?.attributes.name, cancel?.attributes.value]).toEqual(["submit", "cancel-aia", "true"]);
|
|
124
|
-
const plain = bySlot(renderToStaticMarkup(<SiteAction id="cancel" field={{ name: "cancel-aia", value: "true" }} label="Cancel" />), "site-action")[0];
|
|
125
|
-
expect(plain?.attributes.name).toBeUndefined();
|
|
126
|
-
expect(bySlot(renderToStaticMarkup(<SiteAction id="go" label="Go" />), "site-action")[0]?.attributes.id).toBeUndefined();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("draws its icon before its label", () => {
|
|
130
|
-
const html = renderToStaticMarkup(<SiteAction id="a" label="Download" icon={<svg data-slot="glyph" />} />);
|
|
131
|
-
expect(html.indexOf("glyph")).toBeLessThan(html.indexOf("Download"));
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("SiteLink", () => {
|
|
136
|
-
it("draws a plain anchor without a provider and the product's link under one", () => {
|
|
137
|
-
expect(renderToStaticMarkup(<SiteAction id="a" label="A" href="/a" />)).toMatch(/^<a /);
|
|
138
|
-
const Routed = (props: SiteLinkProps) => <a {...props} data-router="yes" />;
|
|
139
|
-
const html = renderToStaticMarkup(
|
|
140
|
-
<SiteLinkProvider component={Routed}>
|
|
141
|
-
<SiteAction id="a" label="A" href="/a" />
|
|
142
|
-
</SiteLinkProvider>,
|
|
143
|
-
);
|
|
144
|
-
expect(html).toContain('data-router="yes"');
|
|
145
|
-
expect(html).toContain('data-slot="site-action"');
|
|
146
|
-
const reset = renderToStaticMarkup(
|
|
147
|
-
<SiteLinkProvider>
|
|
148
|
-
<SiteAction id="a" label="A" href="/a" />
|
|
149
|
-
</SiteLinkProvider>,
|
|
150
|
-
);
|
|
151
|
-
expect(reset).not.toContain("data-router");
|
|
152
|
-
expect(renderToStaticMarkup(<PlainSiteLink href="/x">x</PlainSiteLink>)).toBe('<a href="/x">x</a>');
|
|
153
|
-
});
|
|
154
|
-
});
|
package/src/auth/auth.test.tsx
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { bySlot, tagsOf, unmarked } from "../testing/markup";
|
|
5
|
-
import { AuthAlert, AuthCard, AuthDoneMark, AuthFieldHead, AuthForm, AuthLink, AuthLinks, AuthOr, AuthPage, AuthProviders, AuthText, PasswordRules, PasswordStrength, submitAuthForm } from "./auth";
|
|
6
|
-
|
|
7
|
-
describe("AuthPage and AuthCard", () => {
|
|
8
|
-
it("draws the step as the page, its card headed by the mark and the one h1", () => {
|
|
9
|
-
const html = renderToStaticMarkup(
|
|
10
|
-
<AuthPage step="signIn">
|
|
11
|
-
<AuthCard title="Sign in" mark={<svg data-slot="glyph" />}>
|
|
12
|
-
<AuthText size="body">Welcome back</AuthText>
|
|
13
|
-
</AuthCard>
|
|
14
|
-
</AuthPage>,
|
|
15
|
-
);
|
|
16
|
-
const root = bySlot(html, "site-auth")[0];
|
|
17
|
-
expect(root?.attributes["data-page"]).toBe("signIn");
|
|
18
|
-
expect(root?.attributes["data-band"]).toBeUndefined();
|
|
19
|
-
expect(bySlot(html, "site-auth-title")[0]?.name).toBe("h1");
|
|
20
|
-
expect(bySlot(html, "site-auth-card")[0]?.attributes["aria-label"]).toBe("Sign in");
|
|
21
|
-
expect(unmarked(html)).toEqual([]);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
it("takes the dark values on a dark scheme", () => {
|
|
25
|
-
const html = renderToStaticMarkup(
|
|
26
|
-
<AuthPage step="code" scheme="dark">
|
|
27
|
-
<AuthCard title="Code">x</AuthCard>
|
|
28
|
-
</AuthPage>,
|
|
29
|
-
);
|
|
30
|
-
expect(bySlot(html, "site-auth")[0]?.attributes["data-band"]).toBe("dark");
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
describe("the card's parts", () => {
|
|
35
|
-
it("sets a form's fields apart, and a passkey form that is only its submit not at all", () => {
|
|
36
|
-
expect(bySlot(renderToStaticMarkup(<AuthForm>x</AuthForm>), "site-auth-form")[0]?.attributes["data-gap"]).toBe("fields");
|
|
37
|
-
const passkey = bySlot(renderToStaticMarkup(<AuthForm gap="none">x</AuthForm>), "site-auth-form")[0];
|
|
38
|
-
expect(passkey?.attributes["data-gap"]).toBe("none");
|
|
39
|
-
expect(passkey?.attributes.novalidate ?? passkey?.attributes.noValidate).toBeDefined();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("hands a step's values to the step, and lets the browser post a server page's form", () => {
|
|
43
|
-
let prevented = 0;
|
|
44
|
-
let handed = 0;
|
|
45
|
-
const event = { preventDefault: () => (prevented += 1) };
|
|
46
|
-
submitAuthForm(event, undefined, () => (handed += 1));
|
|
47
|
-
expect([prevented, handed]).toEqual([1, 1]);
|
|
48
|
-
submitAuthForm(event, "https://id.example/login-actions/authenticate", () => (handed += 1));
|
|
49
|
-
expect([prevented, handed]).toEqual([1, 2]);
|
|
50
|
-
submitAuthForm(event, "https://id.example/login-actions/authenticate", undefined);
|
|
51
|
-
expect(prevented).toBe(1);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("names the address, the method and the id of a posted form, and none on a step's own form", () => {
|
|
55
|
-
const posted = bySlot(renderToStaticMarkup(<AuthForm action="/act" id="kc-form-login">x</AuthForm>), "site-auth-form")[0];
|
|
56
|
-
expect(posted?.attributes.action).toBe("/act");
|
|
57
|
-
expect(posted?.attributes.method).toBe("post");
|
|
58
|
-
expect(posted?.attributes.id).toBe("kc-form-login");
|
|
59
|
-
const own = bySlot(renderToStaticMarkup(<AuthForm>x</AuthForm>), "site-auth-form")[0];
|
|
60
|
-
expect(own?.attributes.action).toBeUndefined();
|
|
61
|
-
expect(own?.attributes.method).toBeUndefined();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("speaks a wrong value at once and a status only on request", () => {
|
|
65
|
-
expect(bySlot(renderToStaticMarkup(<AuthAlert>Wrong password</AuthAlert>), "site-auth-alert")[0]?.attributes.role).toBe("alert");
|
|
66
|
-
expect(bySlot(renderToStaticMarkup(<AuthText live>Signed in</AuthText>), "site-auth-text")[0]?.attributes.role).toBe("status");
|
|
67
|
-
expect(bySlot(renderToStaticMarkup(<AuthText>Fine print</AuthText>), "site-auth-text")[0]?.attributes.role).toBeUndefined();
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("draws a refusal's glyph beside its words, hidden from a screen reader, and nothing extra without one", () => {
|
|
71
|
-
const marked = renderToStaticMarkup(<AuthAlert mark={<svg data-slot="glyph" />}>Wrong password</AuthAlert>);
|
|
72
|
-
const alert = bySlot(marked, "site-auth-alert")[0];
|
|
73
|
-
expect([alert?.attributes.role, alert?.attributes["data-marked"]]).toEqual(["alert", "true"]);
|
|
74
|
-
const mark = bySlot(marked, "site-auth-alert-mark")[0];
|
|
75
|
-
expect(mark?.attributes["aria-hidden"]).toBe("true");
|
|
76
|
-
expect(marked.indexOf("glyph")).toBeLessThan(marked.indexOf("Wrong password"));
|
|
77
|
-
const plain = renderToStaticMarkup(<AuthAlert>Wrong password</AuthAlert>);
|
|
78
|
-
expect(bySlot(plain, "site-auth-alert")[0]?.attributes["data-marked"]).toBe("false");
|
|
79
|
-
expect(bySlot(plain, "site-auth-alert-mark")).toEqual([]);
|
|
80
|
-
expect(plain).toContain(">Wrong password</p>");
|
|
81
|
-
expect(unmarked(marked)).toEqual([]);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it("fills the strength bars up to the score and names the strength", () => {
|
|
85
|
-
const html = renderToStaticMarkup(<PasswordStrength score={2} label="Password strength 2 of 3" />);
|
|
86
|
-
expect(bySlot(html, "site-password-step").map((tag) => tag.attributes["data-on"])).toEqual(["true", "true", "false"]);
|
|
87
|
-
expect(bySlot(html, "site-password-strength")[0]?.attributes["aria-label"]).toBe("Password strength 2 of 3");
|
|
88
|
-
expect(unmarked(html)).toEqual([]);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("ticks a met rule and tells a screen reader it is met", () => {
|
|
92
|
-
const html = renderToStaticMarkup(
|
|
93
|
-
<PasswordRules
|
|
94
|
-
mark={<svg data-slot="glyph" />}
|
|
95
|
-
metLabel="met"
|
|
96
|
-
rules={[
|
|
97
|
-
{ key: "length", label: "At least 10 characters", met: true },
|
|
98
|
-
{ key: "mix", label: "Letters and numbers", met: false },
|
|
99
|
-
]}
|
|
100
|
-
/>,
|
|
101
|
-
);
|
|
102
|
-
expect(bySlot(html, "site-password-rule").map((tag) => tag.attributes["data-met"])).toEqual(["true", "false"]);
|
|
103
|
-
expect(bySlot(html, "site-password-met")).toHaveLength(1);
|
|
104
|
-
expect(bySlot(html, "site-password-rules")[0]?.attributes["aria-live"]).toBe("polite");
|
|
105
|
-
expect(bySlot(html, "glyph")).toHaveLength(1);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("marks every element of the other parts", () => {
|
|
109
|
-
const html = renderToStaticMarkup(
|
|
110
|
-
<>
|
|
111
|
-
<AuthProviders>
|
|
112
|
-
<a data-slot="site-action" href="/google">Google</a>
|
|
113
|
-
</AuthProviders>
|
|
114
|
-
<AuthOr label="or" />
|
|
115
|
-
<AuthFieldHead title="Enter the code" hint="It changes every 30 seconds" />
|
|
116
|
-
<AuthLinks layout="inline">
|
|
117
|
-
<a data-slot="site-text-action" href="/resend">Resend</a>
|
|
118
|
-
</AuthLinks>
|
|
119
|
-
<AuthLink>
|
|
120
|
-
<a data-slot="site-text-action" href="/back">Back</a>
|
|
121
|
-
</AuthLink>
|
|
122
|
-
<AuthDoneMark>
|
|
123
|
-
<svg data-slot="glyph" />
|
|
124
|
-
</AuthDoneMark>
|
|
125
|
-
</>,
|
|
126
|
-
);
|
|
127
|
-
expect(unmarked(html)).toEqual([]);
|
|
128
|
-
expect(bySlot(html, "site-auth-or-line")).toHaveLength(2);
|
|
129
|
-
expect(bySlot(html, "site-auth-done")[0]?.attributes["aria-hidden"]).toBe("true");
|
|
130
|
-
expect(tagsOf(html).filter((tag) => tag.attributes["data-layout"] === "inline")).toHaveLength(1);
|
|
131
|
-
});
|
|
132
|
-
});
|