@oslokommune/punkt-testing-utils 19.18.0 → 19.18.2
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.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { default as DomTestingLibrary } from '@testing-library/dom';
|
|
2
1
|
import { PktBackLink, PktCheckbox, PktCombobox, PktDatepicker, PktHelptext, PktIcon, PktInputWrapper, PktLoader, PktProgressbar, PktRadioButton, PktSelect, PktTextarea } from '@oslokommune/punkt-elements';
|
|
2
|
+
import { default as DomTestingLibrary } from '@testing-library/dom';
|
|
3
3
|
export declare const PKT_CUSTOM_FORMFIELDS: string[];
|
|
4
4
|
type PTLElementType = PktBackLink | PktCheckbox | PktCombobox | PktDatepicker | PktHelptext | PktIcon | PktInputWrapper | PktLoader | PktProgressbar | PktRadioButton | PktSelect | PktTextarea | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
5
5
|
export type PktTestingLibraryOptions = Pick<typeof DomTestingLibrary, 'fireEvent' | 'findAllByLabelText' | 'findAllByTestId' | 'findAllByDisplayValue' | 'findAllByText' | 'getAllByLabelText' | 'getAllByTestId' | 'getAllByDisplayValue' | 'getAllByText'>;
|
|
@@ -98,7 +98,8 @@ var withTestingLibrary = (testingLibrary, fn) => fn(testingLibrary);
|
|
|
98
98
|
var waitForPktElementsToBeDefined = async () => await Promise.all(PKT_CUSTOM_ELEMENTS.map((elementName) => {
|
|
99
99
|
if (document.querySelector(elementName) !== null) return window.customElements.whenDefined(elementName);
|
|
100
100
|
}).filter((promise) => promise));
|
|
101
|
-
var findPossibleWrappingPktCustomElement = (
|
|
101
|
+
var findPossibleWrappingPktCustomElement = (innerElement, isByRole, args) => {
|
|
102
|
+
if (!innerElement) throw getElementError(`Finner ikke noe element med ${isByRole ? "role" : "label"} "${args[0]}"`, document.body);
|
|
102
103
|
const pktElement = innerElement?.closest(PKT_CUSTOM_FORMFIELDS.join(", "));
|
|
103
104
|
if (pktElement) return pktElement;
|
|
104
105
|
else return innerElement;
|
|
@@ -106,9 +107,9 @@ var findPossibleWrappingPktCustomElement = (testingLibrary) => (innerElement, is
|
|
|
106
107
|
var getPktElementBy = (testingLibrary) => (query = "label", identifier, container) => {
|
|
107
108
|
try {
|
|
108
109
|
const innerElement = doElementSearch(identifier, query, syncQueryFunctionResolver(testingLibrary)(query), container)[0];
|
|
109
|
-
return findPossibleWrappingPktCustomElement(
|
|
110
|
-
} catch
|
|
111
|
-
return fallbackSearchForPktSelectByLabel(
|
|
110
|
+
return findPossibleWrappingPktCustomElement(innerElement, false, []);
|
|
111
|
+
} catch {
|
|
112
|
+
return fallbackSearchForPktSelectByLabel(identifier, query, container);
|
|
112
113
|
}
|
|
113
114
|
};
|
|
114
115
|
var removeElementBySelector = (ancestor, selector) => {
|
|
@@ -140,7 +141,7 @@ var labelMatcher = (labelTextToMatch) => (nodeContent, element) => {
|
|
|
140
141
|
if (element instanceof HTMLElement) return getPureLabelTextForLabelOwner(element) === labelTextToMatch;
|
|
141
142
|
else return false;
|
|
142
143
|
};
|
|
143
|
-
var fallbackSearchForPktSelectByLabel = (
|
|
144
|
+
var fallbackSearchForPktSelectByLabel = (identifier, query, container = document.body) => {
|
|
144
145
|
if (typeof identifier === "string" && query === "label") {
|
|
145
146
|
const matchingLabel = Array.from(container.querySelectorAll("label")).find((labelElement) => getPureLabelText(labelElement) === identifier);
|
|
146
147
|
const labelOwner = matchingLabel?.control || matchingLabel?.closest("pkt-select") || matchingLabel?.closest("pkt-combobox");
|
|
@@ -156,9 +157,9 @@ var findPktElementBy = (testingLibrary) => async (query = "label", identifier, c
|
|
|
156
157
|
try {
|
|
157
158
|
if (identifier instanceof HTMLLabelElement) return Promise.resolve(getByLabelElement(identifier));
|
|
158
159
|
const innerElement = (await doElementSearch(identifier, query, asyncQueryFunctionResolver(testingLibrary)(query), container))[0];
|
|
159
|
-
return Promise.resolve(findPossibleWrappingPktCustomElement(
|
|
160
|
-
} catch
|
|
161
|
-
return fallbackSearchForPktSelectByLabel(
|
|
160
|
+
return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []));
|
|
161
|
+
} catch {
|
|
162
|
+
return fallbackSearchForPktSelectByLabel(identifier, query, container);
|
|
162
163
|
}
|
|
163
164
|
};
|
|
164
165
|
var getPktElementByLabel = (testingLibrary) => (label, container) => label instanceof HTMLLabelElement ? getByLabelElement(label) : getPktElementBy(testingLibrary)("label", label, container);
|
|
@@ -189,7 +190,7 @@ var getPktElementByDisplayValue = (testingLibrary) => (text, container) => getPk
|
|
|
189
190
|
var findPktElementByDisplayValue = (testingLibrary) => (text, container) => findPktElementBy(testingLibrary)("displayValue", text, container);
|
|
190
191
|
var getPktSelectOptions = (testingLibrary) => syncFuncWithStringIdentifierOrElement(testingLibrary)((selectElement, onlySelected) => {
|
|
191
192
|
const optionElements = Array.from(selectElement.querySelectorAll("option:not(.pkt-hide), data:not(.pkt.hide)"));
|
|
192
|
-
const filter = onlySelected ? ([, , selected]) => selected : (
|
|
193
|
+
const filter = onlySelected ? ([, , selected]) => selected : () => true;
|
|
193
194
|
const currentValue = selectElement.value;
|
|
194
195
|
return optionElements.map((optionElement) => [
|
|
195
196
|
optionElement.value,
|
|
@@ -198,7 +199,7 @@ var getPktSelectOptions = (testingLibrary) => syncFuncWithStringIdentifierOrElem
|
|
|
198
199
|
]).filter(filter);
|
|
199
200
|
});
|
|
200
201
|
var getAllPktElementsByLabelText = (testingLibrary) => (label, container) => {
|
|
201
|
-
return testingLibrary.getAllByLabelText(container || document.body, label).map((element) => findPossibleWrappingPktCustomElement(
|
|
202
|
+
return testingLibrary.getAllByLabelText(container || document.body, label).map((element) => findPossibleWrappingPktCustomElement(element, false, []));
|
|
202
203
|
};
|
|
203
204
|
var setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element, valueOrValues, optionsOrUseInputEvent = false) => {
|
|
204
205
|
const options = typeof optionsOrUseInputEvent === "object" ? optionsOrUseInputEvent : optionsOrUseInputEvent && {
|
|
@@ -242,7 +243,7 @@ var pktClickButton = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(
|
|
|
242
243
|
}, "text");
|
|
243
244
|
var setPktSelectedOptionsByLabel = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (pktSelect, ...desiredOptionLabels) => {
|
|
244
245
|
const availableOptions = getPktSelectOptions(testingLibrary)(pktSelect);
|
|
245
|
-
const selectedOptions = desiredOptionLabels.map((optionLabel) => availableOptions.find(([
|
|
246
|
+
const selectedOptions = desiredOptionLabels.map((optionLabel) => availableOptions.find(([, label]) => label === optionLabel)).filter((possibleOption) => possibleOption);
|
|
246
247
|
if (selectedOptions.length !== desiredOptionLabels.length) throw new Error("Noen av option'ene finnes ikke i denne komponenten. Du valgte " + JSON.stringify(desiredOptionLabels) + ", mens valgmulighetene er " + JSON.stringify(availableOptions.map(([, label]) => label)));
|
|
247
248
|
return await setPktElementValue(testingLibrary)(pktSelect, selectedOptions.map(([value]) => value));
|
|
248
249
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"punkt-testing-utils.es.js","names":["pktSelect"],"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 PktBackLink,\n PktCheckbox,\n PktCombobox,\n PktDatepicker,\n PktHelptext,\n PktIcon,\n PktInputWrapper,\n PktLoader,\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-backlink',\n 'pkt-checkbox',\n 'pkt-combobox',\n 'pkt-progressbar',\n 'pkt-radiobutton',\n 'pkt-select',\n 'pkt-textarea',\n 'pkt-textinput',\n]\nconst PKT_CUSTOM_ELEMENTS = [\n 'pkt-input-wrapper',\n 'pkt-icon',\n 'pkt-helptext',\n 'pkt-loader',\n 'pkt-backlink',\n ...PKT_CUSTOM_FORMFIELDS,\n]\n\ntype PTLElementType =\n | PktBackLink\n | PktCheckbox\n | PktCombobox\n | PktDatepicker\n | PktHelptext\n | PktIcon\n | PktInputWrapper\n | PktLoader\n | PktProgressbar\n | PktRadioButton\n | PktSelect\n | PktTextarea\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 | HTMLLabelElement\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (\n label: string | RegExp | HTMLLabelElement,\n container?: HTMLElement,\n ) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp | HTMLLabelElement, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, onlySelected?: boolean) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n isPktElementChecked: (labelOrElement: LabelOrElement) => boolean\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n optionsOrUseInputEvent?:\n | boolean\n | {\n useInputEventForNative?: boolean\n useChangeEventForNative?: boolean\n setValuePropForNative?: boolean\n },\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<HTMLInputElement | HTMLButtonElement>) => Promise<boolean>\n waitForPktElementsToBeDefined: () => Promise<any>\n setPktSelectedOptionsByLabel: (\n labelOrElement: LabelOrElement<PktSelect>,\n ...desiredOptionLabels: Array<string>\n ) => Promise<any>\n getPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => PTLElementType\n findPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n}\n\nexport const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary = (\n options: PktTestingLibraryOptions,\n) => {\n const tools: TestingLibraryTools = {\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 isPktElementChecked: withTestingLibrary(tools, isPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n setPktSelectedOptionsByLabel: withTestingLibrary(tools, setPktSelectedOptionsByLabel),\n getPktElementByDisplayValue: withTestingLibrary(tools, getPktElementByDisplayValue),\n findPktElementByDisplayValue: withTestingLibrary(tools, findPktElementByDisplayValue),\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 | HTMLElement, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? (getPktElementBy(testingLibrary)(query, elementOrIdentifier) as ElementType)\n : (elementOrIdentifier as ElementType)\n\nconst getByLabelElement = <ElementType>(possibleLabelElement: HTMLLabelElement) => {\n const control = possibleLabelElement instanceof HTMLLabelElement && (possibleLabelElement.control as ElementType)\n if (control) {\n return control\n } else {\n throw new Error('Fant ikke noe skjema-element for labelen: ' + possibleLabelElement.outerHTML)\n }\n}\n\nconst asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | HTMLElement, query: QueryTypes) =>\n (elementOrIdentifier instanceof HTMLLabelElement && getByLabelElement<ElementType>(elementOrIdentifier)) ||\n (typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? ((await findPktElementBy(testingLibrary)(query, elementOrIdentifier)) as ElementType)\n : (elementOrIdentifier as ElementType))\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 | HTMLElement, ...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 | HTMLElement, ...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 =\n (testingLibrary: TestingLibraryTools) =>\n <R extends PTLElementType>(innerElement: HTMLElement | null, isByRole: boolean, args: Array<any>): 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 try {\n const queryFunc = syncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = doElementSearch(identifier, query, queryFunc, container)[0]\n return findPossibleWrappingPktCustomElement(testingLibrary)(innerElement, false, [])\n } catch (e) {\n return fallbackSearchForPktSelectByLabel(testingLibrary)(identifier, query, container)\n }\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, '.pkt-input__counter')\n removeElementBySelector(clonedLabel, 'option')\n removeElementBySelector(clonedLabel, 'pkt-listbox')\n removeElementBySelector(clonedLabel, '.pkt-alert--error')\n removeElementBySelector(clonedLabel, '.pkt-tag')\n removeElementBySelector(clonedLabel, '.pkt-input-check__input-helptext')\n removeElementBySelector(clonedLabel, '.pkt-inputwrapper__helptext')\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 (['input', ...PKT_CUSTOM_FORMFIELDS].includes(labelOwner.tagName.toLowerCase()) &&\n (labelOwner.querySelector('label') as HTMLLabelElement | null)) ||\n 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 fallbackSearchForPktSelectByLabel =\n (testingLibrary: TestingLibraryTools) =>\n (identifier: any, query: QueryTypes, container: HTMLElement = document.body): PTLElementType => {\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(container.querySelectorAll('label')).find(\n (labelElement) => getPureLabelText(labelElement) === identifier,\n )\n const labelOwner =\n matchingLabel?.control || matchingLabel?.closest('pkt-select') || matchingLabel?.closest('pkt-combobox')\n if (!labelOwner) {\n throw getElementError(`Fant ikke noe element med label \"${identifier}\"`, container)\n }\n return labelOwner as PTLElementType\n }\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, container)\n }\n\nconst doElementSearch = <T>(\n identifier: string | RegExp | HTMLLabelElement,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n): T => {\n return identifier instanceof HTMLLabelElement\n ? getByLabelElement(identifier)\n : typeof identifier === 'string' && query === 'label'\n ? queryFunc(container, labelMatcher(identifier.trim()))\n : queryFunc(container, identifier)\n}\n\nconst findPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n async (\n query: QueryTypes = 'label',\n identifier: string | RegExp | HTMLLabelElement,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n try {\n if (identifier instanceof HTMLLabelElement) {\n return Promise.resolve(getByLabelElement<PTLElementType>(identifier))\n }\n const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0]\n return Promise.resolve(findPossibleWrappingPktCustomElement(testingLibrary)(innerElement, false, []))\n } catch (e) {\n return fallbackSearchForPktSelectByLabel(testingLibrary)(identifier, query, container)\n }\n }\n\nconst getPktElementByLabel =\n (testingLibrary: TestingLibraryTools) => (label: string | RegExp | HTMLLabelElement, container?: HTMLElement) =>\n label instanceof HTMLLabelElement\n ? getByLabelElement<PTLElementType>(label)\n : getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp | HTMLLabelElement, container?: HTMLElement): Promise<PTLElementType> =>\n label instanceof HTMLLabelElement\n ? getByLabelElement<PTLElementType>(label)\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)(async (element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Bare elementer som har en \"checked\"-attributt støttes')\n }\n let returnValue: boolean = false\n if (element.tagName === 'INPUT') {\n // https://github.com/testing-library/react-testing-library/issues/175#issuecomment-637349276\n // kentcdodds: \"this should probably be documented better, but with checkboxes you don't actually fire change\n // events, you should fire click events instead.\"\n const htmlInputElement = element as HTMLInputElement\n if (htmlInputElement.type === 'radio') {\n if (!checked) {\n throw new Error(\"Kan ikke av-velge en <input type='radio'> - prøv å velge en annen radioknapp i samme gruppe\")\n } else {\n returnValue = testingLibrary.fireEvent.click(element)\n await new Promise((resolve) => setTimeout(resolve, 0))\n }\n } else if (htmlInputElement.type === 'checkbox') {\n if (htmlInputElement.checked !== checked) {\n returnValue = testingLibrary.fireEvent.click(element)\n }\n }\n } else {\n returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n }\n\n return Promise.resolve(returnValue)\n })\n\nconst isPktElementChecked =\n (testingLibrary: TestingLibraryTools) =>\n (target: LabelOrElement): boolean => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<PTLElementType>(target, 'label')\n\n if ('checked' in element) return !!(element as HTMLInputElement).checked\n\n const descendant = element.querySelector('input[type=\"radio\"]:checked, input[type=\"checkbox\"]:checked')\n return descendant !== null\n }\n\nconst getPktElementByDisplayValue =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('displayValue', text, container)\n\nconst findPktElementByDisplayValue =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('displayValue', text, container)\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 | undefined, boolean]\n\nconst getPktSelectOptions = (testingLibrary: TestingLibraryTools) =>\n syncFuncWithStringIdentifierOrElement(testingLibrary)<PktSelect, Array<PktOption>>(\n (selectElement: PktSelect, onlySelected?: boolean): Array<PktOption> => {\n const optionElements: Array<HTMLOptionElement> = Array.from(\n selectElement.querySelectorAll('option:not(.pkt-hide), data:not(.pkt.hide)'),\n )\n const filter = onlySelected ? ([, , selected]: PktOption) => selected : (_: PktOption) => true\n const currentValue = selectElement.value\n return optionElements\n .map(\n (optionElement) =>\n [optionElement.value, optionElement.textContent?.trim(), optionElement.value === currentValue] as PktOption,\n )\n .filter(filter)\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(testingLibrary)(element, false, []))\n }\n\nconst setPktElementValue = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (\n element: PTLElementType,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n optionsOrUseInputEvent:\n | boolean\n | {\n useInputEventForNative?: boolean\n useChangeEventForNative?: boolean\n setValuePropForNative?: boolean\n } = false,\n ): Promise<boolean> => {\n const options =\n typeof optionsOrUseInputEvent === 'object'\n ? optionsOrUseInputEvent\n : // Hvis det er en boolean, så vær bakoverkompatibel\n (optionsOrUseInputEvent && {\n useInputEventForNative: true,\n useChangeEventForNative: true,\n setValuePropForNative: true,\n }) || {\n useInputEventForNative: false,\n useChangeEventForNative: true,\n setValuePropForNative: false,\n }\n if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === 'PKT-SELECT') {\n throw new Error('Multi-verdi <pkt-select> støttes ikke. Bruk <pkt-combobox> i stedet.')\n }\n if (element.tagName === 'PKT-SELECT' || element.tagName === 'PKT-COMBOBOX') {\n const pktSelect = element as HTMLSelectElement\n const multiple = pktSelect.multiple\n const valueAsArray = Array.isArray(valueOrValues) ? valueOrValues : [valueOrValues]\n const newValue = (multiple && valueAsArray) || (valueAsArray.length == 0 && '') || valueAsArray[0]\n testingLibrary.fireEvent.change(element, { target: { value: newValue } })\n return Promise.resolve(true)\n } else {\n if (options.setValuePropForNative) {\n if ('value' in element) {\n element.value = valueOrValues.toString()\n }\n }\n if (options.useInputEventForNative) {\n testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n }\n if (options.useChangeEventForNative) {\n testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n }\n return Promise.resolve(true)\n }\n },\n )\n\nconst containsRadioInput = (element: Element): boolean => {\n if (element.tagName === 'INPUT' && (element as HTMLInputElement).type === 'radio') return true\n\n if (element.querySelector?.('input[type=\"radio\"]')) return true\n\n const label = element.closest?.('label') as HTMLLabelElement | null\n if (label) {\n const control = label.control || (label.htmlFor ? document.getElementById(label.htmlFor) : null)\n return !!(control && (control as HTMLInputElement).type === 'radio')\n }\n\n return false\n}\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType) => {\n if (containsRadioInput(element)) {\n throw new Error('Klikk på <pkt-radiobutton> støttes ikke - bruk setPktElementChecked i stedet')\n }\n return testingLibrary.fireEvent.click(element)\n }, 'text')\n\nconst setPktSelectedOptionsByLabel = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (pktSelect: PktSelect, ...desiredOptionLabels: Array<string>) => {\n const availableOptions = getPktSelectOptions(testingLibrary)(pktSelect)\n const selectedOptions = desiredOptionLabels\n .map((optionLabel) => availableOptions.find(([_, label]) => label === optionLabel))\n .filter((possibleOption) => possibleOption) as Array<PktOption>\n if (selectedOptions.length !== desiredOptionLabels.length) {\n throw new Error(\n \"Noen av option'ene finnes ikke i denne komponenten. Du valgte \" +\n JSON.stringify(desiredOptionLabels) +\n ', mens valgmulighetene er ' +\n JSON.stringify(availableOptions.map(([, label]) => label)),\n )\n }\n\n return await setPktElementValue(testingLibrary)(\n pktSelect,\n selectedOptions.map(([value]) => value),\n )\n },\n )\n"],"mappings":";;AA4BA,IAAa,wBAAwB;CACnC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AACA,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F,IAAM,sBAAsB,YAA8B;CACxD,IAAI,QAAQ,YAAY,WAAY,QAA6B,SAAS,SAAS,OAAO;CAE1F,IAAI,QAAQ,gBAAgB,uBAAqB,GAAG,OAAO;CAE3D,MAAM,QAAQ,QAAQ,UAAU,OAAO;CACvC,IAAI,OAAO;EACT,MAAM,UAAU,MAAM,YAAY,MAAM,UAAU,SAAS,eAAe,MAAM,OAAO,IAAI;EAC3F,OAAO,CAAC,EAAE,WAAY,QAA6B,SAAS;CAC9D;CAEA,OAAO;AACT;AAEA,IAAM,kBAAkB,mBACtB,uCAAuC,cAAc,CAAC,CAAC,OAAO,YAA4B;CACxF,IAAI,mBAAmB,OAAO,GAC5B,MAAM,IAAI,MAAM,8EAA8E;CAEhG,OAAO,eAAe,UAAU,MAAM,OAAO;AAC/C,GAAG,MAAM;AAEX,IAAM,gCAAgC,mBACpC,uCAAuC,cAAc,CAAC,CACpD,OAAO,WAAsB,GAAG,wBAAuC;CACrE,MAAM,mBAAmB,oBAAoB,cAAc,CAAC,CAAC,SAAS;CACtE,MAAM,kBAAkB,oBACrB,KAAK,gBAAgB,iBAAiB,MAAM,CAAC,GAAG,WAAW,UAAU,WAAW,CAAC,CAAC,CAClF,QAAQ,mBAAmB,cAAc;CAC5C,IAAI,gBAAgB,WAAW,oBAAoB,QACjD,MAAM,IAAI,MACR,mEACE,KAAK,UAAU,mBAAmB,IAClC,+BACA,KAAK,UAAU,iBAAiB,KAAK,GAAG,WAAW,KAAK,CAAC,CAC7D;CAGF,OAAO,MAAM,mBAAmB,cAAc,CAAC,CAC7C,WACA,gBAAgB,KAAK,CAAC,WAAW,KAAK,CACxC;AACF,CACF"}
|
|
1
|
+
{"version":3,"file":"punkt-testing-utils.es.js","names":["pktSelect"],"sources":["../src/index.ts"],"sourcesContent":["import {\n PktBackLink,\n PktCheckbox,\n PktCombobox,\n PktDatepicker,\n PktHelptext,\n PktIcon,\n PktInputWrapper,\n PktLoader,\n PktProgressbar,\n PktRadioButton,\n PktSelect,\n PktTextarea,\n} from '@oslokommune/punkt-elements'\nimport 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 { AllByBoundAttribute } from '@testing-library/dom/types/queries'\n\nexport const PKT_CUSTOM_FORMFIELDS = [\n 'pkt-backlink',\n 'pkt-checkbox',\n 'pkt-combobox',\n 'pkt-progressbar',\n 'pkt-radiobutton',\n 'pkt-select',\n 'pkt-textarea',\n 'pkt-textinput',\n]\nconst PKT_CUSTOM_ELEMENTS = [\n 'pkt-input-wrapper',\n 'pkt-icon',\n 'pkt-helptext',\n 'pkt-loader',\n 'pkt-backlink',\n ...PKT_CUSTOM_FORMFIELDS,\n]\n\ntype PTLElementType =\n | PktBackLink\n | PktCheckbox\n | PktCombobox\n | PktDatepicker\n | PktHelptext\n | PktIcon\n | PktInputWrapper\n | PktLoader\n | PktProgressbar\n | PktRadioButton\n | PktSelect\n | PktTextarea\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 | HTMLLabelElement\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (\n label: string | RegExp | HTMLLabelElement,\n container?: HTMLElement,\n ) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp | HTMLLabelElement, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, onlySelected?: boolean) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n isPktElementChecked: (labelOrElement: LabelOrElement) => boolean\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n optionsOrUseInputEvent?:\n | boolean\n | {\n useInputEventForNative?: boolean\n useChangeEventForNative?: boolean\n setValuePropForNative?: boolean\n },\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<HTMLInputElement | HTMLButtonElement>) => Promise<boolean>\n waitForPktElementsToBeDefined: () => Promise<any>\n setPktSelectedOptionsByLabel: (\n labelOrElement: LabelOrElement<PktSelect>,\n ...desiredOptionLabels: Array<string>\n ) => Promise<any>\n getPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => PTLElementType\n findPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n}\n\nexport const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary = (\n options: PktTestingLibraryOptions,\n) => {\n const tools: TestingLibraryTools = {\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 isPktElementChecked: withTestingLibrary(tools, isPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n setPktSelectedOptionsByLabel: withTestingLibrary(tools, setPktSelectedOptionsByLabel),\n getPktElementByDisplayValue: withTestingLibrary(tools, getPktElementByDisplayValue),\n findPktElementByDisplayValue: withTestingLibrary(tools, findPktElementByDisplayValue),\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 | HTMLElement, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? (getPktElementBy(testingLibrary)(query, elementOrIdentifier) as ElementType)\n : (elementOrIdentifier as ElementType)\n\nconst getByLabelElement = <ElementType>(possibleLabelElement: HTMLLabelElement) => {\n const control = possibleLabelElement instanceof HTMLLabelElement && (possibleLabelElement.control as ElementType)\n if (control) {\n return control\n } else {\n throw new Error('Fant ikke noe skjema-element for labelen: ' + possibleLabelElement.outerHTML)\n }\n}\n\nconst asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | HTMLElement, query: QueryTypes) =>\n (elementOrIdentifier instanceof HTMLLabelElement && getByLabelElement<ElementType>(elementOrIdentifier)) ||\n (typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? ((await findPktElementBy(testingLibrary)(query, elementOrIdentifier)) as ElementType)\n : (elementOrIdentifier as ElementType))\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 | HTMLElement, ...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 | HTMLElement, ...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) {\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 try {\n const queryFunc = syncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = doElementSearch(identifier, query, queryFunc, container)[0]\n return findPossibleWrappingPktCustomElement(innerElement, false, [])\n } catch {\n return fallbackSearchForPktSelectByLabel(identifier, query, container)\n }\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, '.pkt-input__counter')\n removeElementBySelector(clonedLabel, 'option')\n removeElementBySelector(clonedLabel, 'pkt-listbox')\n removeElementBySelector(clonedLabel, '.pkt-alert--error')\n removeElementBySelector(clonedLabel, '.pkt-tag')\n removeElementBySelector(clonedLabel, '.pkt-input-check__input-helptext')\n removeElementBySelector(clonedLabel, '.pkt-inputwrapper__helptext')\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 (['input', ...PKT_CUSTOM_FORMFIELDS].includes(labelOwner.tagName.toLowerCase()) &&\n (labelOwner.querySelector('label') as HTMLLabelElement | null)) ||\n 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 fallbackSearchForPktSelectByLabel = (\n identifier: any,\n query: QueryTypes,\n container: HTMLElement = document.body,\n): PTLElementType => {\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(container.querySelectorAll('label')).find(\n (labelElement) => getPureLabelText(labelElement) === identifier,\n )\n const labelOwner =\n matchingLabel?.control || matchingLabel?.closest('pkt-select') || matchingLabel?.closest('pkt-combobox')\n if (!labelOwner) {\n throw getElementError(`Fant ikke noe element med label \"${identifier}\"`, container)\n }\n return labelOwner as PTLElementType\n }\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, container)\n}\n\nconst doElementSearch = <T>(\n identifier: string | RegExp | HTMLLabelElement,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n): T => {\n return identifier instanceof HTMLLabelElement\n ? getByLabelElement(identifier)\n : typeof identifier === 'string' && query === 'label'\n ? queryFunc(container, labelMatcher(identifier.trim()))\n : queryFunc(container, identifier)\n}\n\nconst findPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n async (\n query: QueryTypes = 'label',\n identifier: string | RegExp | HTMLLabelElement,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n try {\n if (identifier instanceof HTMLLabelElement) {\n return Promise.resolve(getByLabelElement<PTLElementType>(identifier))\n }\n const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0]\n return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []))\n } catch {\n return fallbackSearchForPktSelectByLabel(identifier, query, container)\n }\n }\n\nconst getPktElementByLabel =\n (testingLibrary: TestingLibraryTools) => (label: string | RegExp | HTMLLabelElement, container?: HTMLElement) =>\n label instanceof HTMLLabelElement\n ? getByLabelElement<PTLElementType>(label)\n : getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp | HTMLLabelElement, container?: HTMLElement): Promise<PTLElementType> =>\n label instanceof HTMLLabelElement\n ? getByLabelElement<PTLElementType>(label)\n : findPktElementBy(testingLibrary)('label', label, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Bare elementer som har en \"checked\"-attributt støttes')\n }\n let returnValue: boolean = false\n if (element.tagName === 'INPUT') {\n // https://github.com/testing-library/react-testing-library/issues/175#issuecomment-637349276\n // kentcdodds: \"this should probably be documented better, but with checkboxes you don't actually fire change\n // events, you should fire click events instead.\"\n const htmlInputElement = element as HTMLInputElement\n if (htmlInputElement.type === 'radio') {\n if (!checked) {\n throw new Error(\"Kan ikke av-velge en <input type='radio'> - prøv å velge en annen radioknapp i samme gruppe\")\n } else {\n returnValue = testingLibrary.fireEvent.click(element)\n await new Promise((resolve) => setTimeout(resolve, 0))\n }\n } else if (htmlInputElement.type === 'checkbox') {\n if (htmlInputElement.checked !== checked) {\n returnValue = testingLibrary.fireEvent.click(element)\n }\n }\n } else {\n returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n }\n\n return Promise.resolve(returnValue)\n })\n\nconst isPktElementChecked =\n (testingLibrary: TestingLibraryTools) =>\n (target: LabelOrElement): boolean => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<PTLElementType>(target, 'label')\n\n if ('checked' in element) return !!(element as HTMLInputElement).checked\n\n const descendant = element.querySelector('input[type=\"radio\"]:checked, input[type=\"checkbox\"]:checked')\n return descendant !== null\n }\n\nconst getPktElementByDisplayValue =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('displayValue', text, container)\n\nconst findPktElementByDisplayValue =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('displayValue', text, container)\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 | undefined, boolean]\n\nconst getPktSelectOptions = (testingLibrary: TestingLibraryTools) =>\n syncFuncWithStringIdentifierOrElement(testingLibrary)<PktSelect, Array<PktOption>>(\n (selectElement: PktSelect, onlySelected?: boolean): Array<PktOption> => {\n const optionElements: Array<HTMLOptionElement> = Array.from(\n selectElement.querySelectorAll('option:not(.pkt-hide), data:not(.pkt.hide)'),\n )\n const filter = onlySelected ? ([, , selected]: PktOption) => selected : () => true\n const currentValue = selectElement.value\n return optionElements\n .map(\n (optionElement) =>\n [optionElement.value, optionElement.textContent?.trim(), optionElement.value === currentValue] as PktOption,\n )\n .filter(filter)\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 optionsOrUseInputEvent:\n | boolean\n | {\n useInputEventForNative?: boolean\n useChangeEventForNative?: boolean\n setValuePropForNative?: boolean\n } = false,\n ): Promise<boolean> => {\n const options =\n typeof optionsOrUseInputEvent === 'object'\n ? optionsOrUseInputEvent\n : // Hvis det er en boolean, så vær bakoverkompatibel\n (optionsOrUseInputEvent && {\n useInputEventForNative: true,\n useChangeEventForNative: true,\n setValuePropForNative: true,\n }) || {\n useInputEventForNative: false,\n useChangeEventForNative: true,\n setValuePropForNative: false,\n }\n if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === 'PKT-SELECT') {\n throw new Error('Multi-verdi <pkt-select> støttes ikke. Bruk <pkt-combobox> i stedet.')\n }\n if (element.tagName === 'PKT-SELECT' || element.tagName === 'PKT-COMBOBOX') {\n const pktSelect = element as HTMLSelectElement\n const multiple = pktSelect.multiple\n const valueAsArray = Array.isArray(valueOrValues) ? valueOrValues : [valueOrValues]\n const newValue = (multiple && valueAsArray) || (valueAsArray.length == 0 && '') || valueAsArray[0]\n testingLibrary.fireEvent.change(element, { target: { value: newValue } })\n return Promise.resolve(true)\n } else {\n if (options.setValuePropForNative) {\n if ('value' in element) {\n element.value = valueOrValues.toString()\n }\n }\n if (options.useInputEventForNative) {\n testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n }\n if (options.useChangeEventForNative) {\n testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n }\n return Promise.resolve(true)\n }\n },\n )\n\nconst containsRadioInput = (element: Element): boolean => {\n if (element.tagName === 'INPUT' && (element as HTMLInputElement).type === 'radio') return true\n\n if (element.querySelector?.('input[type=\"radio\"]')) return true\n\n const label = element.closest?.('label') as HTMLLabelElement | null\n if (label) {\n const control = label.control || (label.htmlFor ? document.getElementById(label.htmlFor) : null)\n return !!(control && (control as HTMLInputElement).type === 'radio')\n }\n\n return false\n}\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType) => {\n if (containsRadioInput(element)) {\n throw new Error('Klikk på <pkt-radiobutton> støttes ikke - bruk setPktElementChecked i stedet')\n }\n return testingLibrary.fireEvent.click(element)\n }, 'text')\n\nconst setPktSelectedOptionsByLabel = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (pktSelect: PktSelect, ...desiredOptionLabels: Array<string>) => {\n const availableOptions = getPktSelectOptions(testingLibrary)(pktSelect)\n const selectedOptions = desiredOptionLabels\n .map((optionLabel) => availableOptions.find(([, label]) => label === optionLabel))\n .filter((possibleOption) => possibleOption) as Array<PktOption>\n if (selectedOptions.length !== desiredOptionLabels.length) {\n throw new Error(\n \"Noen av option'ene finnes ikke i denne komponenten. Du valgte \" +\n JSON.stringify(desiredOptionLabels) +\n ', mens valgmulighetene er ' +\n JSON.stringify(availableOptions.map(([, label]) => label)),\n )\n }\n\n return await setPktElementValue(testingLibrary)(\n pktSelect,\n selectedOptions.map(([value]) => value),\n )\n },\n )\n"],"mappings":";;AA4BA,IAAa,wBAAwB;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CAC7B;AACF,CACF;AAEF,IAAM,sBAAsB,YAA8B;CACxD,IAAI,QAAQ,YAAY,WAAY,QAA6B,SAAS,SAAS,OAAO;CAE1F,IAAI,QAAQ,gBAAgB,uBAAqB,GAAG,OAAO;CAE3D,MAAM,QAAQ,QAAQ,UAAU,OAAO;CACvC,IAAI,OAAO;EACT,MAAM,UAAU,MAAM,YAAY,MAAM,UAAU,SAAS,eAAe,MAAM,OAAO,IAAI;EAC3F,OAAO,CAAC,EAAE,WAAY,QAA6B,SAAS;CAC9D;CAEA,OAAO;AACT;AAEA,IAAM,kBAAkB,mBACtB,uCAAuC,cAAc,CAAC,CAAC,OAAO,YAA4B;CACxF,IAAI,mBAAmB,OAAO,GAC5B,MAAM,IAAI,MAAM,8EAA8E;CAEhG,OAAO,eAAe,UAAU,MAAM,OAAO;AAC/C,GAAG,MAAM;AAEX,IAAM,gCAAgC,mBACpC,uCAAuC,cAAc,CAAC,CACpD,OAAO,WAAsB,GAAG,wBAAuC;CACrE,MAAM,mBAAmB,oBAAoB,cAAc,CAAC,CAAC,SAAS;CACtE,MAAM,kBAAkB,oBACrB,KAAK,gBAAgB,iBAAiB,MAAM,GAAG,WAAW,UAAU,WAAW,CAAC,CAAC,CACjF,QAAQ,mBAAmB,cAAc;CAC5C,IAAI,gBAAgB,WAAW,oBAAoB,QACjD,MAAM,IAAI,MACR,mEACE,KAAK,UAAU,mBAAmB,IAClC,+BACA,KAAK,UAAU,iBAAiB,KAAK,GAAG,WAAW,KAAK,CAAC,CAC7D;CAGF,OAAO,MAAM,mBAAmB,cAAc,CAAC,CAC7C,WACA,gBAAgB,KAAK,CAAC,WAAW,KAAK,CACxC;AACF,CACF"}
|
|
@@ -101,7 +101,8 @@
|
|
|
101
101
|
var waitForPktElementsToBeDefined = async () => await Promise.all(PKT_CUSTOM_ELEMENTS.map((elementName) => {
|
|
102
102
|
if (document.querySelector(elementName) !== null) return window.customElements.whenDefined(elementName);
|
|
103
103
|
}).filter((promise) => promise));
|
|
104
|
-
var findPossibleWrappingPktCustomElement = (
|
|
104
|
+
var findPossibleWrappingPktCustomElement = (innerElement, isByRole, args) => {
|
|
105
|
+
if (!innerElement) throw (0, _testing_library_dom.getElementError)(`Finner ikke noe element med ${isByRole ? "role" : "label"} "${args[0]}"`, document.body);
|
|
105
106
|
const pktElement = innerElement?.closest(PKT_CUSTOM_FORMFIELDS.join(", "));
|
|
106
107
|
if (pktElement) return pktElement;
|
|
107
108
|
else return innerElement;
|
|
@@ -109,9 +110,9 @@
|
|
|
109
110
|
var getPktElementBy = (testingLibrary) => (query = "label", identifier, container) => {
|
|
110
111
|
try {
|
|
111
112
|
const innerElement = doElementSearch(identifier, query, syncQueryFunctionResolver(testingLibrary)(query), container)[0];
|
|
112
|
-
return findPossibleWrappingPktCustomElement(
|
|
113
|
-
} catch
|
|
114
|
-
return fallbackSearchForPktSelectByLabel(
|
|
113
|
+
return findPossibleWrappingPktCustomElement(innerElement, false, []);
|
|
114
|
+
} catch {
|
|
115
|
+
return fallbackSearchForPktSelectByLabel(identifier, query, container);
|
|
115
116
|
}
|
|
116
117
|
};
|
|
117
118
|
var removeElementBySelector = (ancestor, selector) => {
|
|
@@ -143,7 +144,7 @@
|
|
|
143
144
|
if (element instanceof HTMLElement) return getPureLabelTextForLabelOwner(element) === labelTextToMatch;
|
|
144
145
|
else return false;
|
|
145
146
|
};
|
|
146
|
-
var fallbackSearchForPktSelectByLabel = (
|
|
147
|
+
var fallbackSearchForPktSelectByLabel = (identifier, query, container = document.body) => {
|
|
147
148
|
if (typeof identifier === "string" && query === "label") {
|
|
148
149
|
const matchingLabel = Array.from(container.querySelectorAll("label")).find((labelElement) => getPureLabelText(labelElement) === identifier);
|
|
149
150
|
const labelOwner = matchingLabel?.control || matchingLabel?.closest("pkt-select") || matchingLabel?.closest("pkt-combobox");
|
|
@@ -159,9 +160,9 @@
|
|
|
159
160
|
try {
|
|
160
161
|
if (identifier instanceof HTMLLabelElement) return Promise.resolve(getByLabelElement(identifier));
|
|
161
162
|
const innerElement = (await doElementSearch(identifier, query, asyncQueryFunctionResolver(testingLibrary)(query), container))[0];
|
|
162
|
-
return Promise.resolve(findPossibleWrappingPktCustomElement(
|
|
163
|
-
} catch
|
|
164
|
-
return fallbackSearchForPktSelectByLabel(
|
|
163
|
+
return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []));
|
|
164
|
+
} catch {
|
|
165
|
+
return fallbackSearchForPktSelectByLabel(identifier, query, container);
|
|
165
166
|
}
|
|
166
167
|
};
|
|
167
168
|
var getPktElementByLabel = (testingLibrary) => (label, container) => label instanceof HTMLLabelElement ? getByLabelElement(label) : getPktElementBy(testingLibrary)("label", label, container);
|
|
@@ -192,7 +193,7 @@
|
|
|
192
193
|
var findPktElementByDisplayValue = (testingLibrary) => (text, container) => findPktElementBy(testingLibrary)("displayValue", text, container);
|
|
193
194
|
var getPktSelectOptions = (testingLibrary) => syncFuncWithStringIdentifierOrElement(testingLibrary)((selectElement, onlySelected) => {
|
|
194
195
|
const optionElements = Array.from(selectElement.querySelectorAll("option:not(.pkt-hide), data:not(.pkt.hide)"));
|
|
195
|
-
const filter = onlySelected ? ([, , selected]) => selected : (
|
|
196
|
+
const filter = onlySelected ? ([, , selected]) => selected : () => true;
|
|
196
197
|
const currentValue = selectElement.value;
|
|
197
198
|
return optionElements.map((optionElement) => [
|
|
198
199
|
optionElement.value,
|
|
@@ -201,7 +202,7 @@
|
|
|
201
202
|
]).filter(filter);
|
|
202
203
|
});
|
|
203
204
|
var getAllPktElementsByLabelText = (testingLibrary) => (label, container) => {
|
|
204
|
-
return testingLibrary.getAllByLabelText(container || document.body, label).map((element) => findPossibleWrappingPktCustomElement(
|
|
205
|
+
return testingLibrary.getAllByLabelText(container || document.body, label).map((element) => findPossibleWrappingPktCustomElement(element, false, []));
|
|
205
206
|
};
|
|
206
207
|
var setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element, valueOrValues, optionsOrUseInputEvent = false) => {
|
|
207
208
|
const options = typeof optionsOrUseInputEvent === "object" ? optionsOrUseInputEvent : optionsOrUseInputEvent && {
|
|
@@ -245,7 +246,7 @@
|
|
|
245
246
|
}, "text");
|
|
246
247
|
var setPktSelectedOptionsByLabel = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (pktSelect, ...desiredOptionLabels) => {
|
|
247
248
|
const availableOptions = getPktSelectOptions(testingLibrary)(pktSelect);
|
|
248
|
-
const selectedOptions = desiredOptionLabels.map((optionLabel) => availableOptions.find(([
|
|
249
|
+
const selectedOptions = desiredOptionLabels.map((optionLabel) => availableOptions.find(([, label]) => label === optionLabel)).filter((possibleOption) => possibleOption);
|
|
249
250
|
if (selectedOptions.length !== desiredOptionLabels.length) throw new Error("Noen av option'ene finnes ikke i denne komponenten. Du valgte " + JSON.stringify(desiredOptionLabels) + ", mens valgmulighetene er " + JSON.stringify(availableOptions.map(([, label]) => label)));
|
|
250
251
|
return await setPktElementValue(testingLibrary)(pktSelect, selectedOptions.map(([value]) => value));
|
|
251
252
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"punkt-testing-utils.umd.js","names":["getElementError","pktSelect"],"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 PktBackLink,\n PktCheckbox,\n PktCombobox,\n PktDatepicker,\n PktHelptext,\n PktIcon,\n PktInputWrapper,\n PktLoader,\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-backlink',\n 'pkt-checkbox',\n 'pkt-combobox',\n 'pkt-progressbar',\n 'pkt-radiobutton',\n 'pkt-select',\n 'pkt-textarea',\n 'pkt-textinput',\n]\nconst PKT_CUSTOM_ELEMENTS = [\n 'pkt-input-wrapper',\n 'pkt-icon',\n 'pkt-helptext',\n 'pkt-loader',\n 'pkt-backlink',\n ...PKT_CUSTOM_FORMFIELDS,\n]\n\ntype PTLElementType =\n | PktBackLink\n | PktCheckbox\n | PktCombobox\n | PktDatepicker\n | PktHelptext\n | PktIcon\n | PktInputWrapper\n | PktLoader\n | PktProgressbar\n | PktRadioButton\n | PktSelect\n | PktTextarea\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 | HTMLLabelElement\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (\n label: string | RegExp | HTMLLabelElement,\n container?: HTMLElement,\n ) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp | HTMLLabelElement, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, onlySelected?: boolean) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n isPktElementChecked: (labelOrElement: LabelOrElement) => boolean\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n optionsOrUseInputEvent?:\n | boolean\n | {\n useInputEventForNative?: boolean\n useChangeEventForNative?: boolean\n setValuePropForNative?: boolean\n },\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<HTMLInputElement | HTMLButtonElement>) => Promise<boolean>\n waitForPktElementsToBeDefined: () => Promise<any>\n setPktSelectedOptionsByLabel: (\n labelOrElement: LabelOrElement<PktSelect>,\n ...desiredOptionLabels: Array<string>\n ) => Promise<any>\n getPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => PTLElementType\n findPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n}\n\nexport const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary = (\n options: PktTestingLibraryOptions,\n) => {\n const tools: TestingLibraryTools = {\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 isPktElementChecked: withTestingLibrary(tools, isPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n setPktSelectedOptionsByLabel: withTestingLibrary(tools, setPktSelectedOptionsByLabel),\n getPktElementByDisplayValue: withTestingLibrary(tools, getPktElementByDisplayValue),\n findPktElementByDisplayValue: withTestingLibrary(tools, findPktElementByDisplayValue),\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 | HTMLElement, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? (getPktElementBy(testingLibrary)(query, elementOrIdentifier) as ElementType)\n : (elementOrIdentifier as ElementType)\n\nconst getByLabelElement = <ElementType>(possibleLabelElement: HTMLLabelElement) => {\n const control = possibleLabelElement instanceof HTMLLabelElement && (possibleLabelElement.control as ElementType)\n if (control) {\n return control\n } else {\n throw new Error('Fant ikke noe skjema-element for labelen: ' + possibleLabelElement.outerHTML)\n }\n}\n\nconst asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | HTMLElement, query: QueryTypes) =>\n (elementOrIdentifier instanceof HTMLLabelElement && getByLabelElement<ElementType>(elementOrIdentifier)) ||\n (typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? ((await findPktElementBy(testingLibrary)(query, elementOrIdentifier)) as ElementType)\n : (elementOrIdentifier as ElementType))\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 | HTMLElement, ...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 | HTMLElement, ...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 =\n (testingLibrary: TestingLibraryTools) =>\n <R extends PTLElementType>(innerElement: HTMLElement | null, isByRole: boolean, args: Array<any>): 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 try {\n const queryFunc = syncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = doElementSearch(identifier, query, queryFunc, container)[0]\n return findPossibleWrappingPktCustomElement(testingLibrary)(innerElement, false, [])\n } catch (e) {\n return fallbackSearchForPktSelectByLabel(testingLibrary)(identifier, query, container)\n }\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, '.pkt-input__counter')\n removeElementBySelector(clonedLabel, 'option')\n removeElementBySelector(clonedLabel, 'pkt-listbox')\n removeElementBySelector(clonedLabel, '.pkt-alert--error')\n removeElementBySelector(clonedLabel, '.pkt-tag')\n removeElementBySelector(clonedLabel, '.pkt-input-check__input-helptext')\n removeElementBySelector(clonedLabel, '.pkt-inputwrapper__helptext')\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 (['input', ...PKT_CUSTOM_FORMFIELDS].includes(labelOwner.tagName.toLowerCase()) &&\n (labelOwner.querySelector('label') as HTMLLabelElement | null)) ||\n 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 fallbackSearchForPktSelectByLabel =\n (testingLibrary: TestingLibraryTools) =>\n (identifier: any, query: QueryTypes, container: HTMLElement = document.body): PTLElementType => {\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(container.querySelectorAll('label')).find(\n (labelElement) => getPureLabelText(labelElement) === identifier,\n )\n const labelOwner =\n matchingLabel?.control || matchingLabel?.closest('pkt-select') || matchingLabel?.closest('pkt-combobox')\n if (!labelOwner) {\n throw getElementError(`Fant ikke noe element med label \"${identifier}\"`, container)\n }\n return labelOwner as PTLElementType\n }\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, container)\n }\n\nconst doElementSearch = <T>(\n identifier: string | RegExp | HTMLLabelElement,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n): T => {\n return identifier instanceof HTMLLabelElement\n ? getByLabelElement(identifier)\n : typeof identifier === 'string' && query === 'label'\n ? queryFunc(container, labelMatcher(identifier.trim()))\n : queryFunc(container, identifier)\n}\n\nconst findPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n async (\n query: QueryTypes = 'label',\n identifier: string | RegExp | HTMLLabelElement,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n try {\n if (identifier instanceof HTMLLabelElement) {\n return Promise.resolve(getByLabelElement<PTLElementType>(identifier))\n }\n const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0]\n return Promise.resolve(findPossibleWrappingPktCustomElement(testingLibrary)(innerElement, false, []))\n } catch (e) {\n return fallbackSearchForPktSelectByLabel(testingLibrary)(identifier, query, container)\n }\n }\n\nconst getPktElementByLabel =\n (testingLibrary: TestingLibraryTools) => (label: string | RegExp | HTMLLabelElement, container?: HTMLElement) =>\n label instanceof HTMLLabelElement\n ? getByLabelElement<PTLElementType>(label)\n : getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp | HTMLLabelElement, container?: HTMLElement): Promise<PTLElementType> =>\n label instanceof HTMLLabelElement\n ? getByLabelElement<PTLElementType>(label)\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)(async (element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Bare elementer som har en \"checked\"-attributt støttes')\n }\n let returnValue: boolean = false\n if (element.tagName === 'INPUT') {\n // https://github.com/testing-library/react-testing-library/issues/175#issuecomment-637349276\n // kentcdodds: \"this should probably be documented better, but with checkboxes you don't actually fire change\n // events, you should fire click events instead.\"\n const htmlInputElement = element as HTMLInputElement\n if (htmlInputElement.type === 'radio') {\n if (!checked) {\n throw new Error(\"Kan ikke av-velge en <input type='radio'> - prøv å velge en annen radioknapp i samme gruppe\")\n } else {\n returnValue = testingLibrary.fireEvent.click(element)\n await new Promise((resolve) => setTimeout(resolve, 0))\n }\n } else if (htmlInputElement.type === 'checkbox') {\n if (htmlInputElement.checked !== checked) {\n returnValue = testingLibrary.fireEvent.click(element)\n }\n }\n } else {\n returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n }\n\n return Promise.resolve(returnValue)\n })\n\nconst isPktElementChecked =\n (testingLibrary: TestingLibraryTools) =>\n (target: LabelOrElement): boolean => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<PTLElementType>(target, 'label')\n\n if ('checked' in element) return !!(element as HTMLInputElement).checked\n\n const descendant = element.querySelector('input[type=\"radio\"]:checked, input[type=\"checkbox\"]:checked')\n return descendant !== null\n }\n\nconst getPktElementByDisplayValue =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('displayValue', text, container)\n\nconst findPktElementByDisplayValue =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('displayValue', text, container)\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 | undefined, boolean]\n\nconst getPktSelectOptions = (testingLibrary: TestingLibraryTools) =>\n syncFuncWithStringIdentifierOrElement(testingLibrary)<PktSelect, Array<PktOption>>(\n (selectElement: PktSelect, onlySelected?: boolean): Array<PktOption> => {\n const optionElements: Array<HTMLOptionElement> = Array.from(\n selectElement.querySelectorAll('option:not(.pkt-hide), data:not(.pkt.hide)'),\n )\n const filter = onlySelected ? ([, , selected]: PktOption) => selected : (_: PktOption) => true\n const currentValue = selectElement.value\n return optionElements\n .map(\n (optionElement) =>\n [optionElement.value, optionElement.textContent?.trim(), optionElement.value === currentValue] as PktOption,\n )\n .filter(filter)\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(testingLibrary)(element, false, []))\n }\n\nconst setPktElementValue = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (\n element: PTLElementType,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n optionsOrUseInputEvent:\n | boolean\n | {\n useInputEventForNative?: boolean\n useChangeEventForNative?: boolean\n setValuePropForNative?: boolean\n } = false,\n ): Promise<boolean> => {\n const options =\n typeof optionsOrUseInputEvent === 'object'\n ? optionsOrUseInputEvent\n : // Hvis det er en boolean, så vær bakoverkompatibel\n (optionsOrUseInputEvent && {\n useInputEventForNative: true,\n useChangeEventForNative: true,\n setValuePropForNative: true,\n }) || {\n useInputEventForNative: false,\n useChangeEventForNative: true,\n setValuePropForNative: false,\n }\n if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === 'PKT-SELECT') {\n throw new Error('Multi-verdi <pkt-select> støttes ikke. Bruk <pkt-combobox> i stedet.')\n }\n if (element.tagName === 'PKT-SELECT' || element.tagName === 'PKT-COMBOBOX') {\n const pktSelect = element as HTMLSelectElement\n const multiple = pktSelect.multiple\n const valueAsArray = Array.isArray(valueOrValues) ? valueOrValues : [valueOrValues]\n const newValue = (multiple && valueAsArray) || (valueAsArray.length == 0 && '') || valueAsArray[0]\n testingLibrary.fireEvent.change(element, { target: { value: newValue } })\n return Promise.resolve(true)\n } else {\n if (options.setValuePropForNative) {\n if ('value' in element) {\n element.value = valueOrValues.toString()\n }\n }\n if (options.useInputEventForNative) {\n testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n }\n if (options.useChangeEventForNative) {\n testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n }\n return Promise.resolve(true)\n }\n },\n )\n\nconst containsRadioInput = (element: Element): boolean => {\n if (element.tagName === 'INPUT' && (element as HTMLInputElement).type === 'radio') return true\n\n if (element.querySelector?.('input[type=\"radio\"]')) return true\n\n const label = element.closest?.('label') as HTMLLabelElement | null\n if (label) {\n const control = label.control || (label.htmlFor ? document.getElementById(label.htmlFor) : null)\n return !!(control && (control as HTMLInputElement).type === 'radio')\n }\n\n return false\n}\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType) => {\n if (containsRadioInput(element)) {\n throw new Error('Klikk på <pkt-radiobutton> støttes ikke - bruk setPktElementChecked i stedet')\n }\n return testingLibrary.fireEvent.click(element)\n }, 'text')\n\nconst setPktSelectedOptionsByLabel = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (pktSelect: PktSelect, ...desiredOptionLabels: Array<string>) => {\n const availableOptions = getPktSelectOptions(testingLibrary)(pktSelect)\n const selectedOptions = desiredOptionLabels\n .map((optionLabel) => availableOptions.find(([_, label]) => label === optionLabel))\n .filter((possibleOption) => possibleOption) as Array<PktOption>\n if (selectedOptions.length !== desiredOptionLabels.length) {\n throw new Error(\n \"Noen av option'ene finnes ikke i denne komponenten. Du valgte \" +\n JSON.stringify(desiredOptionLabels) +\n ', mens valgmulighetene er ' +\n JSON.stringify(availableOptions.map(([, label]) => label)),\n )\n }\n\n return await setPktElementValue(testingLibrary)(\n pktSelect,\n selectedOptions.map(([value]) => value),\n )\n },\n )\n"],"mappings":";;;;;CA4BA,IAAa,wBAAwB;EACnC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;C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E,OAAO,QAAQ,QAAQ,IAAI;EAC7B;CACF,CACF;CAEF,IAAM,sBAAsB,YAA8B;EACxD,IAAI,QAAQ,YAAY,WAAY,QAA6B,SAAS,SAAS,OAAO;EAE1F,IAAI,QAAQ,gBAAgB,uBAAqB,GAAG,OAAO;EAE3D,MAAM,QAAQ,QAAQ,UAAU,OAAO;EACvC,IAAI,OAAO;GACT,MAAM,UAAU,MAAM,YAAY,MAAM,UAAU,SAAS,eAAe,MAAM,OAAO,IAAI;GAC3F,OAAO,CAAC,EAAE,WAAY,QAA6B,SAAS;EAC9D;EAEA,OAAO;CACT;CAEA,IAAM,kBAAkB,mBACtB,uCAAuC,cAAc,CAAC,CAAC,OAAO,YAA4B;EACxF,IAAI,mBAAmB,OAAO,GAC5B,MAAM,IAAI,MAAM,8EAA8E;EAEhG,OAAO,eAAe,UAAU,MAAM,OAAO;CAC/C,GAAG,MAAM;CAEX,IAAM,gCAAgC,mBACpC,uCAAuC,cAAc,CAAC,CACpD,OAAO,WAAsB,GAAG,wBAAuC;EACrE,MAAM,mBAAmB,oBAAoB,cAAc,CAAC,CAAC,SAAS;EACtE,MAAM,kBAAkB,oBACrB,KAAK,gBAAgB,iBAAiB,MAAM,CAAC,GAAG,WAAW,UAAU,WAAW,CAAC,CAAC,CAClF,QAAQ,mBAAmB,cAAc;EAC5C,IAAI,gBAAgB,WAAW,oBAAoB,QACjD,MAAM,IAAI,MACR,mEACE,KAAK,UAAU,mBAAmB,IAClC,+BACA,KAAK,UAAU,iBAAiB,KAAK,GAAG,WAAW,KAAK,CAAC,CAC7D;EAGF,OAAO,MAAM,mBAAmB,cAAc,CAAC,CAC7C,WACA,gBAAgB,KAAK,CAAC,WAAW,KAAK,CACxC;CACF,CACF"}
|
|
1
|
+
{"version":3,"file":"punkt-testing-utils.umd.js","names":["getElementError","pktSelect"],"sources":["../src/index.ts"],"sourcesContent":["import {\n PktBackLink,\n PktCheckbox,\n PktCombobox,\n PktDatepicker,\n PktHelptext,\n PktIcon,\n PktInputWrapper,\n PktLoader,\n PktProgressbar,\n PktRadioButton,\n PktSelect,\n PktTextarea,\n} from '@oslokommune/punkt-elements'\nimport 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 { AllByBoundAttribute } from '@testing-library/dom/types/queries'\n\nexport const PKT_CUSTOM_FORMFIELDS = [\n 'pkt-backlink',\n 'pkt-checkbox',\n 'pkt-combobox',\n 'pkt-progressbar',\n 'pkt-radiobutton',\n 'pkt-select',\n 'pkt-textarea',\n 'pkt-textinput',\n]\nconst PKT_CUSTOM_ELEMENTS = [\n 'pkt-input-wrapper',\n 'pkt-icon',\n 'pkt-helptext',\n 'pkt-loader',\n 'pkt-backlink',\n ...PKT_CUSTOM_FORMFIELDS,\n]\n\ntype PTLElementType =\n | PktBackLink\n | PktCheckbox\n | PktCombobox\n | PktDatepicker\n | PktHelptext\n | PktIcon\n | PktInputWrapper\n | PktLoader\n | PktProgressbar\n | PktRadioButton\n | PktSelect\n | PktTextarea\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 | HTMLLabelElement\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (\n label: string | RegExp | HTMLLabelElement,\n container?: HTMLElement,\n ) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp | HTMLLabelElement, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, onlySelected?: boolean) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n isPktElementChecked: (labelOrElement: LabelOrElement) => boolean\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n optionsOrUseInputEvent?:\n | boolean\n | {\n useInputEventForNative?: boolean\n useChangeEventForNative?: boolean\n setValuePropForNative?: boolean\n },\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<HTMLInputElement | HTMLButtonElement>) => Promise<boolean>\n waitForPktElementsToBeDefined: () => Promise<any>\n setPktSelectedOptionsByLabel: (\n labelOrElement: LabelOrElement<PktSelect>,\n ...desiredOptionLabels: Array<string>\n ) => Promise<any>\n getPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => PTLElementType\n findPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n}\n\nexport const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary = (\n options: PktTestingLibraryOptions,\n) => {\n const tools: TestingLibraryTools = {\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 isPktElementChecked: withTestingLibrary(tools, isPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n setPktSelectedOptionsByLabel: withTestingLibrary(tools, setPktSelectedOptionsByLabel),\n getPktElementByDisplayValue: withTestingLibrary(tools, getPktElementByDisplayValue),\n findPktElementByDisplayValue: withTestingLibrary(tools, findPktElementByDisplayValue),\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 | HTMLElement, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? (getPktElementBy(testingLibrary)(query, elementOrIdentifier) as ElementType)\n : (elementOrIdentifier as ElementType)\n\nconst getByLabelElement = <ElementType>(possibleLabelElement: HTMLLabelElement) => {\n const control = possibleLabelElement instanceof HTMLLabelElement && (possibleLabelElement.control as ElementType)\n if (control) {\n return control\n } else {\n throw new Error('Fant ikke noe skjema-element for labelen: ' + possibleLabelElement.outerHTML)\n }\n}\n\nconst asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | HTMLElement, query: QueryTypes) =>\n (elementOrIdentifier instanceof HTMLLabelElement && getByLabelElement<ElementType>(elementOrIdentifier)) ||\n (typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? ((await findPktElementBy(testingLibrary)(query, elementOrIdentifier)) as ElementType)\n : (elementOrIdentifier as ElementType))\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 | HTMLElement, ...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 | HTMLElement, ...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) {\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 try {\n const queryFunc = syncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = doElementSearch(identifier, query, queryFunc, container)[0]\n return findPossibleWrappingPktCustomElement(innerElement, false, [])\n } catch {\n return fallbackSearchForPktSelectByLabel(identifier, query, container)\n }\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, '.pkt-input__counter')\n removeElementBySelector(clonedLabel, 'option')\n removeElementBySelector(clonedLabel, 'pkt-listbox')\n removeElementBySelector(clonedLabel, '.pkt-alert--error')\n removeElementBySelector(clonedLabel, '.pkt-tag')\n removeElementBySelector(clonedLabel, '.pkt-input-check__input-helptext')\n removeElementBySelector(clonedLabel, '.pkt-inputwrapper__helptext')\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 (['input', ...PKT_CUSTOM_FORMFIELDS].includes(labelOwner.tagName.toLowerCase()) &&\n (labelOwner.querySelector('label') as HTMLLabelElement | null)) ||\n 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 fallbackSearchForPktSelectByLabel = (\n identifier: any,\n query: QueryTypes,\n container: HTMLElement = document.body,\n): PTLElementType => {\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(container.querySelectorAll('label')).find(\n (labelElement) => getPureLabelText(labelElement) === identifier,\n )\n const labelOwner =\n matchingLabel?.control || matchingLabel?.closest('pkt-select') || matchingLabel?.closest('pkt-combobox')\n if (!labelOwner) {\n throw getElementError(`Fant ikke noe element med label \"${identifier}\"`, container)\n }\n return labelOwner as PTLElementType\n }\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, container)\n}\n\nconst doElementSearch = <T>(\n identifier: string | RegExp | HTMLLabelElement,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n): T => {\n return identifier instanceof HTMLLabelElement\n ? getByLabelElement(identifier)\n : typeof identifier === 'string' && query === 'label'\n ? queryFunc(container, labelMatcher(identifier.trim()))\n : queryFunc(container, identifier)\n}\n\nconst findPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n async (\n query: QueryTypes = 'label',\n identifier: string | RegExp | HTMLLabelElement,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n try {\n if (identifier instanceof HTMLLabelElement) {\n return Promise.resolve(getByLabelElement<PTLElementType>(identifier))\n }\n const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0]\n return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []))\n } catch {\n return fallbackSearchForPktSelectByLabel(identifier, query, container)\n }\n }\n\nconst getPktElementByLabel =\n (testingLibrary: TestingLibraryTools) => (label: string | RegExp | HTMLLabelElement, container?: HTMLElement) =>\n label instanceof HTMLLabelElement\n ? getByLabelElement<PTLElementType>(label)\n : getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp | HTMLLabelElement, container?: HTMLElement): Promise<PTLElementType> =>\n label instanceof HTMLLabelElement\n ? getByLabelElement<PTLElementType>(label)\n : findPktElementBy(testingLibrary)('label', label, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Bare elementer som har en \"checked\"-attributt støttes')\n }\n let returnValue: boolean = false\n if (element.tagName === 'INPUT') {\n // https://github.com/testing-library/react-testing-library/issues/175#issuecomment-637349276\n // kentcdodds: \"this should probably be documented better, but with checkboxes you don't actually fire change\n // events, you should fire click events instead.\"\n const htmlInputElement = element as HTMLInputElement\n if (htmlInputElement.type === 'radio') {\n if (!checked) {\n throw new Error(\"Kan ikke av-velge en <input type='radio'> - prøv å velge en annen radioknapp i samme gruppe\")\n } else {\n returnValue = testingLibrary.fireEvent.click(element)\n await new Promise((resolve) => setTimeout(resolve, 0))\n }\n } else if (htmlInputElement.type === 'checkbox') {\n if (htmlInputElement.checked !== checked) {\n returnValue = testingLibrary.fireEvent.click(element)\n }\n }\n } else {\n returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n }\n\n return Promise.resolve(returnValue)\n })\n\nconst isPktElementChecked =\n (testingLibrary: TestingLibraryTools) =>\n (target: LabelOrElement): boolean => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<PTLElementType>(target, 'label')\n\n if ('checked' in element) return !!(element as HTMLInputElement).checked\n\n const descendant = element.querySelector('input[type=\"radio\"]:checked, input[type=\"checkbox\"]:checked')\n return descendant !== null\n }\n\nconst getPktElementByDisplayValue =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('displayValue', text, container)\n\nconst findPktElementByDisplayValue =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('displayValue', text, container)\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 | undefined, boolean]\n\nconst getPktSelectOptions = (testingLibrary: TestingLibraryTools) =>\n syncFuncWithStringIdentifierOrElement(testingLibrary)<PktSelect, Array<PktOption>>(\n (selectElement: PktSelect, onlySelected?: boolean): Array<PktOption> => {\n const optionElements: Array<HTMLOptionElement> = Array.from(\n selectElement.querySelectorAll('option:not(.pkt-hide), data:not(.pkt.hide)'),\n )\n const filter = onlySelected ? ([, , selected]: PktOption) => selected : () => true\n const currentValue = selectElement.value\n return optionElements\n .map(\n (optionElement) =>\n [optionElement.value, optionElement.textContent?.trim(), optionElement.value === currentValue] as PktOption,\n )\n .filter(filter)\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 optionsOrUseInputEvent:\n | boolean\n | {\n useInputEventForNative?: boolean\n useChangeEventForNative?: boolean\n setValuePropForNative?: boolean\n } = false,\n ): Promise<boolean> => {\n const options =\n typeof optionsOrUseInputEvent === 'object'\n ? optionsOrUseInputEvent\n : // Hvis det er en boolean, så vær bakoverkompatibel\n (optionsOrUseInputEvent && {\n useInputEventForNative: true,\n useChangeEventForNative: true,\n setValuePropForNative: true,\n }) || {\n useInputEventForNative: false,\n useChangeEventForNative: true,\n setValuePropForNative: false,\n }\n if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === 'PKT-SELECT') {\n throw new Error('Multi-verdi <pkt-select> støttes ikke. Bruk <pkt-combobox> i stedet.')\n }\n if (element.tagName === 'PKT-SELECT' || element.tagName === 'PKT-COMBOBOX') {\n const pktSelect = element as HTMLSelectElement\n const multiple = pktSelect.multiple\n const valueAsArray = Array.isArray(valueOrValues) ? valueOrValues : [valueOrValues]\n const newValue = (multiple && valueAsArray) || (valueAsArray.length == 0 && '') || valueAsArray[0]\n testingLibrary.fireEvent.change(element, { target: { value: newValue } })\n return Promise.resolve(true)\n } else {\n if (options.setValuePropForNative) {\n if ('value' in element) {\n element.value = valueOrValues.toString()\n }\n }\n if (options.useInputEventForNative) {\n testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n }\n if (options.useChangeEventForNative) {\n testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n }\n return Promise.resolve(true)\n }\n },\n )\n\nconst containsRadioInput = (element: Element): boolean => {\n if (element.tagName === 'INPUT' && (element as HTMLInputElement).type === 'radio') return true\n\n if (element.querySelector?.('input[type=\"radio\"]')) return true\n\n const label = element.closest?.('label') as HTMLLabelElement | null\n if (label) {\n const control = label.control || (label.htmlFor ? document.getElementById(label.htmlFor) : null)\n return !!(control && (control as HTMLInputElement).type === 'radio')\n }\n\n return false\n}\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType) => {\n if (containsRadioInput(element)) {\n throw new Error('Klikk på <pkt-radiobutton> støttes ikke - bruk setPktElementChecked i stedet')\n }\n return testingLibrary.fireEvent.click(element)\n }, 'text')\n\nconst setPktSelectedOptionsByLabel = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (pktSelect: PktSelect, ...desiredOptionLabels: Array<string>) => {\n const availableOptions = getPktSelectOptions(testingLibrary)(pktSelect)\n const selectedOptions = desiredOptionLabels\n .map((optionLabel) => availableOptions.find(([, label]) => label === optionLabel))\n .filter((possibleOption) => possibleOption) as Array<PktOption>\n if (selectedOptions.length !== desiredOptionLabels.length) {\n throw new Error(\n \"Noen av option'ene finnes ikke i denne komponenten. Du valgte \" +\n JSON.stringify(desiredOptionLabels) +\n ', mens valgmulighetene er ' +\n JSON.stringify(availableOptions.map(([, label]) => label)),\n )\n }\n\n return await setPktElementValue(testingLibrary)(\n pktSelect,\n selectedOptions.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2
2
|
"name": "@oslokommune/punkt-testing-utils",
|
|
3
|
-
"version": "19.18.
|
|
3
|
+
"version": "19.18.2",
|
|
4
4
|
"description": "Test-utilities for Punkt",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo kommune",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
"dist"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@testing-library/dom": "10.4.
|
|
15
|
+
"@testing-library/dom": "10.4.2",
|
|
16
16
|
"@testing-library/react": "16.3.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@oslokommune/punkt-elements": "^19.18.
|
|
20
|
-
"@oslokommune/punkt-react": "^19.18.
|
|
21
|
-
"@testing-library/jest-dom": "^
|
|
19
|
+
"@oslokommune/punkt-elements": "^19.18.2",
|
|
20
|
+
"@oslokommune/punkt-react": "^19.18.2",
|
|
21
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
22
22
|
"@types/node": "^25.9.3",
|
|
23
23
|
"@vitejs/plugin-react": "^6.0.2",
|
|
24
24
|
"jsdom": "^29.1.1",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"engines": {
|
|
66
66
|
"node": "^22.19.0 || ^24.0.0 || ^26.0.0"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "365dcae5072b21d9508448b2d541932ae7dee859"
|
|
69
69
|
}
|