@oslokommune/punkt-testing-utils 12.24.3
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/LICENSE +21 -0
- package/README.md +94 -0
- package/dist/index.d.ts +28 -0
- package/dist/punkt-testing-utils.es.js +205 -0
- package/dist/punkt-testing-utils.es.js.map +1 -0
- package/dist/punkt-testing-utils.umd.js +208 -0
- package/dist/punkt-testing-utils.umd.js.map +1 -0
- package/dist/setupTests.d.ts +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present Oslo kommune, Oslo Origo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# punkt-testing-library
|
|
2
|
+
|
|
3
|
+
Dette biblioteket oppstod for å gjøre det enklere å skrive frontend-tester i applikasjoner som bruker Punkt og testing-library.
|
|
4
|
+
|
|
5
|
+
Siden testing-library ikke har veldig god støtte for custom elements (web components). Når du oppgraderer til ny Punkt-versjon, og Punkt-teamet har migrert komponenter fra React/Vue til Web components, risikerer du at testene dine begynner å feile på ikke-opplagt vis.
|
|
6
|
+
|
|
7
|
+
punkt-testing-library er ment å gjøre oppgradering til nye Punkt-versjoner mindre smertefullt, ved å abstrahere funksjoner fra testing-library og la deg som webapp-utvikler forholde deg til funksjoner som vedlikeholdes av Punkt.
|
|
8
|
+
|
|
9
|
+
## Installasjon og oppsett
|
|
10
|
+
```
|
|
11
|
+
npm install --save-dev @oslokommune/punkt-testing-library
|
|
12
|
+
```
|
|
13
|
+
Du må initialisere punkt-testing-library med din testing-library-implementasjon, for eksempel:
|
|
14
|
+
```
|
|
15
|
+
import * as ReactTestingLibrary from '@testing-library/react';
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
getPktElementByLabelText,
|
|
19
|
+
setPktElementChecked,
|
|
20
|
+
setPktElementValue,
|
|
21
|
+
getAllPktElementsByLabelText,
|
|
22
|
+
getPktElementByPlaceholderText,
|
|
23
|
+
waitForPktElementsToBeDefined,
|
|
24
|
+
getPktSelectOptions,
|
|
25
|
+
checkPktElement,
|
|
26
|
+
} = setupPktTestingLibrary(ReactTestingLibrary)
|
|
27
|
+
```
|
|
28
|
+
Dette kan du gjerne gjøre i en felles-fil som du importerer i testene dine.
|
|
29
|
+
|
|
30
|
+
## Eksempel:
|
|
31
|
+
|
|
32
|
+
### Uten punkt-testing-library
|
|
33
|
+
```
|
|
34
|
+
const input = (await screen.findByLabelText("Mitt input-felt"));
|
|
35
|
+
fireEvent.change(input, "Ny verdi");
|
|
36
|
+
```
|
|
37
|
+
Dette er sårbart fordi `findByLabelText` kan returnere et `PktTextinput` eller det underliggende `HTMLInput`-elementet, avhengig av hvilken versjon av Punkt du bruker.
|
|
38
|
+
|
|
39
|
+
### Med punkt-testing-library
|
|
40
|
+
```
|
|
41
|
+
const input = punktTestingLibrary.getPktElementByLabelText('Mitt input-felt');
|
|
42
|
+
await punktTestingLibrary.changePktElementValue(input, 'Ny verdi');
|
|
43
|
+
```
|
|
44
|
+
Dette er mindre sårbart fordi du ikke trenger å vite om input-feltet er et `PktTextinput` eller et `HTMLInput`-element - så lenge du holder deg til funksjoner fra punkt-testing-library, vil testene dine fungere uavhengig av hvilken versjon av Punkt du bruker.
|
|
45
|
+
|
|
46
|
+
Funksjoner i punkt-testing-library som tar et element som parameter, kan også kalles med label, så eksempelet kan forkortes til
|
|
47
|
+
```
|
|
48
|
+
const element = await punktTestingLibrary.setPktElementValue('Mitt input-felt', 'Ny verdi');
|
|
49
|
+
```
|
|
50
|
+
Merk at funksjoner i punkt-testing-library som endrer verdier er asynkrone (returnerer et promise), så de bør alltid brukes med `await`.
|
|
51
|
+
|
|
52
|
+
## API
|
|
53
|
+
```
|
|
54
|
+
export type LabelOrElement = string | RegExp | Element
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Representerer en option i en PktSelect.
|
|
58
|
+
*
|
|
59
|
+
* @property {string} 0 - verdien (value)
|
|
60
|
+
* @property {string | null} 1 - Tekstinnholdet, <option>tekstinnhold</option>
|
|
61
|
+
* @property {boolean} 2 - Om denne er valgt (selected)
|
|
62
|
+
*/
|
|
63
|
+
type PktOption = [string, string | null, boolean];
|
|
64
|
+
|
|
65
|
+
export type PktTestingLibrary = {
|
|
66
|
+
checkPktElement: (labelOrElement: LabelOrElement) => Promise<boolean>
|
|
67
|
+
getPktElementByLabelText: (label: string, container?: HTMLElement) => Element
|
|
68
|
+
getPktElementByPlaceholderText: (labelOrElement: LabelOrElement) => Element
|
|
69
|
+
getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>) => Array<PktOption>
|
|
70
|
+
getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]
|
|
71
|
+
setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>
|
|
72
|
+
setPktElementValue: (
|
|
73
|
+
labelOrElement: LabelOrElement,
|
|
74
|
+
valueOrValues: string | Array<string>,
|
|
75
|
+
useInputEvent?: boolean,
|
|
76
|
+
) => Promise<boolean>
|
|
77
|
+
pktClickButton: (labelOrElement: LabelOrElement) => Promise<boolean>
|
|
78
|
+
waitForPktElementsToBeDefined: () => Promise<any>
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Er dette bare for React?
|
|
83
|
+
Nja - foreløpig er punkt-testing-library bare testet med react-testing-library. Bruker Punkt med Vue? Det _kan_ det hende at mye vil fungere med vue-testing-library også. Hvis du prøver, så gi oss gjerne tilbakemelding, så er vi interesserte i å få det til å funke!
|
|
84
|
+
|
|
85
|
+
Det kan også være mulig å bruke punkt-testing-library med helt andre testrammeverk. Du må i så fall implementere `PktTestingLibraryOptions`-interfacet selv, og initialisere punkt-testing-library med din implementasjon:
|
|
86
|
+
```
|
|
87
|
+
const MyTestingLibrary = {
|
|
88
|
+
fireEvent: /* implementasjon */ ,
|
|
89
|
+
findAllByLabelText: /* implementasjon */
|
|
90
|
+
// osv
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const { getPktElementByLabelText, setPktElementChecked, ...} = setupPktTestingLibrary(MyTestingLibrary)
|
|
94
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { default as DomTestingLibrary } from '@testing-library/dom';
|
|
2
|
+
import { PktDatepicker, PktInputWrapper, PktProgressbar, PktRadioButton, PktSelect, PktTextarea } from '@oslokommune/punkt-elements';
|
|
3
|
+
|
|
4
|
+
export declare const PKT_CUSTOM_FORMFIELDS: string[];
|
|
5
|
+
type PTLElementType = PktDatepicker | PktProgressbar | PktTextarea | PktInputWrapper | PktSelect | PktRadioButton | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
6
|
+
export type PktTestingLibraryOptions = Pick<typeof DomTestingLibrary, 'fireEvent' | 'findAllByLabelText' | 'findAllByTestId' | 'findAllByDisplayValue' | 'findAllByText' | 'getAllByLabelText' | 'getAllByTestId' | 'getAllByDisplayValue' | 'getAllByText'>;
|
|
7
|
+
export type LabelOrElement<ElementType = PTLElementType> = string | RegExp | ElementType;
|
|
8
|
+
export type PktElementValueType = string | number | Date;
|
|
9
|
+
export type PktTestingLibrary = {
|
|
10
|
+
findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>;
|
|
11
|
+
getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType;
|
|
12
|
+
getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>) => Array<PktOption>;
|
|
13
|
+
getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[];
|
|
14
|
+
setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>;
|
|
15
|
+
setPktElementValue: (labelOrElement: LabelOrElement, valueOrValues: PktElementValueType | Array<PktElementValueType>, useInputEvent?: boolean) => Promise<boolean>;
|
|
16
|
+
pktClickButton: (labelOrElement: LabelOrElement<PktRadioButton>) => Promise<boolean>;
|
|
17
|
+
waitForPktElementsToBeDefined: () => Promise<any>;
|
|
18
|
+
};
|
|
19
|
+
export declare const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary;
|
|
20
|
+
/**
|
|
21
|
+
* Representerer en option i en PktSelect.
|
|
22
|
+
*
|
|
23
|
+
* @property {string} 0 - verdien (value)
|
|
24
|
+
* @property {string | null} 1 - Tekstinnholdet, <option>tekstinnhold</option>
|
|
25
|
+
* @property {boolean} 2 - Om denne er valgt (selected)
|
|
26
|
+
*/
|
|
27
|
+
export type PktOption = [string, string | null, boolean];
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { getElementError } from "@testing-library/dom";
|
|
2
|
+
const PKT_CUSTOM_FORMFIELDS = [
|
|
3
|
+
"pkt-datepicker",
|
|
4
|
+
"pkt-progressbar",
|
|
5
|
+
"pkt-textarea",
|
|
6
|
+
"pkt-textinput",
|
|
7
|
+
"pkt-select"
|
|
8
|
+
];
|
|
9
|
+
const PKT_CUSTOM_ELEMENTS = ["pkt-input-wrapper", ...PKT_CUSTOM_FORMFIELDS];
|
|
10
|
+
const setupPktTestingLibrary = (options) => {
|
|
11
|
+
const tools = {
|
|
12
|
+
fireEvent: options.fireEvent,
|
|
13
|
+
findAllByLabelText: options.findAllByLabelText,
|
|
14
|
+
findAllByDisplayValue: options.findAllByDisplayValue,
|
|
15
|
+
findAllByTestId: options.findAllByTestId,
|
|
16
|
+
findAllByText: options.findAllByText,
|
|
17
|
+
getAllByLabelText: options.getAllByLabelText,
|
|
18
|
+
getAllByDisplayValue: options.getAllByDisplayValue,
|
|
19
|
+
getAllByTestId: options.getAllByTestId,
|
|
20
|
+
getAllByText: options.getAllByText
|
|
21
|
+
};
|
|
22
|
+
return {
|
|
23
|
+
findPktElementByLabelText: withTestingLibrary(tools, findPktElementByLabel),
|
|
24
|
+
waitForPktElementsToBeDefined,
|
|
25
|
+
getPktElementByLabelText: withTestingLibrary(tools, getPktElementByLabel),
|
|
26
|
+
setPktElementChecked: withTestingLibrary(tools, setPktElementChecked),
|
|
27
|
+
getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),
|
|
28
|
+
getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),
|
|
29
|
+
setPktElementValue: withTestingLibrary(tools, setPktElementValue),
|
|
30
|
+
pktClickButton: withTestingLibrary(tools, pktClickButton)
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const syncQueryFunctionResolver = (testingLibrary) => (queryType) => {
|
|
34
|
+
const queries = {
|
|
35
|
+
text: testingLibrary.getAllByText,
|
|
36
|
+
label: testingLibrary.getAllByLabelText,
|
|
37
|
+
testid: testingLibrary.getAllByTestId,
|
|
38
|
+
displayValue: testingLibrary.getAllByDisplayValue
|
|
39
|
+
};
|
|
40
|
+
const query = queries[queryType];
|
|
41
|
+
if (query) {
|
|
42
|
+
return query;
|
|
43
|
+
} else {
|
|
44
|
+
throw new Error("Unsupported query type: " + queryType);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const asyncQueryFunctionResolver = (testingLibrary) => (queryType) => {
|
|
48
|
+
const queries = {
|
|
49
|
+
text: testingLibrary.findAllByText,
|
|
50
|
+
label: testingLibrary.findAllByLabelText,
|
|
51
|
+
testid: testingLibrary.findAllByTestId,
|
|
52
|
+
displayValue: testingLibrary.findAllByDisplayValue
|
|
53
|
+
};
|
|
54
|
+
const query = queries[queryType];
|
|
55
|
+
if (query) {
|
|
56
|
+
return query;
|
|
57
|
+
} else {
|
|
58
|
+
throw new Error("Unsupported query type: " + queryType);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const syncResolveIdentifierOrElement = (testingLibrary) => (elementOrIdentifier, query) => typeof elementOrIdentifier === "string" || elementOrIdentifier instanceof RegExp ? getPktElementBy(testingLibrary)(query, elementOrIdentifier) : elementOrIdentifier;
|
|
62
|
+
const asyncResolveIdentifierOrElement = (testingLibrary) => async (elementOrIdentifier, query) => typeof elementOrIdentifier === "string" || elementOrIdentifier instanceof RegExp ? await findPktElementBy(testingLibrary)(query, elementOrIdentifier) : elementOrIdentifier;
|
|
63
|
+
const asyncFuncWithStringIdentifierOrElement = (testingLibrary) => (func, query = "label") => {
|
|
64
|
+
return async (labelOrPktElement, ...restArgs) => {
|
|
65
|
+
const element = await asyncResolveIdentifierOrElement(testingLibrary)(labelOrPktElement, query);
|
|
66
|
+
return await func(element, ...restArgs);
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const syncFuncWithStringIdentifierOrElement = (testingLibrary) => (func, query = "label") => {
|
|
70
|
+
return (labelOrPktElement, ...restArgs) => {
|
|
71
|
+
const element = syncResolveIdentifierOrElement(testingLibrary)(labelOrPktElement, query);
|
|
72
|
+
return func(element, ...restArgs);
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
const withTestingLibrary = (testingLibrary, fn) => fn(testingLibrary);
|
|
76
|
+
const waitForPktElementsToBeDefined = async () => await Promise.all(
|
|
77
|
+
PKT_CUSTOM_ELEMENTS.map((elementName) => {
|
|
78
|
+
if (document.querySelector(elementName) !== null) {
|
|
79
|
+
return window.customElements.whenDefined(elementName);
|
|
80
|
+
}
|
|
81
|
+
}).filter((promise) => promise)
|
|
82
|
+
);
|
|
83
|
+
const findPossibleWrappingPktCustomElement = (innerElement, isByRole, args) => {
|
|
84
|
+
if (!innerElement === null) {
|
|
85
|
+
throw getElementError(`Finner ikke noe element med ${isByRole ? "role" : "label"} "${args[0]}"`, document.body);
|
|
86
|
+
}
|
|
87
|
+
const pktElement = innerElement == null ? void 0 : innerElement.closest(PKT_CUSTOM_FORMFIELDS.join(", "));
|
|
88
|
+
if (pktElement) {
|
|
89
|
+
return pktElement;
|
|
90
|
+
} else {
|
|
91
|
+
return innerElement;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const getPktElementBy = (testingLibrary) => (query = "label", identifier, container) => {
|
|
95
|
+
const queryFunc = syncQueryFunctionResolver(testingLibrary)(query);
|
|
96
|
+
const innerElement = doElementSearch(identifier, query, queryFunc, container)[0];
|
|
97
|
+
return findPossibleWrappingPktCustomElement(innerElement, false, []);
|
|
98
|
+
};
|
|
99
|
+
const removeElementBySelector = (ancestor, selector) => {
|
|
100
|
+
const elements = Array.from(ancestor.querySelectorAll(selector));
|
|
101
|
+
elements.forEach((element) => {
|
|
102
|
+
var _a;
|
|
103
|
+
(_a = element.parentNode) == null ? void 0 : _a.removeChild(element);
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
function getPureLabelText(label) {
|
|
107
|
+
var _a;
|
|
108
|
+
const clonedLabel = label.cloneNode(true);
|
|
109
|
+
removeElementBySelector(clonedLabel, "pkt-helptext");
|
|
110
|
+
removeElementBySelector(clonedLabel, ".pkt-input-suffix");
|
|
111
|
+
removeElementBySelector(clonedLabel, ".pkt-input-prefix");
|
|
112
|
+
removeElementBySelector(clonedLabel, ".pkt-input-icon");
|
|
113
|
+
removeElementBySelector(clonedLabel, "option");
|
|
114
|
+
return ((_a = clonedLabel.textContent) == null ? void 0 : _a.trim()) || null;
|
|
115
|
+
}
|
|
116
|
+
const getPureLabelTextForLabelOwner = (labelOwner) => {
|
|
117
|
+
const label = "labels" in labelOwner && labelOwner.labels instanceof NodeList && labelOwner.labels.length > 0 && labelOwner.labels[0] || labelOwner.querySelector("label");
|
|
118
|
+
if (label) {
|
|
119
|
+
return getPureLabelText(label);
|
|
120
|
+
} else {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
const labelMatcher = (labelTextToMatch) => (nodeContent, element) => {
|
|
125
|
+
if (element instanceof HTMLElement) {
|
|
126
|
+
const labelWithoutHelptext = getPureLabelTextForLabelOwner(element);
|
|
127
|
+
return labelWithoutHelptext === labelTextToMatch;
|
|
128
|
+
} else {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const doElementSearch = (identifier, query, queryFunc, container = document.body) => {
|
|
133
|
+
try {
|
|
134
|
+
return typeof identifier === "string" && query === "label" ? queryFunc(container, labelMatcher(identifier.trim())) : queryFunc(container, identifier);
|
|
135
|
+
} catch (e) {
|
|
136
|
+
if (typeof identifier === "string" && query === "label") {
|
|
137
|
+
const matchingLabel = Array.from(document.body.querySelectorAll("label")).find(
|
|
138
|
+
(labelElement) => getPureLabelText(labelElement) === identifier
|
|
139
|
+
);
|
|
140
|
+
const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select"));
|
|
141
|
+
if (labelOwner) {
|
|
142
|
+
return [labelOwner];
|
|
143
|
+
} else {
|
|
144
|
+
throw getElementError(`Fant ikke noe element med ${query} "${identifier}"`, document.body);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
throw getElementError(`Fant ikke noe element med ${query} "${identifier}"`, document.body);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const findPktElementBy = (testingLibrary) => async (query = "label", identifier, container) => {
|
|
151
|
+
const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query);
|
|
152
|
+
const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0];
|
|
153
|
+
return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []));
|
|
154
|
+
};
|
|
155
|
+
const getPktElementByLabel = (testingLibrary) => (label, container) => getPktElementBy(testingLibrary)("label", label, container);
|
|
156
|
+
const findPktElementByLabel = (testingLibrary) => async (label, container) => findPktElementBy(testingLibrary)("label", label, container);
|
|
157
|
+
const setPktElementChecked = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)((element, checked) => {
|
|
158
|
+
if (!("checked" in element)) {
|
|
159
|
+
throw new Error("Only elements with a checked attribute can be checked");
|
|
160
|
+
}
|
|
161
|
+
const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } });
|
|
162
|
+
return Promise.resolve(returnValue);
|
|
163
|
+
});
|
|
164
|
+
const getPktSelectOptions = (testingLibrary) => syncFuncWithStringIdentifierOrElement(testingLibrary)(
|
|
165
|
+
(selectElement) => {
|
|
166
|
+
const optionElements = Array.from(
|
|
167
|
+
selectElement.querySelectorAll(
|
|
168
|
+
":scope > option, :scope > optgroup > option, :scope > data, :scope > optgroup > data"
|
|
169
|
+
)
|
|
170
|
+
);
|
|
171
|
+
const currentValue = selectElement.value;
|
|
172
|
+
return optionElements.map((optionElement) => [
|
|
173
|
+
optionElement.value,
|
|
174
|
+
optionElement.textContent,
|
|
175
|
+
optionElement.value === currentValue
|
|
176
|
+
]);
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
const getAllPktElementsByLabelText = (testingLibrary) => (label, container) => {
|
|
180
|
+
const innerElements = testingLibrary.getAllByLabelText(container || document.body, label);
|
|
181
|
+
return innerElements.map((element) => findPossibleWrappingPktCustomElement(element, false, []));
|
|
182
|
+
};
|
|
183
|
+
const setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
|
|
184
|
+
async (element, valueOrValues, useInputEvent = false) => {
|
|
185
|
+
if (Array.isArray(valueOrValues) && !(element.tagName === "PKT-SELECT" && "multiple" in element && element.multiple)) {
|
|
186
|
+
throw new Error("Only a multi-select PktSelect can have multiple values");
|
|
187
|
+
}
|
|
188
|
+
if (element.tagName === "PKT-SELECT") {
|
|
189
|
+
testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
|
|
190
|
+
return Promise.resolve(true);
|
|
191
|
+
} else {
|
|
192
|
+
const returnValue = useInputEvent ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } }) : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
|
|
193
|
+
return Promise.resolve(returnValue);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
const pktClickButton = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element) => {
|
|
198
|
+
const returnValue = testingLibrary.fireEvent.click(element);
|
|
199
|
+
return Promise.resolve(returnValue);
|
|
200
|
+
}, "text");
|
|
201
|
+
export {
|
|
202
|
+
PKT_CUSTOM_FORMFIELDS,
|
|
203
|
+
setupPktTestingLibrary
|
|
204
|
+
};
|
|
205
|
+
//# sourceMappingURL=punkt-testing-utils.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"punkt-testing-utils.es.js","sources":["../src/index.ts"],"sourcesContent":["import DomTestingLibrary, {\n FindAllByBoundAttribute,\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByTestId,\n findAllByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByTestId,\n getAllByText,\n getElementError,\n} from '@testing-library/dom'\nimport {\n PktDatepicker,\n PktInputWrapper,\n PktProgressbar,\n PktRadioButton,\n PktSelect,\n PktTextarea,\n} from '@oslokommune/punkt-elements'\nimport { AllByBoundAttribute } from '@testing-library/dom/types/queries'\n\nexport const PKT_CUSTOM_FORMFIELDS = [\n 'pkt-datepicker',\n 'pkt-progressbar',\n 'pkt-textarea',\n 'pkt-textinput',\n 'pkt-select',\n]\nconst PKT_CUSTOM_ELEMENTS = ['pkt-input-wrapper', ...PKT_CUSTOM_FORMFIELDS]\n\ntype PTLElementType =\n | PktDatepicker\n | PktProgressbar\n | PktTextarea\n | PktInputWrapper\n | PktSelect\n | PktRadioButton\n | HTMLInputElement\n | HTMLSelectElement\n | HTMLTextAreaElement\n\nexport type PktTestingLibraryOptions = Pick<\n typeof DomTestingLibrary,\n | 'fireEvent'\n | 'findAllByLabelText'\n | 'findAllByTestId'\n | 'findAllByDisplayValue'\n | 'findAllByText'\n | 'getAllByLabelText'\n | 'getAllByTestId'\n | 'getAllByDisplayValue'\n | 'getAllByText'\n>\n\ntype TestingLibraryTools = {\n fireEvent: typeof DomTestingLibrary.fireEvent\n findAllByLabelText: typeof DomTestingLibrary.findAllByLabelText\n findAllByTestId: typeof DomTestingLibrary.findAllByTestId\n findAllByDisplayValue: typeof DomTestingLibrary.findAllByDisplayValue\n findAllByText: typeof DomTestingLibrary.findAllByText\n getAllByLabelText: typeof DomTestingLibrary.getAllByLabelText\n getAllByTestId: typeof DomTestingLibrary.getAllByTestId\n getAllByDisplayValue: typeof DomTestingLibrary.getAllByDisplayValue\n getAllByText: typeof DomTestingLibrary.getAllByText\n}\n\nexport type LabelOrElement<ElementType = PTLElementType> = string | RegExp | ElementType\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent?: boolean,\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<PktRadioButton>) => Promise<boolean>\n waitForPktElementsToBeDefined: () => Promise<any>\n}\n\nexport const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary = (\n options: PktTestingLibraryOptions,\n) => {\n const tools: PktTestingLibraryOptions = {\n fireEvent: options.fireEvent,\n findAllByLabelText: options.findAllByLabelText,\n findAllByDisplayValue: options.findAllByDisplayValue,\n findAllByTestId: options.findAllByTestId,\n findAllByText: options.findAllByText,\n getAllByLabelText: options.getAllByLabelText,\n getAllByDisplayValue: options.getAllByDisplayValue,\n getAllByTestId: options.getAllByTestId,\n getAllByText: options.getAllByText,\n }\n return {\n findPktElementByLabelText: withTestingLibrary(tools, findPktElementByLabel),\n waitForPktElementsToBeDefined,\n getPktElementByLabelText: withTestingLibrary(tools, getPktElementByLabel),\n setPktElementChecked: withTestingLibrary(tools, setPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n }\n}\n\ntype SyncQueries = typeof getAllByText | typeof getAllByLabelText | typeof getAllByTestId | typeof getAllByDisplayValue\ntype AsyncQueries =\n | FindAllByBoundAttribute\n | typeof findAllByText\n | typeof findAllByLabelText\n | typeof findAllByTestId\n | typeof findAllByDisplayValue\n\ntype QueryTypes = 'label' | 'text' | 'displayValue' | 'testid'\n\nconst syncQueryFunctionResolver =\n (testingLibrary: TestingLibraryTools) =>\n (queryType: QueryTypes): SyncQueries => {\n const queries: Record<QueryTypes, SyncQueries> = {\n text: testingLibrary.getAllByText,\n label: testingLibrary.getAllByLabelText,\n testid: testingLibrary.getAllByTestId,\n displayValue: testingLibrary.getAllByDisplayValue,\n }\n const query = queries[queryType]\n if (query) {\n return query\n } else {\n throw new Error('Unsupported query type: ' + queryType)\n }\n }\n\nconst asyncQueryFunctionResolver =\n (testingLibrary: TestingLibraryTools) =>\n (queryType: QueryTypes): AsyncQueries => {\n const queries: Record<QueryTypes, AsyncQueries> = {\n text: testingLibrary.findAllByText,\n label: testingLibrary.findAllByLabelText,\n testid: testingLibrary.findAllByTestId,\n displayValue: testingLibrary.findAllByDisplayValue,\n }\n const query = queries[queryType]\n if (query) {\n return query\n } else {\n throw new Error('Unsupported query type: ' + queryType)\n }\n }\n\nconst syncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType>(elementOrIdentifier: string | RegExp | ElementType, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? (getPktElementBy(testingLibrary)(query, elementOrIdentifier) as ElementType)\n : elementOrIdentifier\n\nconst asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | ElementType, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? ((await findPktElementBy(testingLibrary)(query, elementOrIdentifier)) as ElementType)\n : elementOrIdentifier\n\nconst asyncFuncWithStringIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType, ResultType>(\n func: (element: ElementType, ...restArgs: Array<any>) => Promise<ResultType>,\n query: QueryTypes = 'label',\n ) => {\n return async (labelOrPktElement: string | RegExp | ElementType, ...restArgs: Array<any>) => {\n const element = await asyncResolveIdentifierOrElement(testingLibrary)<ElementType>(labelOrPktElement, query)\n return await func(element, ...restArgs)\n }\n }\n\nconst syncFuncWithStringIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType, ResultType>(\n func: (element: ElementType, ...restArgs: Array<any>) => ResultType,\n query: QueryTypes = 'label',\n ) => {\n return (labelOrPktElement: string | RegExp | ElementType, ...restArgs: Array<any>) => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<ElementType>(labelOrPktElement, query)\n return func(element, ...restArgs)\n }\n }\n\nconst withTestingLibrary = <F>(testingLibrary: TestingLibraryTools, fn: (testingLibrary: TestingLibraryTools) => F) =>\n fn(testingLibrary)\n\n/**\n * Sørger for at alle brukte custom elements fra Punkt er definerte og erstattet med implementasjoner.\n * Bør kalles etter `render`, før noen operasjoner og antakelser gjøres.\n *\n * F.eks.:\n * <code>\n * render(<div><PktTextinput id=\"textinput\" name={'textInput'} label=\"My text input\" aria-label=\"My text input\" /></div>);\n * await waitForPktElementsToBeDefined();\n *\n * await setPktElementValue(\"My text input\", \"new value\");\n * </code>\n */\nconst waitForPktElementsToBeDefined = async () =>\n await Promise.all(\n PKT_CUSTOM_ELEMENTS.map((elementName) => {\n if (document.querySelector(elementName) !== null) {\n return window.customElements.whenDefined(elementName)\n }\n }).filter((promise) => promise),\n )\n\nconst findPossibleWrappingPktCustomElement = <R extends PTLElementType>(\n innerElement: HTMLElement | null,\n isByRole: boolean,\n args: Array<any>,\n): PTLElementType => {\n if (!innerElement === null) {\n throw getElementError(`Finner ikke noe element med ${isByRole ? 'role' : 'label'} \"${args[0]}\"`, document.body)\n }\n const pktElement = innerElement?.closest(PKT_CUSTOM_FORMFIELDS.join(', ')) as R | null\n if (pktElement) {\n return pktElement as R\n } else {\n return innerElement as R\n }\n}\n\nconst getPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n (query: QueryTypes = 'label', identifier: string | RegExp, container?: HTMLElement): PTLElementType => {\n const queryFunc = syncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = doElementSearch(identifier, query, queryFunc, container)[0]\n return findPossibleWrappingPktCustomElement(innerElement, false, [])\n }\n\nconst removeElementBySelector = (ancestor: HTMLElement, selector: string) => {\n const elements = Array.from(ancestor.querySelectorAll(selector))\n elements.forEach((element) => {\n element.parentNode?.removeChild(element)\n })\n}\n\nfunction getPureLabelText(label: Node) {\n const clonedLabel = label.cloneNode(true) as HTMLElement\n removeElementBySelector(clonedLabel, 'pkt-helptext')\n removeElementBySelector(clonedLabel, '.pkt-input-suffix')\n removeElementBySelector(clonedLabel, '.pkt-input-prefix')\n removeElementBySelector(clonedLabel, '.pkt-input-icon')\n removeElementBySelector(clonedLabel, 'option')\n return clonedLabel.textContent?.trim() || null\n}\n\nconst getPureLabelTextForLabelOwner = (labelOwner: HTMLElement): string | null => {\n const label =\n ('labels' in labelOwner &&\n labelOwner.labels instanceof NodeList &&\n labelOwner.labels.length > 0 &&\n labelOwner.labels[0]) ||\n (labelOwner.querySelector('label') as HTMLLabelElement | null)\n if (label) {\n return getPureLabelText(label)\n } else {\n return null\n }\n}\n\nconst labelMatcher = (labelTextToMatch: string) => (nodeContent: string, element: Element | null) => {\n if (element instanceof HTMLElement) {\n const labelWithoutHelptext = getPureLabelTextForLabelOwner(element as HTMLElement)\n return labelWithoutHelptext === labelTextToMatch\n } else {\n return false\n }\n}\n\nconst doElementSearch = <T>(\n identifier: string | RegExp,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n) => {\n try {\n return typeof identifier === 'string' && query === 'label'\n ? queryFunc(container, labelMatcher(identifier.trim()))\n : queryFunc(container, identifier)\n } catch (e) {\n if (typeof identifier === 'string' && query === 'label') {\n // Spesial-case for <pkt-select> som ikke har aria-label\n const matchingLabel: HTMLLabelElement | undefined = Array.from(document.body.querySelectorAll('label')).find(\n (labelElement) => getPureLabelText(labelElement) === identifier,\n )\n const labelOwner = matchingLabel?.control || matchingLabel?.closest('pkt-select')\n if (labelOwner) {\n return [labelOwner]\n } else {\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, document.body)\n }\n }\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, document.body)\n }\n}\n\nconst findPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n async (\n query: QueryTypes = 'label',\n identifier: string | RegExp,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0]\n\n return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []))\n }\n\nconst getPktElementByLabel =\n (testingLibrary: TestingLibraryTools) => (label: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp, container?: HTMLElement): Promise<PTLElementType> =>\n findPktElementBy(testingLibrary)('label', label, container)\n\nconst getPktElementByText = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('text', text, container)\n\nconst findPktElementByText =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('text', text, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)((element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Only elements with a checked attribute can be checked')\n }\n const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n return Promise.resolve(returnValue)\n })\n\n/**\n * Representerer en option i en PktSelect.\n *\n * @property {string} 0 - verdien (value)\n * @property {string | null} 1 - Tekstinnholdet, <option>tekstinnhold</option>\n * @property {boolean} 2 - Om denne er valgt (selected)\n */\nexport type PktOption = [string, string | null, boolean]\n\nconst getPktSelectOptions = (testingLibrary: TestingLibraryTools) =>\n syncFuncWithStringIdentifierOrElement(testingLibrary)<PktSelect, Array<PktOption>>(\n (selectElement: PktSelect): Array<PktOption> => {\n const optionElements: Array<HTMLOptionElement> = Array.from(\n selectElement.querySelectorAll(\n ':scope > option, :scope > optgroup > option, :scope > data, :scope > optgroup > data',\n ),\n )\n const currentValue = selectElement.value\n return optionElements.map((optionElement) => [\n optionElement.value,\n optionElement.textContent,\n optionElement.value === currentValue,\n ])\n },\n )\n\nconst getAllPktElementsByLabelText =\n (testingLibrary: TestingLibraryTools) =>\n (label: string, container?: HTMLElement): Element[] => {\n const innerElements = testingLibrary.getAllByLabelText(container || document.body, label)\n return innerElements.map((element) => findPossibleWrappingPktCustomElement(element, false, []))\n }\n\nconst setPktElementValue = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (\n element: PTLElementType,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent = false,\n ): Promise<boolean> => {\n if (\n Array.isArray(valueOrValues) &&\n !(element.tagName === 'PKT-SELECT' && 'multiple' in element && element.multiple)\n ) {\n throw new Error('Only a multi-select PktSelect can have multiple values')\n }\n if (element.tagName === 'PKT-SELECT') {\n testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(true)\n } else {\n const returnValue = useInputEvent\n ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(returnValue)\n }\n },\n )\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PktRadioButton) => {\n const returnValue = testingLibrary.fireEvent.click(element)\n return Promise.resolve(returnValue)\n }, 'text')\n"],"names":[],"mappings":";AAsBO,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,sBAAsB,CAAC,qBAAqB,GAAG,qBAAqB;AAyD7D,MAAA,yBAAmF,CAC9F,YACG;AACH,QAAM,QAAkC;AAAA,IACtC,WAAW,QAAQ;AAAA,IACnB,oBAAoB,QAAQ;AAAA,IAC5B,uBAAuB,QAAQ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+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@testing-library/dom")) : typeof define === "function" && define.amd ? define(["exports", "@testing-library/dom"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.punktTestingUtils = {}, global["dom-testing-library"]));
|
|
3
|
+
})(this, function(exports2, dom) {
|
|
4
|
+
"use strict";
|
|
5
|
+
const PKT_CUSTOM_FORMFIELDS = [
|
|
6
|
+
"pkt-datepicker",
|
|
7
|
+
"pkt-progressbar",
|
|
8
|
+
"pkt-textarea",
|
|
9
|
+
"pkt-textinput",
|
|
10
|
+
"pkt-select"
|
|
11
|
+
];
|
|
12
|
+
const PKT_CUSTOM_ELEMENTS = ["pkt-input-wrapper", ...PKT_CUSTOM_FORMFIELDS];
|
|
13
|
+
const setupPktTestingLibrary = (options) => {
|
|
14
|
+
const tools = {
|
|
15
|
+
fireEvent: options.fireEvent,
|
|
16
|
+
findAllByLabelText: options.findAllByLabelText,
|
|
17
|
+
findAllByDisplayValue: options.findAllByDisplayValue,
|
|
18
|
+
findAllByTestId: options.findAllByTestId,
|
|
19
|
+
findAllByText: options.findAllByText,
|
|
20
|
+
getAllByLabelText: options.getAllByLabelText,
|
|
21
|
+
getAllByDisplayValue: options.getAllByDisplayValue,
|
|
22
|
+
getAllByTestId: options.getAllByTestId,
|
|
23
|
+
getAllByText: options.getAllByText
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
findPktElementByLabelText: withTestingLibrary(tools, findPktElementByLabel),
|
|
27
|
+
waitForPktElementsToBeDefined,
|
|
28
|
+
getPktElementByLabelText: withTestingLibrary(tools, getPktElementByLabel),
|
|
29
|
+
setPktElementChecked: withTestingLibrary(tools, setPktElementChecked),
|
|
30
|
+
getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),
|
|
31
|
+
getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),
|
|
32
|
+
setPktElementValue: withTestingLibrary(tools, setPktElementValue),
|
|
33
|
+
pktClickButton: withTestingLibrary(tools, pktClickButton)
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
const syncQueryFunctionResolver = (testingLibrary) => (queryType) => {
|
|
37
|
+
const queries = {
|
|
38
|
+
text: testingLibrary.getAllByText,
|
|
39
|
+
label: testingLibrary.getAllByLabelText,
|
|
40
|
+
testid: testingLibrary.getAllByTestId,
|
|
41
|
+
displayValue: testingLibrary.getAllByDisplayValue
|
|
42
|
+
};
|
|
43
|
+
const query = queries[queryType];
|
|
44
|
+
if (query) {
|
|
45
|
+
return query;
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error("Unsupported query type: " + queryType);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const asyncQueryFunctionResolver = (testingLibrary) => (queryType) => {
|
|
51
|
+
const queries = {
|
|
52
|
+
text: testingLibrary.findAllByText,
|
|
53
|
+
label: testingLibrary.findAllByLabelText,
|
|
54
|
+
testid: testingLibrary.findAllByTestId,
|
|
55
|
+
displayValue: testingLibrary.findAllByDisplayValue
|
|
56
|
+
};
|
|
57
|
+
const query = queries[queryType];
|
|
58
|
+
if (query) {
|
|
59
|
+
return query;
|
|
60
|
+
} else {
|
|
61
|
+
throw new Error("Unsupported query type: " + queryType);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const syncResolveIdentifierOrElement = (testingLibrary) => (elementOrIdentifier, query) => typeof elementOrIdentifier === "string" || elementOrIdentifier instanceof RegExp ? getPktElementBy(testingLibrary)(query, elementOrIdentifier) : elementOrIdentifier;
|
|
65
|
+
const asyncResolveIdentifierOrElement = (testingLibrary) => async (elementOrIdentifier, query) => typeof elementOrIdentifier === "string" || elementOrIdentifier instanceof RegExp ? await findPktElementBy(testingLibrary)(query, elementOrIdentifier) : elementOrIdentifier;
|
|
66
|
+
const asyncFuncWithStringIdentifierOrElement = (testingLibrary) => (func, query = "label") => {
|
|
67
|
+
return async (labelOrPktElement, ...restArgs) => {
|
|
68
|
+
const element = await asyncResolveIdentifierOrElement(testingLibrary)(labelOrPktElement, query);
|
|
69
|
+
return await func(element, ...restArgs);
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const syncFuncWithStringIdentifierOrElement = (testingLibrary) => (func, query = "label") => {
|
|
73
|
+
return (labelOrPktElement, ...restArgs) => {
|
|
74
|
+
const element = syncResolveIdentifierOrElement(testingLibrary)(labelOrPktElement, query);
|
|
75
|
+
return func(element, ...restArgs);
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const withTestingLibrary = (testingLibrary, fn) => fn(testingLibrary);
|
|
79
|
+
const waitForPktElementsToBeDefined = async () => await Promise.all(
|
|
80
|
+
PKT_CUSTOM_ELEMENTS.map((elementName) => {
|
|
81
|
+
if (document.querySelector(elementName) !== null) {
|
|
82
|
+
return window.customElements.whenDefined(elementName);
|
|
83
|
+
}
|
|
84
|
+
}).filter((promise) => promise)
|
|
85
|
+
);
|
|
86
|
+
const findPossibleWrappingPktCustomElement = (innerElement, isByRole, args) => {
|
|
87
|
+
if (!innerElement === null) {
|
|
88
|
+
throw dom.getElementError(`Finner ikke noe element med ${isByRole ? "role" : "label"} "${args[0]}"`, document.body);
|
|
89
|
+
}
|
|
90
|
+
const pktElement = innerElement == null ? void 0 : innerElement.closest(PKT_CUSTOM_FORMFIELDS.join(", "));
|
|
91
|
+
if (pktElement) {
|
|
92
|
+
return pktElement;
|
|
93
|
+
} else {
|
|
94
|
+
return innerElement;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const getPktElementBy = (testingLibrary) => (query = "label", identifier, container) => {
|
|
98
|
+
const queryFunc = syncQueryFunctionResolver(testingLibrary)(query);
|
|
99
|
+
const innerElement = doElementSearch(identifier, query, queryFunc, container)[0];
|
|
100
|
+
return findPossibleWrappingPktCustomElement(innerElement, false, []);
|
|
101
|
+
};
|
|
102
|
+
const removeElementBySelector = (ancestor, selector) => {
|
|
103
|
+
const elements = Array.from(ancestor.querySelectorAll(selector));
|
|
104
|
+
elements.forEach((element) => {
|
|
105
|
+
var _a;
|
|
106
|
+
(_a = element.parentNode) == null ? void 0 : _a.removeChild(element);
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
function getPureLabelText(label) {
|
|
110
|
+
var _a;
|
|
111
|
+
const clonedLabel = label.cloneNode(true);
|
|
112
|
+
removeElementBySelector(clonedLabel, "pkt-helptext");
|
|
113
|
+
removeElementBySelector(clonedLabel, ".pkt-input-suffix");
|
|
114
|
+
removeElementBySelector(clonedLabel, ".pkt-input-prefix");
|
|
115
|
+
removeElementBySelector(clonedLabel, ".pkt-input-icon");
|
|
116
|
+
removeElementBySelector(clonedLabel, "option");
|
|
117
|
+
return ((_a = clonedLabel.textContent) == null ? void 0 : _a.trim()) || null;
|
|
118
|
+
}
|
|
119
|
+
const getPureLabelTextForLabelOwner = (labelOwner) => {
|
|
120
|
+
const label = "labels" in labelOwner && labelOwner.labels instanceof NodeList && labelOwner.labels.length > 0 && labelOwner.labels[0] || labelOwner.querySelector("label");
|
|
121
|
+
if (label) {
|
|
122
|
+
return getPureLabelText(label);
|
|
123
|
+
} else {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
const labelMatcher = (labelTextToMatch) => (nodeContent, element) => {
|
|
128
|
+
if (element instanceof HTMLElement) {
|
|
129
|
+
const labelWithoutHelptext = getPureLabelTextForLabelOwner(element);
|
|
130
|
+
return labelWithoutHelptext === labelTextToMatch;
|
|
131
|
+
} else {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
const doElementSearch = (identifier, query, queryFunc, container = document.body) => {
|
|
136
|
+
try {
|
|
137
|
+
return typeof identifier === "string" && query === "label" ? queryFunc(container, labelMatcher(identifier.trim())) : queryFunc(container, identifier);
|
|
138
|
+
} catch (e) {
|
|
139
|
+
if (typeof identifier === "string" && query === "label") {
|
|
140
|
+
const matchingLabel = Array.from(document.body.querySelectorAll("label")).find(
|
|
141
|
+
(labelElement) => getPureLabelText(labelElement) === identifier
|
|
142
|
+
);
|
|
143
|
+
const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select"));
|
|
144
|
+
if (labelOwner) {
|
|
145
|
+
return [labelOwner];
|
|
146
|
+
} else {
|
|
147
|
+
throw dom.getElementError(`Fant ikke noe element med ${query} "${identifier}"`, document.body);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
throw dom.getElementError(`Fant ikke noe element med ${query} "${identifier}"`, document.body);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
const findPktElementBy = (testingLibrary) => async (query = "label", identifier, container) => {
|
|
154
|
+
const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query);
|
|
155
|
+
const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0];
|
|
156
|
+
return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []));
|
|
157
|
+
};
|
|
158
|
+
const getPktElementByLabel = (testingLibrary) => (label, container) => getPktElementBy(testingLibrary)("label", label, container);
|
|
159
|
+
const findPktElementByLabel = (testingLibrary) => async (label, container) => findPktElementBy(testingLibrary)("label", label, container);
|
|
160
|
+
const setPktElementChecked = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)((element, checked) => {
|
|
161
|
+
if (!("checked" in element)) {
|
|
162
|
+
throw new Error("Only elements with a checked attribute can be checked");
|
|
163
|
+
}
|
|
164
|
+
const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } });
|
|
165
|
+
return Promise.resolve(returnValue);
|
|
166
|
+
});
|
|
167
|
+
const getPktSelectOptions = (testingLibrary) => syncFuncWithStringIdentifierOrElement(testingLibrary)(
|
|
168
|
+
(selectElement) => {
|
|
169
|
+
const optionElements = Array.from(
|
|
170
|
+
selectElement.querySelectorAll(
|
|
171
|
+
":scope > option, :scope > optgroup > option, :scope > data, :scope > optgroup > data"
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
const currentValue = selectElement.value;
|
|
175
|
+
return optionElements.map((optionElement) => [
|
|
176
|
+
optionElement.value,
|
|
177
|
+
optionElement.textContent,
|
|
178
|
+
optionElement.value === currentValue
|
|
179
|
+
]);
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
const getAllPktElementsByLabelText = (testingLibrary) => (label, container) => {
|
|
183
|
+
const innerElements = testingLibrary.getAllByLabelText(container || document.body, label);
|
|
184
|
+
return innerElements.map((element) => findPossibleWrappingPktCustomElement(element, false, []));
|
|
185
|
+
};
|
|
186
|
+
const setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
|
|
187
|
+
async (element, valueOrValues, useInputEvent = false) => {
|
|
188
|
+
if (Array.isArray(valueOrValues) && !(element.tagName === "PKT-SELECT" && "multiple" in element && element.multiple)) {
|
|
189
|
+
throw new Error("Only a multi-select PktSelect can have multiple values");
|
|
190
|
+
}
|
|
191
|
+
if (element.tagName === "PKT-SELECT") {
|
|
192
|
+
testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
|
|
193
|
+
return Promise.resolve(true);
|
|
194
|
+
} else {
|
|
195
|
+
const returnValue = useInputEvent ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } }) : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
|
|
196
|
+
return Promise.resolve(returnValue);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
);
|
|
200
|
+
const pktClickButton = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element) => {
|
|
201
|
+
const returnValue = testingLibrary.fireEvent.click(element);
|
|
202
|
+
return Promise.resolve(returnValue);
|
|
203
|
+
}, "text");
|
|
204
|
+
exports2.PKT_CUSTOM_FORMFIELDS = PKT_CUSTOM_FORMFIELDS;
|
|
205
|
+
exports2.setupPktTestingLibrary = setupPktTestingLibrary;
|
|
206
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
207
|
+
});
|
|
208
|
+
//# sourceMappingURL=punkt-testing-utils.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"punkt-testing-utils.umd.js","sources":["../src/index.ts"],"sourcesContent":["import DomTestingLibrary, {\n FindAllByBoundAttribute,\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByTestId,\n findAllByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByTestId,\n getAllByText,\n getElementError,\n} from '@testing-library/dom'\nimport {\n PktDatepicker,\n PktInputWrapper,\n PktProgressbar,\n PktRadioButton,\n PktSelect,\n PktTextarea,\n} from '@oslokommune/punkt-elements'\nimport { AllByBoundAttribute } from '@testing-library/dom/types/queries'\n\nexport const PKT_CUSTOM_FORMFIELDS = [\n 'pkt-datepicker',\n 'pkt-progressbar',\n 'pkt-textarea',\n 'pkt-textinput',\n 'pkt-select',\n]\nconst PKT_CUSTOM_ELEMENTS = ['pkt-input-wrapper', ...PKT_CUSTOM_FORMFIELDS]\n\ntype PTLElementType =\n | PktDatepicker\n | PktProgressbar\n | PktTextarea\n | PktInputWrapper\n | PktSelect\n | PktRadioButton\n | HTMLInputElement\n | HTMLSelectElement\n | HTMLTextAreaElement\n\nexport type PktTestingLibraryOptions = Pick<\n typeof DomTestingLibrary,\n | 'fireEvent'\n | 'findAllByLabelText'\n | 'findAllByTestId'\n | 'findAllByDisplayValue'\n | 'findAllByText'\n | 'getAllByLabelText'\n | 'getAllByTestId'\n | 'getAllByDisplayValue'\n | 'getAllByText'\n>\n\ntype TestingLibraryTools = {\n fireEvent: typeof DomTestingLibrary.fireEvent\n findAllByLabelText: typeof DomTestingLibrary.findAllByLabelText\n findAllByTestId: typeof DomTestingLibrary.findAllByTestId\n findAllByDisplayValue: typeof DomTestingLibrary.findAllByDisplayValue\n findAllByText: typeof DomTestingLibrary.findAllByText\n getAllByLabelText: typeof DomTestingLibrary.getAllByLabelText\n getAllByTestId: typeof DomTestingLibrary.getAllByTestId\n getAllByDisplayValue: typeof DomTestingLibrary.getAllByDisplayValue\n getAllByText: typeof DomTestingLibrary.getAllByText\n}\n\nexport type LabelOrElement<ElementType = PTLElementType> = string | RegExp | ElementType\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent?: boolean,\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<PktRadioButton>) => Promise<boolean>\n waitForPktElementsToBeDefined: () => Promise<any>\n}\n\nexport const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary = (\n options: PktTestingLibraryOptions,\n) => {\n const tools: PktTestingLibraryOptions = {\n fireEvent: options.fireEvent,\n findAllByLabelText: options.findAllByLabelText,\n findAllByDisplayValue: options.findAllByDisplayValue,\n findAllByTestId: options.findAllByTestId,\n findAllByText: options.findAllByText,\n getAllByLabelText: options.getAllByLabelText,\n getAllByDisplayValue: options.getAllByDisplayValue,\n getAllByTestId: options.getAllByTestId,\n getAllByText: options.getAllByText,\n }\n return {\n findPktElementByLabelText: withTestingLibrary(tools, findPktElementByLabel),\n waitForPktElementsToBeDefined,\n getPktElementByLabelText: withTestingLibrary(tools, getPktElementByLabel),\n setPktElementChecked: withTestingLibrary(tools, setPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n }\n}\n\ntype SyncQueries = typeof getAllByText | typeof getAllByLabelText | typeof getAllByTestId | typeof getAllByDisplayValue\ntype AsyncQueries =\n | FindAllByBoundAttribute\n | typeof findAllByText\n | typeof findAllByLabelText\n | typeof findAllByTestId\n | typeof findAllByDisplayValue\n\ntype QueryTypes = 'label' | 'text' | 'displayValue' | 'testid'\n\nconst syncQueryFunctionResolver =\n (testingLibrary: TestingLibraryTools) =>\n (queryType: QueryTypes): SyncQueries => {\n const queries: Record<QueryTypes, SyncQueries> = {\n text: testingLibrary.getAllByText,\n label: testingLibrary.getAllByLabelText,\n testid: testingLibrary.getAllByTestId,\n displayValue: testingLibrary.getAllByDisplayValue,\n }\n const query = queries[queryType]\n if (query) {\n return query\n } else {\n throw new Error('Unsupported query type: ' + queryType)\n }\n }\n\nconst asyncQueryFunctionResolver =\n (testingLibrary: TestingLibraryTools) =>\n (queryType: QueryTypes): AsyncQueries => {\n const queries: Record<QueryTypes, AsyncQueries> = {\n text: testingLibrary.findAllByText,\n label: testingLibrary.findAllByLabelText,\n testid: testingLibrary.findAllByTestId,\n displayValue: testingLibrary.findAllByDisplayValue,\n }\n const query = queries[queryType]\n if (query) {\n return query\n } else {\n throw new Error('Unsupported query type: ' + queryType)\n }\n }\n\nconst syncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType>(elementOrIdentifier: string | RegExp | ElementType, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? (getPktElementBy(testingLibrary)(query, elementOrIdentifier) as ElementType)\n : elementOrIdentifier\n\nconst asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | ElementType, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? ((await findPktElementBy(testingLibrary)(query, elementOrIdentifier)) as ElementType)\n : elementOrIdentifier\n\nconst asyncFuncWithStringIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType, ResultType>(\n func: (element: ElementType, ...restArgs: Array<any>) => Promise<ResultType>,\n query: QueryTypes = 'label',\n ) => {\n return async (labelOrPktElement: string | RegExp | ElementType, ...restArgs: Array<any>) => {\n const element = await asyncResolveIdentifierOrElement(testingLibrary)<ElementType>(labelOrPktElement, query)\n return await func(element, ...restArgs)\n }\n }\n\nconst syncFuncWithStringIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType, ResultType>(\n func: (element: ElementType, ...restArgs: Array<any>) => ResultType,\n query: QueryTypes = 'label',\n ) => {\n return (labelOrPktElement: string | RegExp | ElementType, ...restArgs: Array<any>) => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<ElementType>(labelOrPktElement, query)\n return func(element, ...restArgs)\n }\n }\n\nconst withTestingLibrary = <F>(testingLibrary: TestingLibraryTools, fn: (testingLibrary: TestingLibraryTools) => F) =>\n fn(testingLibrary)\n\n/**\n * Sørger for at alle brukte custom elements fra Punkt er definerte og erstattet med implementasjoner.\n * Bør kalles etter `render`, før noen operasjoner og antakelser gjøres.\n *\n * F.eks.:\n * <code>\n * render(<div><PktTextinput id=\"textinput\" name={'textInput'} label=\"My text input\" aria-label=\"My text input\" /></div>);\n * await waitForPktElementsToBeDefined();\n *\n * await setPktElementValue(\"My text input\", \"new value\");\n * </code>\n */\nconst waitForPktElementsToBeDefined = async () =>\n await Promise.all(\n PKT_CUSTOM_ELEMENTS.map((elementName) => {\n if (document.querySelector(elementName) !== null) {\n return window.customElements.whenDefined(elementName)\n }\n }).filter((promise) => promise),\n )\n\nconst findPossibleWrappingPktCustomElement = <R extends PTLElementType>(\n innerElement: HTMLElement | null,\n isByRole: boolean,\n args: Array<any>,\n): PTLElementType => {\n if (!innerElement === null) {\n throw getElementError(`Finner ikke noe element med ${isByRole ? 'role' : 'label'} \"${args[0]}\"`, document.body)\n }\n const pktElement = innerElement?.closest(PKT_CUSTOM_FORMFIELDS.join(', ')) as R | null\n if (pktElement) {\n return pktElement as R\n } else {\n return innerElement as R\n }\n}\n\nconst getPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n (query: QueryTypes = 'label', identifier: string | RegExp, container?: HTMLElement): PTLElementType => {\n const queryFunc = syncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = doElementSearch(identifier, query, queryFunc, container)[0]\n return findPossibleWrappingPktCustomElement(innerElement, false, [])\n }\n\nconst removeElementBySelector = (ancestor: HTMLElement, selector: string) => {\n const elements = Array.from(ancestor.querySelectorAll(selector))\n elements.forEach((element) => {\n element.parentNode?.removeChild(element)\n })\n}\n\nfunction getPureLabelText(label: Node) {\n const clonedLabel = label.cloneNode(true) as HTMLElement\n removeElementBySelector(clonedLabel, 'pkt-helptext')\n removeElementBySelector(clonedLabel, '.pkt-input-suffix')\n removeElementBySelector(clonedLabel, '.pkt-input-prefix')\n removeElementBySelector(clonedLabel, '.pkt-input-icon')\n removeElementBySelector(clonedLabel, 'option')\n return clonedLabel.textContent?.trim() || null\n}\n\nconst getPureLabelTextForLabelOwner = (labelOwner: HTMLElement): string | null => {\n const label =\n ('labels' in labelOwner &&\n labelOwner.labels instanceof NodeList &&\n labelOwner.labels.length > 0 &&\n labelOwner.labels[0]) ||\n (labelOwner.querySelector('label') as HTMLLabelElement | null)\n if (label) {\n return getPureLabelText(label)\n } else {\n return null\n }\n}\n\nconst labelMatcher = (labelTextToMatch: string) => (nodeContent: string, element: Element | null) => {\n if (element instanceof HTMLElement) {\n const labelWithoutHelptext = getPureLabelTextForLabelOwner(element as HTMLElement)\n return labelWithoutHelptext === labelTextToMatch\n } else {\n return false\n }\n}\n\nconst doElementSearch = <T>(\n identifier: string | RegExp,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n) => {\n try {\n return typeof identifier === 'string' && query === 'label'\n ? queryFunc(container, labelMatcher(identifier.trim()))\n : queryFunc(container, identifier)\n } catch (e) {\n if (typeof identifier === 'string' && query === 'label') {\n // Spesial-case for <pkt-select> som ikke har aria-label\n const matchingLabel: HTMLLabelElement | undefined = Array.from(document.body.querySelectorAll('label')).find(\n (labelElement) => getPureLabelText(labelElement) === identifier,\n )\n const labelOwner = matchingLabel?.control || matchingLabel?.closest('pkt-select')\n if (labelOwner) {\n return [labelOwner]\n } else {\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, document.body)\n }\n }\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, document.body)\n }\n}\n\nconst findPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n async (\n query: QueryTypes = 'label',\n identifier: string | RegExp,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0]\n\n return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []))\n }\n\nconst getPktElementByLabel =\n (testingLibrary: TestingLibraryTools) => (label: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp, container?: HTMLElement): Promise<PTLElementType> =>\n findPktElementBy(testingLibrary)('label', label, container)\n\nconst getPktElementByText = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('text', text, container)\n\nconst findPktElementByText =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('text', text, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)((element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Only elements with a checked attribute can be checked')\n }\n const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n return Promise.resolve(returnValue)\n })\n\n/**\n * Representerer en option i en PktSelect.\n *\n * @property {string} 0 - verdien (value)\n * @property {string | null} 1 - Tekstinnholdet, <option>tekstinnhold</option>\n * @property {boolean} 2 - Om denne er valgt (selected)\n */\nexport type PktOption = [string, string | null, boolean]\n\nconst getPktSelectOptions = (testingLibrary: TestingLibraryTools) =>\n syncFuncWithStringIdentifierOrElement(testingLibrary)<PktSelect, Array<PktOption>>(\n (selectElement: PktSelect): Array<PktOption> => {\n const optionElements: Array<HTMLOptionElement> = Array.from(\n selectElement.querySelectorAll(\n ':scope > option, :scope > optgroup > option, :scope > data, :scope > optgroup > data',\n ),\n )\n const currentValue = selectElement.value\n return optionElements.map((optionElement) => [\n optionElement.value,\n optionElement.textContent,\n optionElement.value === currentValue,\n ])\n },\n )\n\nconst getAllPktElementsByLabelText =\n (testingLibrary: TestingLibraryTools) =>\n (label: string, container?: HTMLElement): Element[] => {\n const innerElements = testingLibrary.getAllByLabelText(container || document.body, label)\n return innerElements.map((element) => findPossibleWrappingPktCustomElement(element, false, []))\n }\n\nconst setPktElementValue = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (\n element: PTLElementType,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent = false,\n ): Promise<boolean> => {\n if (\n Array.isArray(valueOrValues) &&\n !(element.tagName === 'PKT-SELECT' && 'multiple' in element && element.multiple)\n ) {\n throw new Error('Only a multi-select PktSelect can have multiple values')\n }\n if (element.tagName === 'PKT-SELECT') {\n testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(true)\n } else {\n const returnValue = useInputEvent\n ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(returnValue)\n }\n },\n )\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PktRadioButton) => {\n const returnValue = testingLibrary.fireEvent.click(element)\n return Promise.resolve(returnValue)\n }, 'text')\n"],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AS,EAAE,QAAQ,EAAE,OAAO,cAAc,EAAG,CAAA,IAC5E,eAAe,UAAU,OAAO,SAAS,EAAE,QAAQ,EAAE,OAAO,cAAc,EAAA,CAAG;AAC1E,eAAA,QAAQ,QAAQ,WAAW;AAAA,MACpC;AAAA,IACF;AAAA,EACF;AAEF,QAAM,iBAAiB,CAAC,mBACtB,uCAAuC,cAAc,EAAE,OAAO,YAA4B;AACxF,UAAM,cAAc,eAAe,UAAU,MAAM,OAAO;AACnD,WAAA,QAAQ,QAAQ,WAAW;AAAA,EACpC,GAAG,MAAM;;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@oslokommune/punkt-testing-utils",
|
|
3
|
+
"version": "12.24.3",
|
|
4
|
+
"description": "Test-utilities for Punkt",
|
|
5
|
+
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
|
+
"author": "Team Designsystem, Oslo Origo",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/punkt-testing-utils.umd.js",
|
|
9
|
+
"module": "dist/punkt-testing-utils.es.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@testing-library/dom": "10.4.0",
|
|
16
|
+
"@testing-library/react": "16.2.0",
|
|
17
|
+
"element-internals-polyfill": "^1.3.10"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@oslokommune/punkt-elements": "^12.24.0",
|
|
21
|
+
"@oslokommune/punkt-react": "12.24.0",
|
|
22
|
+
"@testing-library/jest-dom": "^6.1.0",
|
|
23
|
+
"@types/jest": "^29.5.0",
|
|
24
|
+
"@types/testing-library__jest-dom": "^5.14.9",
|
|
25
|
+
"@vitejs/plugin-react": "^4.0.0",
|
|
26
|
+
"jest": "^29.7.0",
|
|
27
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
28
|
+
"ts-jest": "^29.2.6",
|
|
29
|
+
"typescript": "^5.0.0",
|
|
30
|
+
"vite": "^4.5.0",
|
|
31
|
+
"vite-plugin-dts": "^3.6.0",
|
|
32
|
+
"whatwg-fetch": "^3.6.19"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "vite build",
|
|
36
|
+
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
|
|
37
|
+
"lint:fix": "eslint --fix 'src/**/*.{jsx,ts,tsx}'",
|
|
38
|
+
"format": "prettier --write src//**/*.{ts,tsx,css} --config ./.prettierrc",
|
|
39
|
+
"test": "jest --config jest.config.cjs"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"@oslokommune/punkt-elements": ">=12.0.0",
|
|
43
|
+
"@oslokommune/punkt-react": ">=12.0.0",
|
|
44
|
+
"react": ">=16.8.0",
|
|
45
|
+
"react-dom": ">=16.8.0"
|
|
46
|
+
},
|
|
47
|
+
"keywords": [
|
|
48
|
+
"punkt",
|
|
49
|
+
"pkt",
|
|
50
|
+
"designsystem",
|
|
51
|
+
"react",
|
|
52
|
+
"elements",
|
|
53
|
+
"testing-library"
|
|
54
|
+
],
|
|
55
|
+
"private": false,
|
|
56
|
+
"publishConfig": {
|
|
57
|
+
"access": "public",
|
|
58
|
+
"registry": "https://registry.npmjs.org"
|
|
59
|
+
},
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"gitHead": "0b77aeb2e4333420d9806e2aa70742f8617a8ebf"
|
|
62
|
+
}
|