@rind-ui/testing 1.0.0 → 1.1.0
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/dist/index.d.mts +10 -0
- package/dist/index.mjs +61 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -227,6 +227,16 @@ export declare function installAnnouncementLog(): Announcement[];
|
|
|
227
227
|
/** The expected lines missing from `actual`, in order (empty when it matches). */
|
|
228
228
|
export declare function missingAriaLines(actual: string, expected: string): string[];
|
|
229
229
|
//#endregion
|
|
230
|
+
//#region src/canonical-html.d.ts
|
|
231
|
+
/**
|
|
232
|
+
* A canonical rendering of `html` (or of `node`'s children): comments and whitespace-only text
|
|
233
|
+
* dropped, adjacent texts joined, attributes sorted, styles normalised by the browser's CSS
|
|
234
|
+
* serialiser; every element id becomes `@0`, `@1`… (in document order) wherever an id or an ARIA
|
|
235
|
+
* relation names it, and every instance id (`data-instance`) `#0`, `#1`… inside the others.
|
|
236
|
+
* Needs a DOM (jsdom or a browser).
|
|
237
|
+
*/
|
|
238
|
+
export declare function canonicalHtml(html: string | Node): string;
|
|
239
|
+
//#endregion
|
|
230
240
|
//#region src/checkbox-invariants.d.ts
|
|
231
241
|
interface CheckboxStepInvariants {
|
|
232
242
|
readonly invariants: readonly ConsumerInvariant<typeof checkboxContract>[];
|
package/dist/index.mjs
CHANGED
|
@@ -97,6 +97,66 @@ function missingAriaLines(actual, expected) {
|
|
|
97
97
|
return missing;
|
|
98
98
|
}
|
|
99
99
|
//#endregion
|
|
100
|
+
//#region src/canonical-html.ts
|
|
101
|
+
/** Attributes whose values may contain generated ids (a toolbar control's key is its id, a radio group's default name holds its instance). */
|
|
102
|
+
const ID_REFS = /^(id|for|name|data-key|aria-(labelledby|describedby|controls|owns|activedescendant|details|errormessage|flowto))$/;
|
|
103
|
+
/**
|
|
104
|
+
* A canonical rendering of `html` (or of `node`'s children): comments and whitespace-only text
|
|
105
|
+
* dropped, adjacent texts joined, attributes sorted, styles normalised by the browser's CSS
|
|
106
|
+
* serialiser; every element id becomes `@0`, `@1`… (in document order) wherever an id or an ARIA
|
|
107
|
+
* relation names it, and every instance id (`data-instance`) `#0`, `#1`… inside the others.
|
|
108
|
+
* Needs a DOM (jsdom or a browser).
|
|
109
|
+
*/
|
|
110
|
+
function canonicalHtml(html) {
|
|
111
|
+
const root = typeof html === "string" ? Object.assign(document.createElement("template"), { innerHTML: html }).content : html;
|
|
112
|
+
const instances = [];
|
|
113
|
+
const seen = (el) => {
|
|
114
|
+
const id = el.getAttribute("data-instance");
|
|
115
|
+
if (id && !instances.includes(id)) instances.push(id);
|
|
116
|
+
for (const child of Array.from(el.children)) seen(child);
|
|
117
|
+
};
|
|
118
|
+
for (const child of Array.from(root.childNodes)) if (child instanceof Element) seen(child);
|
|
119
|
+
const elementIds = [];
|
|
120
|
+
const collect = (el) => {
|
|
121
|
+
if (el.id && !elementIds.includes(el.id)) elementIds.push(el.id);
|
|
122
|
+
for (const child of Array.from(el.children)) collect(child);
|
|
123
|
+
};
|
|
124
|
+
for (const child of Array.from(root.childNodes)) if (child instanceof Element) collect(child);
|
|
125
|
+
const order = [...instances].sort((a, b) => b.length - a.length);
|
|
126
|
+
const inInstance = (value) => order.reduce((v, id) => v.split(id).join(`#${instances.indexOf(id)}`), value);
|
|
127
|
+
const ids = (value) => value.split(" ").map((token) => elementIds.includes(token) ? `@${elementIds.indexOf(token)}` : inInstance(token)).join(" ");
|
|
128
|
+
const out = [];
|
|
129
|
+
const walk = (node, depth) => {
|
|
130
|
+
const pad = " ".repeat(depth);
|
|
131
|
+
if (!(node instanceof Element)) return;
|
|
132
|
+
const attrs = Array.from(node.attributes).filter(({ name }) => name !== "data-hover" && name !== "data-hovering").map(({ name, value }) => {
|
|
133
|
+
if (name === "style") {
|
|
134
|
+
const style = node.style;
|
|
135
|
+
return `style="${Array.from({ length: style.length }, (_, i) => style.item(i)).sort().map((p) => `${p}: ${style.getPropertyValue(p)}`).join("; ")}"`;
|
|
136
|
+
}
|
|
137
|
+
return `${name}="${name === "data-instance" ? inInstance(value) : ID_REFS.test(name) ? ids(value) : value}"`;
|
|
138
|
+
}).sort();
|
|
139
|
+
out.push(`${pad}<${node.tagName.toLowerCase()}${attrs.length ? ` ${attrs.join(" ")}` : ""}>`);
|
|
140
|
+
children(node, depth + 1);
|
|
141
|
+
};
|
|
142
|
+
const children = (parent, depth) => {
|
|
143
|
+
let text = "";
|
|
144
|
+
const flush = () => {
|
|
145
|
+
const t = text.replace(/\s+/g, " ").trim();
|
|
146
|
+
if (t) out.push(`${" ".repeat(depth)}"${t}"`);
|
|
147
|
+
text = "";
|
|
148
|
+
};
|
|
149
|
+
for (const child of Array.from(parent.childNodes)) if (child.nodeType === 3) text += child.textContent ?? "";
|
|
150
|
+
else if (child.nodeType === 1) {
|
|
151
|
+
flush();
|
|
152
|
+
walk(child, depth);
|
|
153
|
+
}
|
|
154
|
+
flush();
|
|
155
|
+
};
|
|
156
|
+
children(root, 0);
|
|
157
|
+
return out.join("\n");
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
100
160
|
//#region src/checkbox-invariants.ts
|
|
101
161
|
const isControl = (t) => t instanceof HTMLElement && t.getAttribute("data-scope") === "checkbox" && t.getAttribute("data-part") === "control";
|
|
102
162
|
/** `checkbox-enter-never-changes`: an Enter key on the Control never changes its value. */
|
|
@@ -4981,4 +5041,4 @@ function allowRindWarning(pattern) {
|
|
|
4981
5041
|
state().allowed.push(pattern);
|
|
4982
5042
|
}
|
|
4983
5043
|
//#endregion
|
|
4984
|
-
export { QrDecodeError, accordionStepInvariants, allowRindWarning, checkGeneric, checkboxStepInvariants, correctBlock, createDriver, createDriverWith, currentRun, dateFieldStepInvariants, dateRangeStepInvariants, decodeQr, domEnv, englishLeaks, expectRindWarning, fakeClipboard, fakeDelayGroup, fakeHoverIntent, fakePositioning, fakeRouter, fakeVisibility, fixedDateClock, formStepInvariants, genericInvariants, getAccordion, getAlert, getAvatar, getBadge, getBreadcrumbs, getButton, getCalendar, getCheckbox, getCheckboxGroup, getClipboard, getCodeBlock, getCollapsible, getColorPicker, getCombobox, getContextMenu, getDateField, getDialog, getDrawer, getField, getFieldset, getFileUpload, getForm, getGridList, getHeading, getHoverCard, getImage, getImageCropper, getImageViewer, getKbd, getLabel, getLink, getListbox, getMarquee, getMenu, getMenubar, getMessageThread, getMeter, getNavigationMenu, getNumberInput, getPagination, getPinInput, getPopover, getProgress, getPromptInput, getQrCode, getRadioGroup, getRating, getReasoning, getScrollArea, getSegmentedControl, getSelect, getSeparator, getSkeleton, getSlider, getSortable, getSplitter, getStepper, getStreamingMessage, getSwitch, getTable, getTableOfContents, getTabs, getTagGroup, getTagsInput, getTextField, getTimeline, getToast, getToaster, getToggle, getToggleGroup, getToolbar, getTooltip, getTour, getTreeView, installAnnouncementLog, interceptNativeNavigation, layoutInvariant, liveAnnouncements, machinePaths, missingAriaLines, missingStateStories, navigationLog, numberInputStepInvariants, parseQrPath, paths, platforms, playwrightEnv, pseudo, pseudoMessages, qrCodeDecodingContract, recordingAnnouncer, runAction, sliderStepInvariants, spokenLog, switchStepInvariants, testMachine, textFieldKeyStepInvariants, textFieldStepInvariants, toGraph, traitInvariants, uncovered, virtualClock, withEngine };
|
|
5044
|
+
export { QrDecodeError, accordionStepInvariants, allowRindWarning, canonicalHtml, checkGeneric, checkboxStepInvariants, correctBlock, createDriver, createDriverWith, currentRun, dateFieldStepInvariants, dateRangeStepInvariants, decodeQr, domEnv, englishLeaks, expectRindWarning, fakeClipboard, fakeDelayGroup, fakeHoverIntent, fakePositioning, fakeRouter, fakeVisibility, fixedDateClock, formStepInvariants, genericInvariants, getAccordion, getAlert, getAvatar, getBadge, getBreadcrumbs, getButton, getCalendar, getCheckbox, getCheckboxGroup, getClipboard, getCodeBlock, getCollapsible, getColorPicker, getCombobox, getContextMenu, getDateField, getDialog, getDrawer, getField, getFieldset, getFileUpload, getForm, getGridList, getHeading, getHoverCard, getImage, getImageCropper, getImageViewer, getKbd, getLabel, getLink, getListbox, getMarquee, getMenu, getMenubar, getMessageThread, getMeter, getNavigationMenu, getNumberInput, getPagination, getPinInput, getPopover, getProgress, getPromptInput, getQrCode, getRadioGroup, getRating, getReasoning, getScrollArea, getSegmentedControl, getSelect, getSeparator, getSkeleton, getSlider, getSortable, getSplitter, getStepper, getStreamingMessage, getSwitch, getTable, getTableOfContents, getTabs, getTagGroup, getTagsInput, getTextField, getTimeline, getToast, getToaster, getToggle, getToggleGroup, getToolbar, getTooltip, getTour, getTreeView, installAnnouncementLog, interceptNativeNavigation, layoutInvariant, liveAnnouncements, machinePaths, missingAriaLines, missingStateStories, navigationLog, numberInputStepInvariants, parseQrPath, paths, platforms, playwrightEnv, pseudo, pseudoMessages, qrCodeDecodingContract, recordingAnnouncer, runAction, sliderStepInvariants, spokenLog, switchStepInvariants, testMachine, textFieldKeyStepInvariants, textFieldStepInvariants, toGraph, traitInvariants, uncovered, virtualClock, withEngine };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rind-ui/testing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Test drivers and environment setup for rind-ui components (Testing Library and Playwright).",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Watermelon Bros",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"dom-accessibility-api": "^0.7.1",
|
|
59
|
-
"@rind-ui/core": "1.
|
|
59
|
+
"@rind-ui/core": "1.1.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@internationalized/date": "^3.12.4",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"react": "^19.3.0",
|
|
67
67
|
"react-dom": "^19.3.0",
|
|
68
68
|
"rolldown": "1.2.13",
|
|
69
|
-
"@rind-ui/react": "1.
|
|
69
|
+
"@rind-ui/react": "1.1.0"
|
|
70
70
|
},
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"@testing-library/dom": ">=10",
|