@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,182 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { holdDroppedFocus, nameByFirstHeading, takeQuestionFocus } from "./question-focus";
|
|
4
|
-
|
|
5
|
-
/** An element of a fake page: it knows what it holds and records the focus it takes. */
|
|
6
|
-
function element(page: { activeElement: unknown }, name: string, children: unknown[] = []) {
|
|
7
|
-
const self = {
|
|
8
|
-
name,
|
|
9
|
-
isConnected: true,
|
|
10
|
-
contains: (other: unknown) => other === self || children.includes(other),
|
|
11
|
-
focus: () => {
|
|
12
|
-
page.activeElement = self;
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
return self;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function page() {
|
|
19
|
-
const doc: { activeElement: unknown; body: unknown } = { activeElement: null, body: { name: "body" } };
|
|
20
|
-
doc.activeElement = doc.body;
|
|
21
|
-
return doc;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
describe("takeQuestionFocus", () => {
|
|
25
|
-
it("moves the focus into the question and back to the opener when the question drops it", () => {
|
|
26
|
-
const doc = page();
|
|
27
|
-
const opener = element(doc, "opener");
|
|
28
|
-
opener.focus();
|
|
29
|
-
const field = element(doc, "field");
|
|
30
|
-
const question = element(doc, "question", [field]);
|
|
31
|
-
const giveBack = takeQuestionFocus(question, doc);
|
|
32
|
-
expect(doc.activeElement).toBe(question);
|
|
33
|
-
field.focus();
|
|
34
|
-
giveBack();
|
|
35
|
-
expect(doc.activeElement).toBe(opener);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("leaves a focus the reader moved out of the question where they put it", () => {
|
|
39
|
-
const doc = page();
|
|
40
|
-
const opener = element(doc, "opener");
|
|
41
|
-
opener.focus();
|
|
42
|
-
const question = element(doc, "question");
|
|
43
|
-
const giveBack = takeQuestionFocus(question, doc);
|
|
44
|
-
const elsewhere = element(doc, "elsewhere");
|
|
45
|
-
elsewhere.focus();
|
|
46
|
-
giveBack();
|
|
47
|
-
expect(doc.activeElement).toBe(elsewhere);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("gives nothing back to an opener the page replaced while asking", () => {
|
|
51
|
-
const doc = page();
|
|
52
|
-
const opener = element(doc, "opener");
|
|
53
|
-
opener.focus();
|
|
54
|
-
const question = element(doc, "question");
|
|
55
|
-
const giveBack = takeQuestionFocus(question, doc);
|
|
56
|
-
opener.isConnected = false;
|
|
57
|
-
doc.activeElement = doc.body;
|
|
58
|
-
giveBack();
|
|
59
|
-
expect(doc.activeElement).toBe(doc.body);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("gives the dropped focus to the control the page drew again in the question's place", () => {
|
|
63
|
-
const doc = page();
|
|
64
|
-
const opener = element(doc, "opener");
|
|
65
|
-
opener.focus();
|
|
66
|
-
// The question replaces its opener as it opens, so the opener is gone before it can be noted.
|
|
67
|
-
opener.isConnected = false;
|
|
68
|
-
doc.activeElement = doc.body;
|
|
69
|
-
const question = element(doc, "question");
|
|
70
|
-
const giveBack = takeQuestionFocus(question, doc, "cancel");
|
|
71
|
-
const redrawn = element(doc, "redrawn");
|
|
72
|
-
const ids: Record<string, typeof redrawn> = { cancel: redrawn };
|
|
73
|
-
const withIds = Object.assign(doc, { getElementById: (id: string) => ids[id] ?? null });
|
|
74
|
-
withIds.activeElement = withIds.body;
|
|
75
|
-
giveBack();
|
|
76
|
-
expect(doc.activeElement).toBe(redrawn);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("leaves a focus the reader moved alone even where the page names a control to return to", () => {
|
|
80
|
-
const doc = Object.assign(page(), { getElementById: () => null as { focus(): void } | null });
|
|
81
|
-
const redrawn = element(doc, "redrawn");
|
|
82
|
-
doc.getElementById = () => redrawn;
|
|
83
|
-
const question = element(doc, "question");
|
|
84
|
-
const giveBack = takeQuestionFocus(question, doc, "cancel");
|
|
85
|
-
const elsewhere = element(doc, "elsewhere");
|
|
86
|
-
elsewhere.focus();
|
|
87
|
-
giveBack();
|
|
88
|
-
expect(doc.activeElement).toBe(elsewhere);
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
it("takes the focus back from the stand-in that caught it before the question closed", () => {
|
|
92
|
-
const doc = page();
|
|
93
|
-
const question = element(doc, "question");
|
|
94
|
-
const redrawn = element(doc, "redrawn");
|
|
95
|
-
const withIds = Object.assign(doc, { getElementById: (id: string) => (id === "cancel" ? redrawn : null) });
|
|
96
|
-
const giveBack = takeQuestionFocus(question, withIds, "cancel");
|
|
97
|
-
// The section's heading caught the focus the closing question dropped, before the question's cleanup ran.
|
|
98
|
-
const heading = Object.assign(element(doc, "heading"), { addEventListener: () => undefined });
|
|
99
|
-
holdDroppedFocus(heading);
|
|
100
|
-
expect(doc.activeElement).toBe(heading);
|
|
101
|
-
giveBack();
|
|
102
|
-
expect(doc.activeElement).toBe(redrawn);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("hands the focus on after a development mount ran the question twice", () => {
|
|
106
|
-
const doc = page();
|
|
107
|
-
const question = element(doc, "question");
|
|
108
|
-
const redrawn = element(doc, "redrawn");
|
|
109
|
-
let drawn = false;
|
|
110
|
-
const withIds = Object.assign(doc, { getElementById: (id: string) => (drawn && id === "cancel" ? redrawn : null) });
|
|
111
|
-
// Mount, the simulated unmount, and the mount again, with the focus inside the question throughout.
|
|
112
|
-
takeQuestionFocus(question, withIds, "cancel")();
|
|
113
|
-
const giveBack = takeQuestionFocus(question, withIds, "cancel");
|
|
114
|
-
expect(doc.activeElement).toBe(question);
|
|
115
|
-
drawn = true;
|
|
116
|
-
doc.activeElement = doc.body;
|
|
117
|
-
giveBack();
|
|
118
|
-
expect(doc.activeElement).toBe(redrawn);
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
it("leaves a heading the reader focused on purpose alone", () => {
|
|
122
|
-
const doc = page();
|
|
123
|
-
const question = element(doc, "question");
|
|
124
|
-
const redrawn = element(doc, "redrawn");
|
|
125
|
-
const giveBack = takeQuestionFocus(question, Object.assign(doc, { getElementById: () => redrawn }), "cancel");
|
|
126
|
-
const heading = element(doc, "heading");
|
|
127
|
-
heading.focus();
|
|
128
|
-
giveBack();
|
|
129
|
-
expect(doc.activeElement).toBe(heading);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("keeps the focus a question inside it took first", () => {
|
|
133
|
-
const doc = page();
|
|
134
|
-
const opener = element(doc, "opener");
|
|
135
|
-
opener.focus();
|
|
136
|
-
const inner = element(doc, "inner");
|
|
137
|
-
const outer = element(doc, "outer", [inner]);
|
|
138
|
-
// The inner question's effect runs first and takes the focus from the opener.
|
|
139
|
-
const innerBack = takeQuestionFocus(inner, doc);
|
|
140
|
-
const outerBack = takeQuestionFocus(outer, doc);
|
|
141
|
-
expect(doc.activeElement).toBe(inner);
|
|
142
|
-
outerBack();
|
|
143
|
-
expect(doc.activeElement).toBe(inner);
|
|
144
|
-
innerBack();
|
|
145
|
-
expect(doc.activeElement).toBe(opener);
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe("nameByFirstHeading", () => {
|
|
150
|
-
function root(heading: { id: string } | null, own: Record<string, string> = {}) {
|
|
151
|
-
const attributes = { ...own };
|
|
152
|
-
return {
|
|
153
|
-
attributes,
|
|
154
|
-
getAttribute: (name: string) => attributes[name] ?? null,
|
|
155
|
-
setAttribute: (name: string, value: string) => {
|
|
156
|
-
attributes[name] = value;
|
|
157
|
-
},
|
|
158
|
-
querySelector: () => heading,
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
it("names the question by its first heading, giving the heading an id where it has none", () => {
|
|
163
|
-
const heading = { id: "" };
|
|
164
|
-
const node = root(heading);
|
|
165
|
-
nameByFirstHeading(node, "q1");
|
|
166
|
-
expect(heading.id).toBe("q1");
|
|
167
|
-
expect(node.attributes["aria-labelledby"]).toBe("q1");
|
|
168
|
-
const titled = { id: "title" };
|
|
169
|
-
const other = root(titled);
|
|
170
|
-
nameByFirstHeading(other, "q2");
|
|
171
|
-
expect(other.attributes["aria-labelledby"]).toBe("title");
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
it("leaves a named root and a root without a heading alone", () => {
|
|
175
|
-
const named = root({ id: "" }, { "aria-label": "Cancel" });
|
|
176
|
-
nameByFirstHeading(named, "q3");
|
|
177
|
-
expect(named.attributes["aria-labelledby"]).toBeUndefined();
|
|
178
|
-
const bare = root(null);
|
|
179
|
-
nameByFirstHeading(bare, "q4");
|
|
180
|
-
expect(bare.attributes["aria-labelledby"]).toBeUndefined();
|
|
181
|
-
});
|
|
182
|
-
});
|
package/src/form/slider.test.tsx
DELETED
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { bySlot, unmarked } from "../testing/markup";
|
|
5
|
-
import { SiteSlider, SLIDER_PAGE_STEPS, sliderKeyTarget, sliderShare, sliderSnap, sliderValueAt, type SiteSliderProps, type SiteSliderRange } from "./slider";
|
|
6
|
-
|
|
7
|
-
/** Checks a props object against the slider's type. */
|
|
8
|
-
const form = (props: SiteSliderProps) => props;
|
|
9
|
-
|
|
10
|
-
const months: SiteSliderRange = { min: 1, max: 12, step: 1, pageStep: SLIDER_PAGE_STEPS };
|
|
11
|
-
const half: SiteSliderRange = { min: 0, max: 1, step: 0.1, pageStep: 0.5 };
|
|
12
|
-
|
|
13
|
-
describe("sliderSnap", () => {
|
|
14
|
-
it("holds a value inside the range", () => {
|
|
15
|
-
expect(sliderSnap(0, months)).toBe(1);
|
|
16
|
-
expect(sliderSnap(40, months)).toBe(12);
|
|
17
|
-
expect(sliderSnap(Number.NaN, months)).toBe(1);
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("moves a value to the nearest whole step from min, without floating point residue", () => {
|
|
21
|
-
expect(sliderSnap(3.4, months)).toBe(3);
|
|
22
|
-
expect(sliderSnap(3.6, months)).toBe(4);
|
|
23
|
-
expect(sliderSnap(0.30000000000000004, half)).toBe(0.3);
|
|
24
|
-
expect(sliderSnap(0.26, half)).toBe(0.3);
|
|
25
|
-
expect(sliderSnap(4, { min: 1, max: 10, step: 2 })).toBe(5);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it("leaves max reachable when the step does not divide the range", () => {
|
|
29
|
-
expect(sliderSnap(10, { min: 1, max: 10, step: 2 })).toBe(10);
|
|
30
|
-
expect(sliderSnap(9.9, { min: 1, max: 10, step: 2 })).toBe(9);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("answers min for an empty range", () => {
|
|
34
|
-
expect(sliderSnap(5, { min: 3, max: 3, step: 1 })).toBe(3);
|
|
35
|
-
expect(sliderShare(5, 3, 3)).toBe(0);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("sliderKeyTarget", () => {
|
|
40
|
-
it("moves by a step on the arrows, right and up raising the value", () => {
|
|
41
|
-
expect(sliderKeyTarget("ArrowRight", 3, months)).toBe(4);
|
|
42
|
-
expect(sliderKeyTarget("ArrowUp", 3, months)).toBe(4);
|
|
43
|
-
expect(sliderKeyTarget("ArrowLeft", 3, months)).toBe(2);
|
|
44
|
-
expect(sliderKeyTarget("ArrowDown", 3, months)).toBe(2);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("moves by a page on Page Up and Page Down, held at the ends", () => {
|
|
48
|
-
expect(sliderKeyTarget("PageUp", 1, months)).toBe(11);
|
|
49
|
-
expect(sliderKeyTarget("PageUp", 3, months)).toBe(12);
|
|
50
|
-
expect(sliderKeyTarget("PageDown", 12, months)).toBe(2);
|
|
51
|
-
expect(sliderKeyTarget("PageDown", 4, months)).toBe(1);
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("jumps to the ends on Home and End", () => {
|
|
55
|
-
expect(sliderKeyTarget("Home", 7, months)).toBe(1);
|
|
56
|
-
expect(sliderKeyTarget("End", 7, months)).toBe(12);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("answers null for a key it does not take and for a move that would not move", () => {
|
|
60
|
-
expect(sliderKeyTarget("Enter", 3, months)).toBeNull();
|
|
61
|
-
expect(sliderKeyTarget("a", 3, months)).toBeNull();
|
|
62
|
-
expect(sliderKeyTarget("ArrowRight", 12, months)).toBeNull();
|
|
63
|
-
expect(sliderKeyTarget("ArrowLeft", 1, months)).toBeNull();
|
|
64
|
-
expect(sliderKeyTarget("Home", 1, months)).toBeNull();
|
|
65
|
-
expect(sliderKeyTarget("End", 12, months)).toBeNull();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("steps a fractional range by its step", () => {
|
|
69
|
-
expect(sliderKeyTarget("ArrowRight", 0.2, half)).toBe(0.3);
|
|
70
|
-
expect(sliderKeyTarget("PageUp", 0.7, half)).toBe(1);
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe("sliderValueAt", () => {
|
|
75
|
-
it("answers the snapped value under the pointer across the track", () => {
|
|
76
|
-
expect(sliderValueAt(100, 100, 220, months)).toBe(1);
|
|
77
|
-
expect(sliderValueAt(320, 100, 220, months)).toBe(12);
|
|
78
|
-
expect(sliderValueAt(100 + 220 * (2 / 11), 100, 220, months)).toBe(3);
|
|
79
|
-
expect(sliderValueAt(100 + 220 * (2.4 / 11), 100, 220, months)).toBe(3);
|
|
80
|
-
expect(sliderValueAt(100 + 220 * (2.6 / 11), 100, 220, months)).toBe(4);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("holds a pointer outside the track at the ends", () => {
|
|
84
|
-
expect(sliderValueAt(20, 100, 220, months)).toBe(1);
|
|
85
|
-
expect(sliderValueAt(900, 100, 220, months)).toBe(12);
|
|
86
|
-
expect(sliderValueAt(150, 100, 0, months)).toBe(1);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
describe("SiteSlider", () => {
|
|
91
|
-
it("is an ARIA slider on the thumb, named, valued and read as words", () => {
|
|
92
|
-
const html = renderToStaticMarkup(<SiteSlider label="Months used" valueText={(n) => `${String(n)} months`} min={1} max={12} value={3} />);
|
|
93
|
-
const thumb = bySlot(html, "site-slider-thumb")[0];
|
|
94
|
-
expect(thumb?.attributes.role).toBe("slider");
|
|
95
|
-
expect(thumb?.attributes.tabindex).toBe("0");
|
|
96
|
-
expect(thumb?.attributes["aria-label"]).toBe("Months used");
|
|
97
|
-
expect(thumb?.attributes["aria-valuemin"]).toBe("1");
|
|
98
|
-
expect(thumb?.attributes["aria-valuemax"]).toBe("12");
|
|
99
|
-
expect(thumb?.attributes["aria-valuenow"]).toBe("3");
|
|
100
|
-
expect(thumb?.attributes["aria-valuetext"]).toBe("3 months");
|
|
101
|
-
expect(thumb?.attributes["aria-orientation"]).toBe("horizontal");
|
|
102
|
-
expect(bySlot(html, "site-slider")[0]?.attributes.role).toBe("group");
|
|
103
|
-
expect(unmarked(html)).toEqual([]);
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("draws the fill up to the value and the thumb on it", () => {
|
|
107
|
-
const html = renderToStaticMarkup(<SiteSlider label="Months used" min={1} max={12} value={3} />);
|
|
108
|
-
const at = `${String((2 / 11) * 100)}%`;
|
|
109
|
-
expect(bySlot(html, "site-slider-fill")[0]?.attributes.style).toBe(`width:${at}`);
|
|
110
|
-
expect(bySlot(html, "site-slider-thumb")[0]?.attributes.style).toBe(`left:${at}`);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("is labelled by a visible label when given its id instead of words", () => {
|
|
114
|
-
const html = renderToStaticMarkup(<SiteSlider labelledBy="used" min={1} max={12} value={3} />);
|
|
115
|
-
const thumb = bySlot(html, "site-slider-thumb")[0];
|
|
116
|
-
expect(thumb?.attributes["aria-labelledby"]).toBe("used");
|
|
117
|
-
expect(thumb?.attributes["aria-label"]).toBeUndefined();
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("holds its own value from defaultValue, snapped, when no value is given", () => {
|
|
121
|
-
const own = bySlot(renderToStaticMarkup(<SiteSlider label="Speed" min={0} max={1} step={0.1} defaultValue={0.26} />), "site-slider-thumb")[0];
|
|
122
|
-
expect(own?.attributes["aria-valuenow"]).toBe("0.3");
|
|
123
|
-
const atMin = bySlot(renderToStaticMarkup(<SiteSlider label="Speed" min={2} max={5} />), "site-slider-thumb")[0];
|
|
124
|
-
expect(atMin?.attributes["aria-valuenow"]).toBe("2");
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("draws a held value outside the range at the end it passed", () => {
|
|
128
|
-
const thumb = bySlot(renderToStaticMarkup(<SiteSlider label="Months used" min={1} max={12} value={30} />), "site-slider-thumb")[0];
|
|
129
|
-
expect(thumb?.attributes["aria-valuenow"]).toBe("12");
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it("leaves the tab order and says so when disabled", () => {
|
|
133
|
-
const html = renderToStaticMarkup(<SiteSlider label="Months used" min={1} max={12} value={3} disabled />);
|
|
134
|
-
const thumb = bySlot(html, "site-slider-thumb")[0];
|
|
135
|
-
expect(thumb?.attributes.tabindex).toBe("-1");
|
|
136
|
-
expect(thumb?.attributes["aria-disabled"]).toBe("true");
|
|
137
|
-
expect(bySlot(html, "site-slider")[0]?.attributes["data-disabled"]).toBe("true");
|
|
138
|
-
const enabled = bySlot(renderToStaticMarkup(<SiteSlider label="Months used" min={1} max={12} value={3} />), "site-slider-thumb")[0];
|
|
139
|
-
expect(enabled?.attributes["aria-disabled"]).toBeUndefined();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("refuses a slider with neither a label nor a labelling id, and one with both", () => {
|
|
143
|
-
// @ts-expect-error a slider needs an accessible name
|
|
144
|
-
expect(form({ min: 1, max: 12 })).toBeDefined();
|
|
145
|
-
// @ts-expect-error a slider is named one way
|
|
146
|
-
expect(form({ label: "A", labelledBy: "b", min: 1, max: 12 })).toBeDefined();
|
|
147
|
-
});
|
|
148
|
-
});
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
|
|
3
|
-
import { SITE_FIELD_NARROW } from "./form.style";
|
|
4
|
-
|
|
5
|
-
// Vite's module glob, which vitest resolves at build time; the package has no Vite client types.
|
|
6
|
-
declare global {
|
|
7
|
-
interface ImportMeta {
|
|
8
|
-
glob<T>(patterns: string | readonly string[], options: { readonly eager: true; readonly import?: string; readonly query?: string }): Record<string, T>;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Every slot style of the kit, by its exported name. */
|
|
13
|
-
const STYLES: Readonly<Record<string, { readonly base?: string }>> = Object.assign(
|
|
14
|
-
{},
|
|
15
|
-
...Object.values(import.meta.glob<Record<string, { readonly base?: string }>>("../**/*.style.ts", { eager: true })),
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
/** The kit's component sources as text, by path, tests left out. */
|
|
19
|
-
const SOURCES: Readonly<Record<string, string>> = import.meta.glob<string>(["../**/*.tsx", "!../**/*.test.tsx"], { eager: true, query: "?raw", import: "default" });
|
|
20
|
-
|
|
21
|
-
/** Types of `<input>` a reader does not type text into. */
|
|
22
|
-
const NOT_TEXT = /type="(checkbox|radio|file|hidden|range|color)"/;
|
|
23
|
-
|
|
24
|
-
/** Each `<input>` or `<textarea>` element the kit draws, with the slot style it spreads. */
|
|
25
|
-
function typedElements(): { readonly where: string; readonly style: string | undefined }[] {
|
|
26
|
-
return Object.entries(SOURCES).flatMap(([file, text]) =>
|
|
27
|
-
[...text.matchAll(/<(input|textarea)\b([\s\S]*?)\/>/g)]
|
|
28
|
-
.filter((match) => !NOT_TEXT.test(match[2] ?? ""))
|
|
29
|
-
.map((match) => ({ where: `${file.replace("../", "")}:${text.slice(0, match.index).split("\n").length}`, style: /slotAttributes\((\w+)/.exec(match[2] ?? "")?.[1] })),
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
describe("text a reader types", () => {
|
|
34
|
-
it("is read at the product's input size at phone width in every element the kit draws for it", () => {
|
|
35
|
-
const elements = typedElements();
|
|
36
|
-
expect(elements.length).toBeGreaterThan(0);
|
|
37
|
-
for (const element of elements) {
|
|
38
|
-
expect(element.style, `${element.where} spreads no slot style`).toBeDefined();
|
|
39
|
-
const base = STYLES[element.style ?? ""]?.base ?? "";
|
|
40
|
-
// A phone browser zooms into a field read below its input size on focus.
|
|
41
|
-
expect(base, `${element.where} (${element.style ?? ""})`).toContain(SITE_FIELD_NARROW);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("finds a typed element that lacks the size, and leaves a checkbox alone", () => {
|
|
46
|
-
const missing = "<input {...slotAttributes(siteSearchInputStyle, {})} />";
|
|
47
|
-
const checkbox = '<input type="checkbox" {...slotAttributes(siteCheckboxStyle, {})} />';
|
|
48
|
-
const read = (text: string) => [...text.matchAll(/<(input|textarea)\b([\s\S]*?)\/>/g)].filter((match) => !NOT_TEXT.test(match[2] ?? "")).map((match) => /slotAttributes\((\w+)/.exec(match[2] ?? "")?.[1]);
|
|
49
|
-
expect(read(missing)).toEqual(["siteSearchInputStyle"]);
|
|
50
|
-
expect(read(checkbox)).toEqual([]);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { renderToStaticMarkup } from "react-dom/server";
|
|
2
|
-
import { describe, expect, it } from "vitest";
|
|
3
|
-
|
|
4
|
-
import { DocLayout } from "../legal/doc-layout";
|
|
5
|
-
import { LegalTable } from "../legal/legal-table";
|
|
6
|
-
|
|
7
|
-
import { bySlot, silentRefusals, tabStops, unmarked } from "../testing/markup";
|
|
8
|
-
import { ArticleFigure, ArticleIntro, ArticleStep, DocProgress, DocSection, FeedbackPanel, QuickBox, RelatedLinks, TipNote } from "./article";
|
|
9
|
-
import { siteRelatedGridStyle } from "./article.style";
|
|
10
|
-
import { siteDocRailStyle, siteDocBodyStyle, siteTocJumpStyle } from "../legal/doc-layout.style";
|
|
11
|
-
import { siteLegalTableRowStyle, siteLegalTableHeadStyle } from "../legal/legal-table.style";
|
|
12
|
-
|
|
13
|
-
const layout = (over = {}) =>
|
|
14
|
-
renderToStaticMarkup(
|
|
15
|
-
<DocLayout
|
|
16
|
-
crumbs={[
|
|
17
|
-
{ key: "help", label: "Help", href: "/help" },
|
|
18
|
-
{ key: "doc", label: "When voices are not made" },
|
|
19
|
-
]}
|
|
20
|
-
crumbsLabel="Help"
|
|
21
|
-
title="When voices are not made"
|
|
22
|
-
tocTitle="In this article"
|
|
23
|
-
toc={[
|
|
24
|
-
{ id: "quick", title: "First, just these" },
|
|
25
|
-
{ id: "s1", no: "1", title: "Read the message", done: true },
|
|
26
|
-
{ id: "s2", no: "2", title: "Run the check", changed: true },
|
|
27
|
-
]}
|
|
28
|
-
current="s2"
|
|
29
|
-
onJump={() => {}}
|
|
30
|
-
doneMark={<svg data-slot="product-glyph" />}
|
|
31
|
-
jump={<span data-slot="product-select" />}
|
|
32
|
-
side={<DocProgress text="1 of 2 tried" share={0.5} />}
|
|
33
|
-
{...over}
|
|
34
|
-
>
|
|
35
|
-
<p data-slot="product-section">body</p>
|
|
36
|
-
</DocLayout>,
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
describe("DocLayout", () => {
|
|
40
|
-
it("draws the trail, the one h1 and the rail beside the document, the rail named by its title", () => {
|
|
41
|
-
const html = layout();
|
|
42
|
-
expect(html.match(/<h1/g)).toHaveLength(1);
|
|
43
|
-
expect(bySlot(html, "site-doc-rail")[0]?.attributes["aria-label"]).toBe("In this article");
|
|
44
|
-
const order = ["site-breadcrumb", "site-doc-head", "site-doc-rail", "site-doc"].map((slot) => html.indexOf(`data-slot="${slot}"`));
|
|
45
|
-
expect(order.every((at, i) => at > 0 && (i === 0 || at > (order[i - 1] ?? 0)))).toBe(true);
|
|
46
|
-
expect(unmarked(html.replace('<svg data-slot="product-glyph"></svg>', "").replace('<span data-slot="product-select"></span>', "").replace('<p data-slot="product-section">body</p>', ""))).toEqual([]);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("marks the section in view, ticks a tried one and dots a changed one", () => {
|
|
50
|
-
const html = layout();
|
|
51
|
-
const buttons = bySlot(html, "site-toc-button");
|
|
52
|
-
expect(buttons.map((button) => button.attributes["aria-current"])).toEqual([undefined, undefined, "location"]);
|
|
53
|
-
expect(buttons.map((button) => button.attributes["data-current"])).toEqual(["false", "false", "true"]);
|
|
54
|
-
expect(bySlot(html, "site-toc-done")).toHaveLength(1);
|
|
55
|
-
expect(bySlot(html, "site-toc-changed")).toHaveLength(1);
|
|
56
|
-
expect(bySlot(html, "site-toc-number")).toHaveLength(2);
|
|
57
|
-
expect(tabStops(html).filter((stop) => stop.attributes["data-slot"] === "site-toc-button")).toHaveLength(3);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("stacks the rail over the document below the medium tier, where the product's jump control replaces the list", () => {
|
|
61
|
-
expect(siteDocBodyStyle.base).toContain("@max-page-medium/page:flex-col");
|
|
62
|
-
expect(siteDocRailStyle.base).toContain("@max-page-medium/page:w-full");
|
|
63
|
-
expect(siteTocJumpStyle.base).toBe("hidden @max-page-medium/page:block");
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("draws the badge and controls only when handed", () => {
|
|
67
|
-
expect(bySlot(layout(), "site-doc-controls")).toEqual([]);
|
|
68
|
-
expect(bySlot(layout({ controls: <span data-slot="product-controls" /> }), "site-doc-controls")).toHaveLength(1);
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe("LegalTable", () => {
|
|
73
|
-
it("is a table of rows whose first value names the row, each value carrying its column's name for a narrow page", () => {
|
|
74
|
-
const html = renderToStaticMarkup(<LegalTable label="Messages" head={["Message", "Meaning"]} rows={[["Not enough credits", "Characters ran out"]]} />);
|
|
75
|
-
expect(bySlot(html, "site-legal-table")[0]?.attributes.role).toBe("table");
|
|
76
|
-
expect(bySlot(html, "site-legal-table-column").map((column) => column.attributes.role)).toEqual(["columnheader", "columnheader"]);
|
|
77
|
-
expect(bySlot(html, "site-legal-table-cell").map((cell) => cell.attributes["data-lead"])).toEqual(["true", "false"]);
|
|
78
|
-
expect(bySlot(html, "site-legal-table-label")).toHaveLength(2);
|
|
79
|
-
expect(siteLegalTableHeadStyle.base).toContain("@max-page-narrow/page:hidden");
|
|
80
|
-
expect(siteLegalTableRowStyle.base).toContain("@max-page-narrow/page:flex-col");
|
|
81
|
-
expect(unmarked(html)).toEqual([]);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
describe("the article parts", () => {
|
|
86
|
-
it("draws the facts, where it applies and the lead", () => {
|
|
87
|
-
const html = renderToStaticMarkup(<ArticleIntro facts={[{ key: "a", label: "3 min read" }]} where={<span data-slot="product-chip" />} lead="Go through these in order." />);
|
|
88
|
-
expect(bySlot(html, "site-article-fact")).toHaveLength(1);
|
|
89
|
-
expect(bySlot(html, "site-article-lead")).toHaveLength(1);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("numbers a step until it is tried, then ticks it and presses its toggle, which names the step", () => {
|
|
93
|
-
const step = (done: boolean) =>
|
|
94
|
-
renderToStaticMarkup(<ArticleStep id="s1" index={1} done={done} doneMark={<svg data-slot="product-glyph" />} title="Run the check" body="Press Start." tried={{ label: done ? "Tried" : "Mark as tried", name: "Mark step 2 as tried" }} />);
|
|
95
|
-
const open = step(false);
|
|
96
|
-
expect(bySlot(open, "site-step-disc")[0]?.attributes["data-done"]).toBe("false");
|
|
97
|
-
expect(open).toContain(">2</span>");
|
|
98
|
-
const toggle = bySlot(open, "site-action")[0];
|
|
99
|
-
expect(toggle?.attributes["aria-pressed"]).toBe("false");
|
|
100
|
-
expect(toggle?.attributes["aria-label"]).toBe("Mark step 2 as tried");
|
|
101
|
-
expect(toggle?.attributes["data-tone"]).toBe("quiet");
|
|
102
|
-
expect(toggle?.attributes["data-pad"]).toBe("quietSm");
|
|
103
|
-
const tried = step(true);
|
|
104
|
-
expect(bySlot(tried, "site-step-disc")[0]?.attributes["data-done"]).toBe("true");
|
|
105
|
-
expect(bySlot(tried, "site-action")[0]?.attributes["aria-pressed"]).toBe("true");
|
|
106
|
-
expect(bySlot(tried, "site-action")[0]?.attributes["data-tone"]).toBe("secondary");
|
|
107
|
-
expect(bySlot(step(false), "site-article-step")[0]?.attributes.id).toBe("s1");
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it("draws the quick checks, a figure with its caption, a tip and a closing section with its primary action", () => {
|
|
111
|
-
const html = renderToStaticMarkup(
|
|
112
|
-
<>
|
|
113
|
-
<QuickBox id="quick" title="First, just these" items={[{ key: "a", ask: "Online?", answer: "Premium needs the server." }]} />
|
|
114
|
-
<ArticleFigure caption="Figure 1">
|
|
115
|
-
<span data-slot="product-picture" />
|
|
116
|
-
</ArticleFigure>
|
|
117
|
-
<TipNote mark={<svg data-slot="product-glyph" />}>Skip this on a tablet.</TipNote>
|
|
118
|
-
<DocSection id="still" heading="Still not working" text="Attach the record." action={{ id: "ask", label: "Contact us" }} />
|
|
119
|
-
</>,
|
|
120
|
-
);
|
|
121
|
-
expect(bySlot(html, "site-quick-ask")[0]?.name).toBe("strong");
|
|
122
|
-
expect(bySlot(html, "site-figure")[0]?.name).toBe("figure");
|
|
123
|
-
expect(bySlot(html, "site-figure-caption")[0]?.name).toBe("figcaption");
|
|
124
|
-
expect(bySlot(html, "site-tip-mark")[0]?.attributes["aria-hidden"]).toBe("true");
|
|
125
|
-
expect(bySlot(html, "site-action")[0]?.attributes["data-tone"]).toBe("primary");
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
it("asks whether it helped, opens the reasons after a no, and thanks once sent", () => {
|
|
129
|
-
const asked = renderToStaticMarkup(
|
|
130
|
-
<FeedbackPanel
|
|
131
|
-
label="Was this helpful?"
|
|
132
|
-
ask={{ question: "Was this helpful?", answers: [{ id: "yes", label: "Yes", pressed: false }, { id: "no", label: "No", pressed: true }] }}
|
|
133
|
-
more={{ label: "What was missing?", reasons: [{ id: "r", label: "Hard to follow", pressed: true }], actions: [{ id: "send", label: "Send", tone: "primary" }] }}
|
|
134
|
-
/>,
|
|
135
|
-
);
|
|
136
|
-
expect(bySlot(asked, "site-feedback")[0]?.attributes["aria-label"]).toBe("Was this helpful?");
|
|
137
|
-
const actions = bySlot(asked, "site-action");
|
|
138
|
-
expect(actions.map((action) => action.attributes["aria-pressed"])).toEqual(["false", "true", "true", undefined]);
|
|
139
|
-
expect(actions[2]?.attributes["data-tone"]).toBe("primary");
|
|
140
|
-
const thanked = renderToStaticMarkup(<FeedbackPanel label="Was this helpful?" status="Thanks" thanks={{ title: "Thanks.", text: "We read every answer." }} />);
|
|
141
|
-
expect(bySlot(thanked, "site-feedback-thanks")).toHaveLength(1);
|
|
142
|
-
expect(bySlot(thanked, "site-feedback-row")).toEqual([]);
|
|
143
|
-
// The answers are gone with their row, so the thanks can take the focus in their place.
|
|
144
|
-
expect(bySlot(thanked, "site-feedback-more")[0]?.attributes.tabindex).toBe("-1");
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it("describes a disabled send after a no by the note under the actions", () => {
|
|
148
|
-
const panel = (note?: string) =>
|
|
149
|
-
renderToStaticMarkup(
|
|
150
|
-
<FeedbackPanel
|
|
151
|
-
label="Was this helpful?"
|
|
152
|
-
ask={{ question: "Was this helpful?", answers: [{ id: "no", label: "No", pressed: true }] }}
|
|
153
|
-
more={{ label: "What was missing?", reasons: [{ id: "a", label: "Hard to follow" }], actions: [{ id: "send", label: "Send", tone: "primary", disabled: true, reason: "Pick what was missing first" }], ...(note === undefined ? {} : { note }) }}
|
|
154
|
-
/>,
|
|
155
|
-
);
|
|
156
|
-
const noted = panel("Answers are not recorded yet");
|
|
157
|
-
expect(silentRefusals(noted)).toEqual([]);
|
|
158
|
-
expect(bySlot(noted, "site-action").find((action) => action.attributes["data-action"] === "send")?.attributes["aria-describedby"]).toBeDefined();
|
|
159
|
-
const unnoted = panel();
|
|
160
|
-
// Without the note the send is described by its own reason, drawn for a screen reader only.
|
|
161
|
-
expect(silentRefusals(unnoted)).toEqual([]);
|
|
162
|
-
expect(bySlot(unnoted, "site-action").find((action) => action.attributes["data-action"] === "send")?.attributes["aria-describedby"]).toBe(bySlot(unnoted, "site-action-reason")[0]?.attributes.id);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("links the related articles two to a row, one below the narrow tier", () => {
|
|
166
|
-
const html = renderToStaticMarkup(<RelatedLinks title="See also" items={[{ key: "a", title: "No sound", meta: "Troubleshooting", href: "/help/a" }]} />);
|
|
167
|
-
expect(tabStops(html).map((stop) => stop.attributes.href)).toEqual(["/help/a"]);
|
|
168
|
-
expect(siteRelatedGridStyle.base).toContain("@max-page-narrow/page:grid-cols-1");
|
|
169
|
-
expect(unmarked(html)).toEqual([]);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
it("draws a related article with no address as its card in place, pending and out of the tab order", () => {
|
|
173
|
-
const html = renderToStaticMarkup(<RelatedLinks title="See also" items={[{ key: "a", title: "No sound", href: "/help/a" }, { key: "b", title: "Dictionary" }]} />);
|
|
174
|
-
expect(tabStops(html).map((stop) => stop.attributes.href)).toEqual(["/help/a"]);
|
|
175
|
-
expect(bySlot(html, "site-related-link").map((link) => [link.name, link.attributes["data-pending"]])).toEqual([
|
|
176
|
-
["a", "false"],
|
|
177
|
-
["span", "true"],
|
|
178
|
-
]);
|
|
179
|
-
expect(unmarked(html)).toEqual([]);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("draws progress only with a share, and the way to ask on its own", () => {
|
|
183
|
-
expect(bySlot(renderToStaticMarkup(<DocProgress text="1 of 2" share={0.5} />), "site-progress")).toHaveLength(1);
|
|
184
|
-
const ask = renderToStaticMarkup(<DocProgress action={{ id: "ask", label: "Contact us" }} />);
|
|
185
|
-
expect(bySlot(ask, "site-progress")).toEqual([]);
|
|
186
|
-
expect(bySlot(ask, "site-live")).toEqual([]);
|
|
187
|
-
expect(bySlot(ask, "site-action")).toHaveLength(1);
|
|
188
|
-
});
|
|
189
|
-
});
|