@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,109 +0,0 @@
|
|
|
1
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { bySlot, silentRefusals, tabStops, unmarked } from "../testing/markup";
|
|
5
|
-
import { SiteTextAction } from "./site-bits";
|
|
6
|
-
import { SiteBreadcrumb, SitePage, SitePageHead, SiteSection } from "./site-page";
|
|
7
|
-
import { sitePageStyle } from "./site-page.style";
|
|
8
|
-
|
|
9
|
-
describe("SitePage", () => {
|
|
10
|
-
it("holds the page's regions in one column no wider than the wide tier, with less side room below the narrow tier", () => {
|
|
11
|
-
const html = renderToStaticMarkup(
|
|
12
|
-
<SitePage>
|
|
13
|
-
<SitePageHead title="Pick a plan" lede="Free voices have no limit." />
|
|
14
|
-
</SitePage>,
|
|
15
|
-
);
|
|
16
|
-
expect(html.startsWith('<div data-slot="site-page"')).toBe(true);
|
|
17
|
-
expect(sitePageStyle.base).toContain("max-w-(--site-page-wide)");
|
|
18
|
-
expect(sitePageStyle.base).toContain("@max-page-narrow/page:px-4");
|
|
19
|
-
expect(sitePageStyle.variants.rhythm.page).toContain("@max-page-narrow/page:py-5");
|
|
20
|
-
expect(unmarked(html)).toEqual([]);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
describe("SitePageHead", () => {
|
|
25
|
-
it("draws the eyebrow, the one h1 and the lede in that order", () => {
|
|
26
|
-
const html = renderToStaticMarkup(<SitePageHead eyebrow="Billing" title="Pick a plan" lede="Free voices have no limit." />);
|
|
27
|
-
expect(html.match(/<h1/g)).toHaveLength(1);
|
|
28
|
-
const at = ["site-page-eyebrow", "site-page-title", "site-page-lede"].map((slot) => html.indexOf(slot));
|
|
29
|
-
expect(at[0]).toBeLessThan(at[1] ?? 0);
|
|
30
|
-
expect(at[1]).toBeLessThan(at[2] ?? 0);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("draws no eyebrow and no lede when none is handed", () => {
|
|
34
|
-
const html = renderToStaticMarkup(<SitePageHead title="Pick a plan" />);
|
|
35
|
-
expect(bySlot(html, "site-page-eyebrow")).toEqual([]);
|
|
36
|
-
expect(bySlot(html, "site-page-lede")).toEqual([]);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("SiteSection", () => {
|
|
41
|
-
it("is named by its h2 and draws its heading at the size asked", () => {
|
|
42
|
-
const html = renderToStaticMarkup(
|
|
43
|
-
<SiteSection heading="Questions" size="lg" lede="Asked before paying.">
|
|
44
|
-
<p data-slot="body">body</p>
|
|
45
|
-
</SiteSection>,
|
|
46
|
-
);
|
|
47
|
-
const section = bySlot(html, "site-section")[0];
|
|
48
|
-
const heading = bySlot(html, "site-section-heading")[0];
|
|
49
|
-
expect(section?.attributes["aria-labelledby"]).toBe(heading?.attributes.id);
|
|
50
|
-
expect(heading?.name).toBe("h2");
|
|
51
|
-
expect(heading?.attributes["data-size"]).toBe("lg");
|
|
52
|
-
expect(bySlot(renderToStaticMarkup(<SiteSection heading="Q">x</SiteSection>), "site-section-heading")[0]?.attributes["data-size"]).toBe("md");
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe("SiteBreadcrumb", () => {
|
|
57
|
-
const steps = [
|
|
58
|
-
{ key: "home", label: "Home", href: "/" },
|
|
59
|
-
{ key: "legal", label: "Legal", href: "/legal" },
|
|
60
|
-
{ key: "terms", label: "Terms of use", href: "/terms" },
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
it("links every step but the last, which is the current page", () => {
|
|
64
|
-
const html = renderToStaticMarkup(<SiteBreadcrumb steps={steps} label="You are here" />);
|
|
65
|
-
expect(bySlot(html, "site-breadcrumb-link").map((link) => link.attributes.href)).toEqual(["/", "/legal"]);
|
|
66
|
-
const items = bySlot(html, "site-breadcrumb-item");
|
|
67
|
-
expect(items.map((item) => item.attributes["aria-current"] ?? "")).toEqual(["", "", "page"]);
|
|
68
|
-
expect(items.map((item) => item.attributes["data-current"])).toEqual(["false", "false", "true"]);
|
|
69
|
-
expect(bySlot(html, "site-breadcrumb-separator")).toHaveLength(2);
|
|
70
|
-
expect(bySlot(html, "site-breadcrumb")[0]?.attributes["aria-label"]).toBe("You are here");
|
|
71
|
-
expect(tabStops(html)).toHaveLength(2);
|
|
72
|
-
expect(unmarked(html)).toEqual([]);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("draws one step as the current page with no separator", () => {
|
|
76
|
-
const html = renderToStaticMarkup(<SiteBreadcrumb steps={[{ key: "home", label: "Home", href: "/" }]} label="Trail" />);
|
|
77
|
-
expect(bySlot(html, "site-breadcrumb-link")).toEqual([]);
|
|
78
|
-
expect(bySlot(html, "site-breadcrumb-separator")).toEqual([]);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
describe("SiteTextAction", () => {
|
|
83
|
-
it("draws a link with an address and, disabled, a button described by its reason for a screen reader", () => {
|
|
84
|
-
expect(bySlot(renderToStaticMarkup(<SiteTextAction href="/a">Resend</SiteTextAction>), "site-text-action")[0]?.name).toBe("a");
|
|
85
|
-
const html = renderToStaticMarkup(
|
|
86
|
-
<SiteTextAction href="/a" disabled reason="Wait a minute before sending again">
|
|
87
|
-
Resend
|
|
88
|
-
</SiteTextAction>,
|
|
89
|
-
);
|
|
90
|
-
const action = bySlot(html, "site-text-action")[0];
|
|
91
|
-
expect(action?.name).toBe("button");
|
|
92
|
-
expect(action?.attributes["aria-describedby"]).toBe(bySlot(html, "site-action-reason")[0]?.attributes.id);
|
|
93
|
-
expect(tabStops(html)).toEqual([]);
|
|
94
|
-
expect(unmarked(html)).toEqual([]);
|
|
95
|
-
// @ts-expect-error a disabled text action carries the reason it cannot run
|
|
96
|
-
expect(<SiteTextAction disabled>Resend</SiteTextAction>).toBeDefined();
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it("is described by the line it names instead of its hidden reason", () => {
|
|
100
|
-
const html = renderToStaticMarkup(
|
|
101
|
-
<SiteTextAction disabled reason="Wait a minute" describedBy="why">
|
|
102
|
-
Resend
|
|
103
|
-
</SiteTextAction>,
|
|
104
|
-
);
|
|
105
|
-
expect(bySlot(html, "site-action-reason")).toEqual([]);
|
|
106
|
-
expect(bySlot(html, "site-text-action")[0]?.attributes["aria-describedby"]).toBe("why");
|
|
107
|
-
expect(silentRefusals(html)).toEqual([]);
|
|
108
|
-
});
|
|
109
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { bySlot } from "../testing/markup";
|
|
5
|
-
import { SiteRead, type SiteReadState } from "./site-read";
|
|
6
|
-
|
|
7
|
-
const draw = (read: SiteReadState<readonly string[]>) =>
|
|
8
|
-
renderToStaticMarkup(
|
|
9
|
-
<SiteRead read={read} failed="Could not be read" empty="Nothing yet" isEmpty={(rows) => rows.length === 0}>
|
|
10
|
-
{(rows) => <ul>{rows.map((row) => <li key={row}>{row}</li>)}</ul>}
|
|
11
|
-
</SiteRead>,
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
describe("SiteRead", () => {
|
|
15
|
-
it("draws nothing while the first answer is on its way", () => {
|
|
16
|
-
expect(draw({ data: undefined, isError: false })).toBe("");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("says the read failed in a caption, before anything else", () => {
|
|
20
|
-
const html = draw({ data: ["kept"], isError: true });
|
|
21
|
-
expect(bySlot(html, "site-caption")[0]?.name).toBe("p");
|
|
22
|
-
expect(html).toContain("Could not be read");
|
|
23
|
-
expect(html).not.toContain("<li>");
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("says the answer is empty, and draws the region once it holds something", () => {
|
|
27
|
-
expect(draw({ data: [], isError: false })).toContain("Nothing yet");
|
|
28
|
-
const html = draw({ data: ["one", "two"], isError: false });
|
|
29
|
-
expect(html).toContain("<li>two</li>");
|
|
30
|
-
expect(html).not.toContain("Nothing yet");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("hands an empty answer to the region when it names no empty sentence", () => {
|
|
34
|
-
const html = renderToStaticMarkup(
|
|
35
|
-
<SiteRead read={{ data: [] as string[], isError: false }} failed="x">
|
|
36
|
-
{(rows) => <span>{rows.length === 0 ? "own empty rows" : "rows"}</span>}
|
|
37
|
-
</SiteRead>,
|
|
38
|
-
);
|
|
39
|
-
expect(html).toContain("own empty rows");
|
|
40
|
-
});
|
|
41
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { bySlot, silentRefusals, tagsOf, unmarked } from "../testing/markup";
|
|
5
|
-
import { PackCard, PackSection } from "./pack-card";
|
|
6
|
-
|
|
7
|
-
const meter = { share: 50_000 / 120_000, label: "50,000 characters", amount: "50,000 characters", talk: "about 50 min of English · 2 twenty-minute talks" };
|
|
8
|
-
const pack = (props: Partial<Parameters<typeof PackCard>[0]> = {}) =>
|
|
9
|
-
renderToStaticMarkup(
|
|
10
|
-
<PackCard
|
|
11
|
-
name="Presentation pack"
|
|
12
|
-
price="₩14,900"
|
|
13
|
-
unit=" once"
|
|
14
|
-
about="For getting one presentation ready"
|
|
15
|
-
meter={meter}
|
|
16
|
-
terms="Usable for 12 months · No automatic payment"
|
|
17
|
-
action={{ id: "pack", label: "Buy the pack", href: "/checkout?kind=pack" }}
|
|
18
|
-
{...props}
|
|
19
|
-
/>,
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
describe("PackSection", () => {
|
|
23
|
-
it("draws the heading and lede, the packs, then the closing line, named by its heading", () => {
|
|
24
|
-
const html = renderToStaticMarkup(
|
|
25
|
-
<PackSection heading="Packs and extra credits" lede="Pay once instead of subscribing." note="Presenting every month? Pro is ₩14,900 a month.">
|
|
26
|
-
<i data-slot="probe-pack" />
|
|
27
|
-
</PackSection>,
|
|
28
|
-
);
|
|
29
|
-
const slots = tagsOf(html).map((tag) => tag.attributes["data-slot"]);
|
|
30
|
-
expect(slots).toEqual(["site-pack-section", "site-pack-head", "site-section-heading", "site-section-lede", "site-pack-grid", "probe-pack", "site-pack-note"]);
|
|
31
|
-
const section = bySlot(html, "site-pack-section")[0];
|
|
32
|
-
expect(section?.attributes["aria-labelledby"]).toBe(bySlot(html, "site-section-heading")[0]?.attributes.id);
|
|
33
|
-
expect(bySlot(html, "site-section-heading")[0]?.attributes["data-size"]).toBe("lg");
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("draws the status lines above the card grid, so no line is a cell of the grid that offsets the cards", () => {
|
|
37
|
-
const html = renderToStaticMarkup(
|
|
38
|
-
<PackSection heading="Packs" status={<><p data-slot="probe-line">Plan could not be read</p><p data-slot="probe-line">Reload to try again</p></>}>
|
|
39
|
-
<i data-slot="probe-pack" />
|
|
40
|
-
</PackSection>,
|
|
41
|
-
);
|
|
42
|
-
const slots = tagsOf(html).map((tag) => tag.attributes["data-slot"]);
|
|
43
|
-
expect(slots).toEqual(["site-pack-section", "site-pack-head", "site-section-heading", "site-pack-status", "probe-line", "probe-line", "site-pack-grid", "probe-pack"]);
|
|
44
|
-
// Both lines sit inside the status region and neither inside the grid.
|
|
45
|
-
expect(html).toMatch(/data-slot="site-pack-status"[^>]*>(?:(?!<\/div>)[\s\S])*Plan could not be read(?:(?!<\/div>)[\s\S])*Reload to try again/);
|
|
46
|
-
expect(html.slice(html.indexOf('data-slot="site-pack-grid"'))).not.toContain("Plan could not be read");
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("draws no status region where it is handed nothing, so the heading and the packs keep their gap", () => {
|
|
50
|
-
for (const status of [undefined, null, false]) {
|
|
51
|
-
const html = renderToStaticMarkup(<PackSection heading="Packs" status={status}>{null}</PackSection>);
|
|
52
|
-
expect(bySlot(html, "site-pack-status")).toEqual([]);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("is a section titled by an h2 under a page title, and the page's own h1 where the packs are the page", () => {
|
|
57
|
-
const under = bySlot(renderToStaticMarkup(<PackSection heading="Packs">{null}</PackSection>), "site-section-heading")[0];
|
|
58
|
-
expect(under?.name).toBe("h2");
|
|
59
|
-
const alone = renderToStaticMarkup(<PackSection level={1} heading="Packs">{null}</PackSection>);
|
|
60
|
-
const page = bySlot(alone, "site-section-heading")[0];
|
|
61
|
-
expect(page?.name).toBe("h1");
|
|
62
|
-
expect(bySlot(alone, "site-pack-section")[0]?.attributes["aria-labelledby"]).toBe(page?.attributes.id);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it("leaves out the lede and the closing line it is not handed", () => {
|
|
66
|
-
const html = renderToStaticMarkup(<PackSection heading="Packs">{null}</PackSection>);
|
|
67
|
-
expect(bySlot(html, "site-section-lede")).toEqual([]);
|
|
68
|
-
expect(bySlot(html, "site-pack-note")).toEqual([]);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("PackCard", () => {
|
|
73
|
-
it("draws the name and price on one line, who it is for, the meter, the terms and a primary action", () => {
|
|
74
|
-
const html = pack();
|
|
75
|
-
expect(unmarked(html)).toEqual([]);
|
|
76
|
-
const order = tagsOf(html).map((tag) => tag.attributes["data-slot"]);
|
|
77
|
-
expect(order.slice(0, 6)).toEqual(["site-pack-card", "site-pack-card-head", "site-pack-card-name", "site-pack-card-price", "site-pack-card-unit", "site-pack-card-about"]);
|
|
78
|
-
expect(order.indexOf("site-quota-meter")).toBeLessThan(order.indexOf("site-pack-card-terms"));
|
|
79
|
-
expect(order.indexOf("site-pack-card-terms")).toBeLessThan(order.indexOf("site-action"));
|
|
80
|
-
const action = bySlot(html, "site-action")[0];
|
|
81
|
-
expect(action?.name).toBe("a");
|
|
82
|
-
expect(action?.attributes["data-tone"]).toBe("primary");
|
|
83
|
-
expect(bySlot(html, "site-pack-card")[0]?.attributes["aria-labelledby"]).toBe(bySlot(html, "site-pack-card-name")[0]?.attributes.id);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("draws the characters bold at the meter's start and the share as the fill's width", () => {
|
|
87
|
-
const html = pack();
|
|
88
|
-
expect(bySlot(html, "site-pack-card-amount")[0]?.name).toBe("b");
|
|
89
|
-
expect(bySlot(html, "site-quota-track")[0]?.attributes["aria-label"]).toBe("50,000 characters");
|
|
90
|
-
expect(bySlot(html, "site-quota-fill")[0]?.attributes.style).toBe(`width:${String((50_000 / 120_000) * 100)}%`);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("describes a disabled action by the reason drawn under it", () => {
|
|
94
|
-
const html = pack({ action: { id: "top-up", label: "Top up credits", disabled: true, reason: "Extra credits need Pro or Pro+." }, reason: "Extra credits need Pro or Pro+. Pick a plan first." });
|
|
95
|
-
const action = bySlot(html, "site-action")[0];
|
|
96
|
-
const reason = bySlot(html, "site-pack-card-reason")[0];
|
|
97
|
-
expect(action?.name).toBe("button");
|
|
98
|
-
expect(action?.attributes["aria-describedby"]).toBe(reason?.attributes.id);
|
|
99
|
-
expect(silentRefusals(html)).toEqual([]);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it("leaves an action that can run undescribed, and draws no reason line it is not handed", () => {
|
|
103
|
-
const html = pack();
|
|
104
|
-
expect(bySlot(html, "site-action")[0]?.attributes["aria-describedby"]).toBeUndefined();
|
|
105
|
-
expect(bySlot(html, "site-pack-card-reason")).toEqual([]);
|
|
106
|
-
});
|
|
107
|
-
});
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { bySlot, silentRefusals, tabStops, unmarked } from "../testing/markup";
|
|
5
|
-
import { OfferRow, PriceTable, QuestionList } from "./offer-parts";
|
|
6
|
-
import { FeatureList, PlanCard, PlanGrid } from "./plan-card";
|
|
7
|
-
import { sitePriceTableStyle, sitePlanGridStyle, siteQuestionListStyle, siteFeatureListStyle, siteSwitchOptionStyle } from "./pricing.style";
|
|
8
|
-
import { SegmentedSwitch, SwitchRow, switchKeyTarget, type SegmentedOption } from "./segmented-switch";
|
|
9
|
-
|
|
10
|
-
type Cycle = "monthly" | "yearly";
|
|
11
|
-
const cycles: readonly SegmentedOption<Cycle>[] = [
|
|
12
|
-
{ value: "monthly", label: "Monthly" },
|
|
13
|
-
{ value: "yearly", label: "Yearly · 2 months free" },
|
|
14
|
-
];
|
|
15
|
-
|
|
16
|
-
describe("SegmentedSwitch", () => {
|
|
17
|
-
it("is a named radio group with the chosen option checked and the only one Tab reaches", () => {
|
|
18
|
-
const html = renderToStaticMarkup(
|
|
19
|
-
<SwitchRow>
|
|
20
|
-
<SegmentedSwitch label="Billing cycle" options={cycles} value="yearly" onValueChange={() => {}} />
|
|
21
|
-
</SwitchRow>,
|
|
22
|
-
);
|
|
23
|
-
const group = bySlot(html, "site-switch")[0];
|
|
24
|
-
expect(group?.attributes.role).toBe("radiogroup");
|
|
25
|
-
expect(group?.attributes["aria-label"]).toBe("Billing cycle");
|
|
26
|
-
const options = bySlot(html, "site-switch-option");
|
|
27
|
-
expect(options.map((option) => option.attributes["aria-checked"])).toEqual(["false", "true"]);
|
|
28
|
-
expect(options.map((option) => option.attributes["data-checked"])).toEqual(["false", "true"]);
|
|
29
|
-
expect(tabStops(html).map((tag) => tag.attributes["data-value"])).toEqual(["yearly"]);
|
|
30
|
-
expect(bySlot(html, "site-switch-row")).toHaveLength(1);
|
|
31
|
-
expect(unmarked(html)).toEqual([]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("moves the choice with the arrows, Home and End, wrapping and skipping disabled options", () => {
|
|
35
|
-
const three: readonly SegmentedOption<"a" | "b" | "c">[] = [
|
|
36
|
-
{ value: "a", label: "A" },
|
|
37
|
-
{ value: "b", label: "B", disabled: true },
|
|
38
|
-
{ value: "c", label: "C" },
|
|
39
|
-
];
|
|
40
|
-
expect(switchKeyTarget(three, "a", "ArrowRight")).toBe("c");
|
|
41
|
-
expect(switchKeyTarget(three, "c", "ArrowRight")).toBe("a");
|
|
42
|
-
expect(switchKeyTarget(three, "a", "ArrowLeft")).toBe("c");
|
|
43
|
-
expect(switchKeyTarget(three, "c", "Home")).toBe("a");
|
|
44
|
-
expect(switchKeyTarget(three, "a", "End")).toBe("c");
|
|
45
|
-
expect(switchKeyTarget(three, "a", "ArrowDown")).toBe("c");
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it("leaves the choice alone for any other key, or when the key lands on the chosen option", () => {
|
|
49
|
-
expect(switchKeyTarget(cycles, "monthly", "Enter")).toBeNull();
|
|
50
|
-
expect(switchKeyTarget(cycles, "monthly", "Home")).toBeNull();
|
|
51
|
-
expect(switchKeyTarget([{ value: "a", label: "A", disabled: true }], "a", "ArrowRight")).toBeNull();
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
describe("SegmentedSwitch sizes", () => {
|
|
56
|
-
const options = [
|
|
57
|
-
{ value: "en", label: "English" },
|
|
58
|
-
{ value: "ko", label: "Korean" },
|
|
59
|
-
] as const;
|
|
60
|
-
|
|
61
|
-
it("draws its options at the small size in a line of small text and at the default size otherwise", () => {
|
|
62
|
-
const small = renderToStaticMarkup(<SegmentedSwitch label="Language" value="en" onValueChange={() => {}} options={options} size="sm" />);
|
|
63
|
-
expect(bySlot(small, "site-switch-option").map((option) => option.attributes["data-size"])).toEqual(["sm", "sm"]);
|
|
64
|
-
const plain = renderToStaticMarkup(<SegmentedSwitch label="Language" value="en" onValueChange={() => {}} options={options} />);
|
|
65
|
-
expect(bySlot(plain, "site-switch-option").map((option) => option.attributes["data-size"])).toEqual(["md", "md"]);
|
|
66
|
-
expect(siteSwitchOptionStyle.variants.size.sm).toBe("h-6");
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
describe("PlanCard", () => {
|
|
71
|
-
const actions = [
|
|
72
|
-
{ id: "start", label: "Start Pro", href: "/checkout?plan=pro", tone: "primary" as const },
|
|
73
|
-
{ id: "trial", label: "Try 7 days", href: "/signup", tone: "quiet" as const },
|
|
74
|
-
];
|
|
75
|
-
|
|
76
|
-
it("draws its name, price with its unit, terms, pitch, what it includes and its actions in reading order", () => {
|
|
77
|
-
const html = renderToStaticMarkup(
|
|
78
|
-
<PlanCard
|
|
79
|
-
name="Pro"
|
|
80
|
-
price="$12"
|
|
81
|
-
unit="/mo"
|
|
82
|
-
note="Plus sales tax"
|
|
83
|
-
pitch="For people who present often"
|
|
84
|
-
detail="About ten talks a month"
|
|
85
|
-
features={[{ key: "chars", label: "50,000 characters" }, { key: "4k", label: "4K video", included: false }]}
|
|
86
|
-
highlight="Most chosen"
|
|
87
|
-
actions={actions}
|
|
88
|
-
/>,
|
|
89
|
-
);
|
|
90
|
-
const order = ["site-plan-card-badge", "site-plan-card-name", "site-plan-card-price", "site-plan-card-unit", "site-plan-card-pitch", "site-feature-list", "site-spacer", "site-plan-card-actions"];
|
|
91
|
-
const at = order.map((slot) => html.indexOf(`data-slot="${slot}"`));
|
|
92
|
-
expect(at.every((value, i) => value > -1 && (i === 0 || value > (at[i - 1] ?? 0)))).toBe(true);
|
|
93
|
-
const card = bySlot(html, "site-plan-card")[0];
|
|
94
|
-
expect(card?.attributes["data-highlight"]).toBe("true");
|
|
95
|
-
expect(card?.attributes["aria-labelledby"]).toBe(bySlot(html, "site-plan-card-name")[0]?.attributes.id);
|
|
96
|
-
expect(bySlot(html, "site-plan-card-note")).toHaveLength(2);
|
|
97
|
-
expect(bySlot(html, "site-feature").map((line) => line.attributes["data-included"])).toEqual(["true", "false"]);
|
|
98
|
-
const drawn = bySlot(html, "site-action");
|
|
99
|
-
expect(drawn.map((action) => [action.attributes["data-tone"], action.attributes["data-block"], action.attributes.href])).toEqual([
|
|
100
|
-
["primary", "true", "/checkout?plan=pro"],
|
|
101
|
-
["quiet", "true", "/signup"],
|
|
102
|
-
]);
|
|
103
|
-
expect(tabStops(html)).toHaveLength(2);
|
|
104
|
-
expect(unmarked(html)).toEqual([]);
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
it("draws the current offer's mark as a disabled action across the card, in place of its actions", () => {
|
|
108
|
-
const html = renderToStaticMarkup(<PlanCard name="Pro" price="$12" current={{ label: "Your plan", reason: "This is the plan you are on" }} actions={actions} />);
|
|
109
|
-
expect(bySlot(html, "site-plan-card")[0]?.attributes["data-current"]).toBe("true");
|
|
110
|
-
const drawn = bySlot(html, "site-action");
|
|
111
|
-
expect(drawn).toHaveLength(1);
|
|
112
|
-
expect(drawn[0]?.name).toBe("button");
|
|
113
|
-
expect(drawn[0]?.attributes.disabled).toBeDefined();
|
|
114
|
-
expect(html).toContain(">Your plan<");
|
|
115
|
-
expect(tabStops(html)).toEqual([]);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("says under its actions why they cannot run now, and draws no reason on the current offer", () => {
|
|
119
|
-
const disabled = actions.map((action) => ({ ...action, disabled: true, reason: "Buying opens with the checkout" }));
|
|
120
|
-
const html = renderToStaticMarkup(<PlanCard name="Pro" price="$12" actions={disabled} reason="Buying opens with the checkout" />);
|
|
121
|
-
expect(html.indexOf('data-slot="site-plan-card-actions"')).toBeLessThan(html.indexOf('data-slot="site-plan-card-reason"'));
|
|
122
|
-
expect(bySlot(html, "site-plan-card-reason")).toHaveLength(1);
|
|
123
|
-
expect(html).toContain(">Buying opens with the checkout</p>");
|
|
124
|
-
expect(tabStops(html)).toEqual([]);
|
|
125
|
-
expect(unmarked(html)).toEqual([]);
|
|
126
|
-
const current = renderToStaticMarkup(<PlanCard name="Pro" price="$12" current={{ label: "Your plan", reason: "This is the plan you are on" }} actions={disabled} reason="Buying opens with the checkout" />);
|
|
127
|
-
expect(bySlot(current, "site-plan-card-reason")).toEqual([]);
|
|
128
|
-
expect(bySlot(renderToStaticMarkup(<PlanCard name="Pro" price="$12" actions={actions} />), "site-plan-card-reason")).toEqual([]);
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it("describes every disabled action by its reason line, and an open action by nothing", () => {
|
|
132
|
-
const disabled = actions.map((action) => ({ ...action, disabled: true, reason: "Buying opens with the checkout" }));
|
|
133
|
-
const html = renderToStaticMarkup(<PlanCard name="Pro" price="$12" actions={disabled} reason="Buying opens with the checkout" />);
|
|
134
|
-
const reasonId = bySlot(html, "site-plan-card-reason")[0]?.attributes.id;
|
|
135
|
-
expect(reasonId).toBeTruthy();
|
|
136
|
-
expect(bySlot(html, "site-action").map((action) => action.attributes["aria-describedby"])).toEqual(disabled.map(() => reasonId));
|
|
137
|
-
expect(silentRefusals(html)).toEqual([]);
|
|
138
|
-
// Without the reason line each disabled action draws its own reason for a screen reader and is described by it.
|
|
139
|
-
const unlined = renderToStaticMarkup(<PlanCard name="Pro" price="$12" actions={disabled} />);
|
|
140
|
-
const hidden = bySlot(unlined, "site-action-reason");
|
|
141
|
-
expect(hidden).toHaveLength(disabled.length);
|
|
142
|
-
expect(bySlot(unlined, "site-action").map((action) => action.attributes["aria-describedby"])).toEqual(hidden.map((reason) => reason.attributes.id));
|
|
143
|
-
expect(silentRefusals(unlined)).toEqual([]);
|
|
144
|
-
const open = renderToStaticMarkup(<PlanCard name="Pro" price="$12" actions={actions} reason="Buying opens with the checkout" />);
|
|
145
|
-
expect(bySlot(open, "site-action").map((action) => action.attributes["aria-describedby"])).toEqual(actions.map(() => undefined));
|
|
146
|
-
// The current offer's disabled action is described by why it cannot be chosen, not by the card's reason.
|
|
147
|
-
const current = renderToStaticMarkup(<PlanCard name="Pro" price="$12" current={{ label: "Your plan", reason: "This is the plan you are on" }} actions={disabled} reason="Buying opens with the checkout" />);
|
|
148
|
-
expect(silentRefusals(current)).toEqual([]);
|
|
149
|
-
expect(bySlot(current, "site-action")[0]?.attributes["aria-describedby"]).toBe(bySlot(current, "site-action-reason")[0]?.attributes.id);
|
|
150
|
-
expect(current).toContain(">This is the plan you are on</span>");
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it("draws no badge, unit, note or features it was not handed, and is not marked current", () => {
|
|
154
|
-
const html = renderToStaticMarkup(<PlanCard name="Free" price="$0" actions={[]} />);
|
|
155
|
-
for (const slot of ["site-plan-card-badge", "site-plan-card-unit", "site-plan-card-note", "site-plan-card-pitch", "site-feature-list", "site-action"]) {
|
|
156
|
-
expect(bySlot(html, slot)).toEqual([]);
|
|
157
|
-
}
|
|
158
|
-
const card = bySlot(html, "site-plan-card")[0];
|
|
159
|
-
expect(card?.attributes["data-highlight"]).toBe("false");
|
|
160
|
-
expect(card?.attributes["data-current"]).toBeUndefined();
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
describe("PlanGrid and FeatureList", () => {
|
|
165
|
-
it("lays four offers to a row by default, two below the medium tier and one below the narrow tier", () => {
|
|
166
|
-
expect(bySlot(renderToStaticMarkup(<PlanGrid>x</PlanGrid>), "site-plan-grid")[0]?.attributes["data-columns"]).toBe("4");
|
|
167
|
-
expect(bySlot(renderToStaticMarkup(<PlanGrid columns={3}>x</PlanGrid>), "site-plan-grid")[0]?.attributes["data-columns"]).toBe("3");
|
|
168
|
-
expect(sitePlanGridStyle.variants.columns["4"]).toBe("grid-cols-4");
|
|
169
|
-
expect(sitePlanGridStyle.base).toContain("@max-page-medium/page:grid-cols-2");
|
|
170
|
-
expect(sitePlanGridStyle.base).toContain("@max-page-narrow/page:grid-cols-1");
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
it("draws a feature list in one column, or two on a wide card that fall to one below the narrow tier", () => {
|
|
174
|
-
const two = bySlot(renderToStaticMarkup(<FeatureList columns={2} items={[{ key: "a", label: "A" }]} />), "site-feature-list")[0];
|
|
175
|
-
expect(two?.attributes["data-columns"]).toBe("2");
|
|
176
|
-
expect(siteFeatureListStyle.variants.columns["2"]).toContain("@max-page-narrow/page:grid-cols-1");
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
describe("OfferRow", () => {
|
|
181
|
-
it("draws its title, what it is, its small action and the note across the row", () => {
|
|
182
|
-
const html = renderToStaticMarkup(
|
|
183
|
-
<OfferRow title="Extra credits" about="For Pro and up" action={{ id: "top-up", label: "Top up credits", href: "/checkout", disabled: true, reason: "Extra credits need Pro or Pro+" }} note="Extra credits need Pro or Pro+" />,
|
|
184
|
-
);
|
|
185
|
-
const at = ["site-offer-row-title", "site-offer-row-about", "site-action", "site-offer-row-note"].map((slot) => html.indexOf(`data-slot="${slot}"`));
|
|
186
|
-
expect(at.every((value, i) => value > -1 && (i === 0 || value > (at[i - 1] ?? 0)))).toBe(true);
|
|
187
|
-
const action = bySlot(html, "site-action")[0];
|
|
188
|
-
expect(action?.attributes["data-size"]).toBe("sm");
|
|
189
|
-
expect(action?.name).toBe("button");
|
|
190
|
-
expect(bySlot(html, "site-offer-row")[0]?.attributes["aria-labelledby"]).toBe(bySlot(html, "site-offer-row-title")[0]?.attributes.id);
|
|
191
|
-
expect(unmarked(html)).toEqual([]);
|
|
192
|
-
expect(action?.attributes["aria-describedby"]).toBe(bySlot(html, "site-offer-row-note")[0]?.attributes.id);
|
|
193
|
-
expect(silentRefusals(html)).toEqual([]);
|
|
194
|
-
// Without the note the action is described by its own reason, drawn for a screen reader only.
|
|
195
|
-
const unnoted = renderToStaticMarkup(<OfferRow title="Extra credits" action={{ id: "top-up", label: "Top up credits", disabled: true, reason: "Extra credits need Pro or Pro+" }} />);
|
|
196
|
-
expect(bySlot(unnoted, "site-action")[0]?.attributes["aria-describedby"]).toBe(bySlot(unnoted, "site-action-reason")[0]?.attributes.id);
|
|
197
|
-
expect(silentRefusals(unnoted)).toEqual([]);
|
|
198
|
-
});
|
|
199
|
-
|
|
200
|
-
it("describes an open action by nothing, though a note stands beside it", () => {
|
|
201
|
-
const html = renderToStaticMarkup(<OfferRow title="Team" action={{ id: "notify", label: "Tell me", onSelect: () => {} }} note="Opens later this year" />);
|
|
202
|
-
expect(bySlot(html, "site-action")[0]?.attributes["aria-describedby"]).toBeUndefined();
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it("draws an open action as a link and no note when none is handed", () => {
|
|
206
|
-
const html = renderToStaticMarkup(<OfferRow title="Team" action={{ id: "notify", label: "Tell me", onSelect: () => {} }} />);
|
|
207
|
-
expect(bySlot(html, "site-action")[0]?.name).toBe("button");
|
|
208
|
-
expect(bySlot(html, "site-offer-row-note")).toEqual([]);
|
|
209
|
-
expect(bySlot(html, "site-offer-row-about")).toEqual([]);
|
|
210
|
-
expect(tabStops(html)).toHaveLength(1);
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
describe("PriceTable", () => {
|
|
215
|
-
it("draws the caption, the named columns and one row head and value per column", () => {
|
|
216
|
-
const html = renderToStaticMarkup(
|
|
217
|
-
<PriceTable
|
|
218
|
-
caption="What each voice costs"
|
|
219
|
-
columns={["Where", "Free voices", "Premium voices"]}
|
|
220
|
-
rows={[
|
|
221
|
-
{ key: "app", head: "PC with the app", cells: ["No credits", "Uses credits"] },
|
|
222
|
-
{ key: "tablet", head: "Tablet", cells: ["No credits", "Uses credits"] },
|
|
223
|
-
]}
|
|
224
|
-
/>,
|
|
225
|
-
);
|
|
226
|
-
expect(bySlot(html, "site-price-table-column").map((column) => column.attributes.scope)).toEqual(["col", "col", "col"]);
|
|
227
|
-
expect(bySlot(html, "site-price-table-row")).toHaveLength(2);
|
|
228
|
-
expect(bySlot(html, "site-price-table-row-head").map((head) => head.attributes.scope)).toEqual(["row", "row"]);
|
|
229
|
-
expect(bySlot(html, "site-price-table-cell")).toHaveLength(4);
|
|
230
|
-
expect(html.indexOf("site-price-table-caption")).toBeLessThan(html.indexOf("site-price-table-head"));
|
|
231
|
-
expect(unmarked(html)).toEqual([]);
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it("stands as its own card unless it is set bare inside another part", () => {
|
|
235
|
-
const table = (framed?: boolean) =>
|
|
236
|
-
bySlot(renderToStaticMarkup(<PriceTable caption="What each voice costs" columns={["Where"]} rows={[]} {...(framed === undefined ? {} : { framed })} />), "site-price-table")[0]?.attributes["data-framed"];
|
|
237
|
-
expect(table()).toBe("true");
|
|
238
|
-
expect(table(false)).toBe("false");
|
|
239
|
-
expect(sitePriceTableStyle.variants.framed.true).toContain("border");
|
|
240
|
-
expect(sitePriceTableStyle.base).not.toContain("border");
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
describe("QuestionList", () => {
|
|
245
|
-
it("draws each question as a term with its answer, three to a row and one below the medium tier", () => {
|
|
246
|
-
const html = renderToStaticMarkup(
|
|
247
|
-
<QuestionList
|
|
248
|
-
items={[
|
|
249
|
-
{ key: "trial", question: "Am I charged when the trial ends?", answer: "No." },
|
|
250
|
-
{ key: "carry", question: "Do unused credits carry over?", answer: "Until the next refill." },
|
|
251
|
-
]}
|
|
252
|
-
/>,
|
|
253
|
-
);
|
|
254
|
-
expect(bySlot(html, "site-question-list")[0]?.name).toBe("dl");
|
|
255
|
-
expect(bySlot(html, "site-question-ask").map((tag) => tag.name)).toEqual(["dt", "dt"]);
|
|
256
|
-
expect(bySlot(html, "site-question-answer").map((tag) => tag.name)).toEqual(["dd", "dd"]);
|
|
257
|
-
expect(siteQuestionListStyle.base).toContain("grid-cols-3");
|
|
258
|
-
expect(siteQuestionListStyle.base).toContain("@max-page-medium/page:grid-cols-1");
|
|
259
|
-
expect(unmarked(html)).toEqual([]);
|
|
260
|
-
});
|
|
261
|
-
});
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { refusalPageFor } from "./refusal-page";
|
|
4
|
-
|
|
5
|
-
const Conflict = () => null;
|
|
6
|
-
|
|
7
|
-
describe("refusalPageFor", () => {
|
|
8
|
-
it("names the page for a refusal the app lists, and none for any other or for no refusal", () => {
|
|
9
|
-
const pages = { IDENTITY_CONFLICT: Conflict };
|
|
10
|
-
expect(refusalPageFor(pages, { errorCode: "IDENTITY_CONFLICT" })).toBe(Conflict);
|
|
11
|
-
expect(refusalPageFor(pages, { errorCode: "OTHER" })).toBeUndefined();
|
|
12
|
-
expect(refusalPageFor(pages, null)).toBeUndefined();
|
|
13
|
-
expect(refusalPageFor(undefined, { errorCode: "IDENTITY_CONFLICT" })).toBeUndefined();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("never resolves a code through the object's prototype", () => {
|
|
17
|
-
expect(refusalPageFor({}, { errorCode: "constructor" })).toBeUndefined();
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { applySiteScheme, markSiteScheme, parseSchemeParam, pickSiteScheme, SCHEME_PARAM, siteSchemeBootstrap, type SchemeQuery } from "./site-scheme";
|
|
4
|
-
|
|
5
|
-
function target() {
|
|
6
|
-
const classes = new Set<string>();
|
|
7
|
-
return {
|
|
8
|
-
classes,
|
|
9
|
-
target: { classList: { toggle: (token: string, force: boolean) => (force ? classes.add(token) : classes.delete(token), force) }, style: { colorScheme: "" } },
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const quietQuery = (matches: boolean): SchemeQuery => ({ matches, addEventListener: () => {}, removeEventListener: () => {} });
|
|
14
|
-
|
|
15
|
-
describe("the scheme parameter", () => {
|
|
16
|
-
it("is named once, for every side that hands the choice to another origin", () => {
|
|
17
|
-
expect(SCHEME_PARAM).toBe("ui_scheme");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("reads an unknown value as no choice, where a stored value reads as the system's", () => {
|
|
21
|
-
expect(parseSchemeParam("dark")).toBe("dark");
|
|
22
|
-
expect(parseSchemeParam("system")).toBe("system");
|
|
23
|
-
expect(parseSchemeParam("purple")).toBeNull();
|
|
24
|
-
expect(parseSchemeParam(null)).toBeNull();
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("takes the address's choice first, then the kept one, then the system", () => {
|
|
28
|
-
expect(pickSiteScheme("dark", "light")).toBe("dark");
|
|
29
|
-
expect(pickSiteScheme(null, "light")).toBe("light");
|
|
30
|
-
expect(pickSiteScheme("purple", undefined)).toBe("system");
|
|
31
|
-
expect(pickSiteScheme("system", "dark")).toBe("system");
|
|
32
|
-
});
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
describe("marking the document", () => {
|
|
36
|
-
it("sets the dark class and the colour scheme the browser draws its own controls in", () => {
|
|
37
|
-
const dark = target();
|
|
38
|
-
markSiteScheme(dark.target, true);
|
|
39
|
-
expect(dark.classes.has("dark")).toBe(true);
|
|
40
|
-
expect(dark.target.style.colorScheme).toBe("dark");
|
|
41
|
-
const light = target();
|
|
42
|
-
applySiteScheme("light", quietQuery(true), light.target);
|
|
43
|
-
expect(light.classes.has("dark")).toBe(false);
|
|
44
|
-
expect(light.target.style.colorScheme).toBe("light");
|
|
45
|
-
const system = target();
|
|
46
|
-
applySiteScheme("system", quietQuery(true), system.target);
|
|
47
|
-
expect(system.target.style.colorScheme).toBe("dark");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("writes the colour scheme from the head script too, before the first paint", () => {
|
|
51
|
-
expect(siteSchemeBootstrap()).toContain("colorScheme");
|
|
52
|
-
});
|
|
53
|
-
});
|