@rind-ui/testing 0.5.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 +230 -220
- package/dist/index.mjs +61 -1
- package/package.json +10 -6
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": "
|
|
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",
|
|
@@ -9,16 +9,20 @@
|
|
|
9
9
|
"url": "git+https://github.com/WatermelonBros/rind-ui.git",
|
|
10
10
|
"directory": "packages/testing"
|
|
11
11
|
},
|
|
12
|
-
"homepage": "https://
|
|
12
|
+
"homepage": "https://rind.watermelon-studio.it",
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/WatermelonBros/rind-ui/issues"
|
|
15
15
|
},
|
|
16
16
|
"keywords": [
|
|
17
17
|
"testing",
|
|
18
|
+
"test-driver",
|
|
18
19
|
"testing-library",
|
|
19
20
|
"playwright",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
21
|
+
"accessibility",
|
|
22
|
+
"a11y",
|
|
23
|
+
"model-based-testing",
|
|
24
|
+
"headless",
|
|
25
|
+
"react"
|
|
22
26
|
],
|
|
23
27
|
"type": "module",
|
|
24
28
|
"sideEffects": [
|
|
@@ -52,7 +56,7 @@
|
|
|
52
56
|
},
|
|
53
57
|
"dependencies": {
|
|
54
58
|
"dom-accessibility-api": "^0.7.1",
|
|
55
|
-
"@rind-ui/core": "
|
|
59
|
+
"@rind-ui/core": "1.1.0"
|
|
56
60
|
},
|
|
57
61
|
"devDependencies": {
|
|
58
62
|
"@internationalized/date": "^3.12.4",
|
|
@@ -62,7 +66,7 @@
|
|
|
62
66
|
"react": "^19.3.0",
|
|
63
67
|
"react-dom": "^19.3.0",
|
|
64
68
|
"rolldown": "1.2.13",
|
|
65
|
-
"@rind-ui/react": "
|
|
69
|
+
"@rind-ui/react": "1.1.0"
|
|
66
70
|
},
|
|
67
71
|
"peerDependencies": {
|
|
68
72
|
"@testing-library/dom": ">=10",
|