@oslokommune/punkt-testing-utils 13.2.0 → 13.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,11 @@ export type PktTestingLibrary = {
|
|
|
13
13
|
getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[];
|
|
14
14
|
setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>;
|
|
15
15
|
isPktElementChecked: (labelOrElement: LabelOrElement) => boolean;
|
|
16
|
-
setPktElementValue: (labelOrElement: LabelOrElement, valueOrValues: PktElementValueType | Array<PktElementValueType>,
|
|
16
|
+
setPktElementValue: (labelOrElement: LabelOrElement, valueOrValues: PktElementValueType | Array<PktElementValueType>, optionsOrUseInputEvent?: boolean | {
|
|
17
|
+
useInputEventForNative?: boolean;
|
|
18
|
+
useChangeEventForNative?: boolean;
|
|
19
|
+
setValuePropForNative?: boolean;
|
|
20
|
+
}) => Promise<boolean>;
|
|
17
21
|
pktClickButton: (labelOrElement: LabelOrElement<HTMLInputElement | HTMLButtonElement>) => Promise<boolean>;
|
|
18
22
|
waitForPktElementsToBeDefined: () => Promise<any>;
|
|
19
23
|
setPktSelectedOptionsByLabel: (labelOrElement: LabelOrElement<PktSelect>, ...desiredOptionLabels: Array<string>) => Promise<any>;
|
|
@@ -233,7 +233,19 @@ const getAllPktElementsByLabelText = (testingLibrary) => (label, container) => {
|
|
|
233
233
|
return innerElements.map((element) => findPossibleWrappingPktCustomElement()(element, false, []));
|
|
234
234
|
};
|
|
235
235
|
const setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
|
|
236
|
-
async (element, valueOrValues,
|
|
236
|
+
async (element, valueOrValues, optionsOrUseInputEvent = false) => {
|
|
237
|
+
const options = typeof optionsOrUseInputEvent === "object" ? optionsOrUseInputEvent : (
|
|
238
|
+
// Hvis det er en boolean, så vær bakoverkompatibel
|
|
239
|
+
optionsOrUseInputEvent && {
|
|
240
|
+
useInputEventForNative: true,
|
|
241
|
+
useChangeEventForNative: true,
|
|
242
|
+
setValuePropForNative: true
|
|
243
|
+
} || {
|
|
244
|
+
useInputEventForNative: false,
|
|
245
|
+
useChangeEventForNative: true,
|
|
246
|
+
setValuePropForNative: false
|
|
247
|
+
}
|
|
248
|
+
);
|
|
237
249
|
if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === "PKT-SELECT") {
|
|
238
250
|
throw new Error("Multi-verdi <pkt-select> støttes ikke. Bruk <pkt-combobox> i stedet.");
|
|
239
251
|
}
|
|
@@ -245,11 +257,17 @@ const setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrEl
|
|
|
245
257
|
testingLibrary.fireEvent.change(element, { target: { value: newValue } });
|
|
246
258
|
return Promise.resolve(true);
|
|
247
259
|
} else {
|
|
248
|
-
if (
|
|
249
|
-
|
|
260
|
+
if (options.setValuePropForNative) {
|
|
261
|
+
if ("value" in element) {
|
|
262
|
+
element.value = valueOrValues.toString();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (options.useInputEventForNative) {
|
|
266
|
+
testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } });
|
|
267
|
+
}
|
|
268
|
+
if (options.useChangeEventForNative) {
|
|
269
|
+
testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
|
|
250
270
|
}
|
|
251
|
-
testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } });
|
|
252
|
-
testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
|
|
253
271
|
return Promise.resolve(true);
|
|
254
272
|
}
|
|
255
273
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"punkt-testing-utils.es.js","sources":["../src/index.ts"],"sourcesContent":["import DomTestingLibrary, {\n FindAllByBoundAttribute,\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByTestId,\n findAllByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByTestId,\n getAllByText,\n getElementError,\n} from '@testing-library/dom'\nimport {\n 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-datepicker',\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\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, 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 useInputEvent?: boolean,\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 asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | HTMLElement, query: QueryTypes) =>\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,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n) => {\n return 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,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n try {\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, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp, container?: HTMLElement): Promise<PTLElementType> =>\n findPktElementBy(testingLibrary)('label', label, container)\n\nconst getPktElementByText = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('text', text, container)\n\nconst findPktElementByText =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('text', text, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(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 useInputEvent = false,\n ): Promise<boolean> => {\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 ('value' in element) {\n element.value = valueOrValues.toString()\n }\n\n testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\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 if (element.tagName === 'LABEL') {\n const label = element as HTMLLabelElement\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"],"names":[],"mappings":";AA4BO,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL;AAsEa,MAAA,yBAAmF,CAC9F,YACG;AACH,QAAM,QAA6B;AAAA,IACjC,WAAW,QAAQ;AAAA,IACnB,oBAAoB,QAAQ;AAAA,IAC5B,uBAAuB,QAAQ;AAAA,IAC/B,iBAAiB,QAAQ;AAAA,IACzB,eAAe,QAAQ;AAAA,IACvB,mBAAmB,QAAQ;AAAA,IAC3B,sBAAsB,QAAQ;AAAA,IAC9B,gBAAgB,QAAQ;AAAA,IACxB,cAAc,QAAQ;AAAA,EACxB;AACO,SAAA;AAAA,IACL,2BAA2B,mBAAmB,OAAO,qBAAqB;AAAA,IAC1E;AAAA,IACA,0BAA0B,mBAAmB,OAAO,oBAAoB;AAAA,IACxE,sBAAsB,mB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;"}
|
|
1
|
+
{"version":3,"file":"punkt-testing-utils.es.js","sources":["../src/index.ts"],"sourcesContent":["import DomTestingLibrary, {\n FindAllByBoundAttribute,\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByTestId,\n findAllByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByTestId,\n getAllByText,\n getElementError,\n} from '@testing-library/dom'\nimport {\n 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-datepicker',\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\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, 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 asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | HTMLElement, query: QueryTypes) =>\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,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n) => {\n return 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,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n try {\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, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp, container?: HTMLElement): Promise<PTLElementType> =>\n findPktElementBy(testingLibrary)('label', label, container)\n\nconst getPktElementByText = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('text', text, container)\n\nconst findPktElementByText =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('text', text, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(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 if (element.tagName === 'LABEL') {\n const label = element as HTMLLabelElement\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"],"names":[],"mappings":";AA4BO,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;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ACR,UAAA,UAAU,MAAM,YAAY,MAAM,UAAU,SAAS,eAAe,MAAM,OAAO,IAAI;AAC3F,WAAO,CAAC,EAAE,WAAY,QAA6B,SAAS;AAAA,EAAA;AAGvD,SAAA;AACT;AAEA,MAAM,iBAAiB,CAAC,mBACtB,uCAAuC,cAAc,EAAE,OAAO,YAA4B;AACpF,MAAA,mBAAmB,OAAO,GAAG;AACzB,UAAA,IAAI,MAAM,8EAA8E;AAAA,EAAA;AAEzF,SAAA,eAAe,UAAU,MAAM,OAAO;AAC/C,GAAG,MAAM;AAEX,MAAM,+BAA+B,CAAC,mBACpC,uCAAuC,cAAc;AAAA,EACnD,OAAO,cAAyB,wBAAuC;AACrE,UAAM,mBAAmB,oBAAoB,cAAc,EAAE,SAAS;AACtE,UAAM,kBAAkB,oBACrB,IAAI,CAAC,gBAAgB,iBAAiB,KAAK,CAAC,CAAC,GAAG,KAAK,MAAM,UAAU,WAAW,CAAC,EACjF,OAAO,CAAC,mBAAmB,cAAc;AACxC,QAAA,gBAAgB,WAAW,oBAAoB,QAAQ;AACzD,YAAM,IAAI;AAAA,QACR,mEACE,KAAK,UAAU,mBAAmB,IAClC,+BACA,KAAK,UAAU,iBAAiB,IAAI,CAAC,CAAA,EAAG,KAAK,MAAM,KAAK,CAAC;AAAA,MAC7D;AAAA,IAAA;AAGK,WAAA,MAAM,mBAAmB,cAAc;AAAA,MAC5C;AAAA,MACA,gBAAgB,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;AAAA,IACxC;AAAA,EAAA;AAEJ;"}
|
|
@@ -236,7 +236,19 @@
|
|
|
236
236
|
return innerElements.map((element) => findPossibleWrappingPktCustomElement()(element, false, []));
|
|
237
237
|
};
|
|
238
238
|
const setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
|
|
239
|
-
async (element, valueOrValues,
|
|
239
|
+
async (element, valueOrValues, optionsOrUseInputEvent = false) => {
|
|
240
|
+
const options = typeof optionsOrUseInputEvent === "object" ? optionsOrUseInputEvent : (
|
|
241
|
+
// Hvis det er en boolean, så vær bakoverkompatibel
|
|
242
|
+
optionsOrUseInputEvent && {
|
|
243
|
+
useInputEventForNative: true,
|
|
244
|
+
useChangeEventForNative: true,
|
|
245
|
+
setValuePropForNative: true
|
|
246
|
+
} || {
|
|
247
|
+
useInputEventForNative: false,
|
|
248
|
+
useChangeEventForNative: true,
|
|
249
|
+
setValuePropForNative: false
|
|
250
|
+
}
|
|
251
|
+
);
|
|
240
252
|
if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === "PKT-SELECT") {
|
|
241
253
|
throw new Error("Multi-verdi <pkt-select> støttes ikke. Bruk <pkt-combobox> i stedet.");
|
|
242
254
|
}
|
|
@@ -248,11 +260,17 @@
|
|
|
248
260
|
testingLibrary.fireEvent.change(element, { target: { value: newValue } });
|
|
249
261
|
return Promise.resolve(true);
|
|
250
262
|
} else {
|
|
251
|
-
if (
|
|
252
|
-
|
|
263
|
+
if (options.setValuePropForNative) {
|
|
264
|
+
if ("value" in element) {
|
|
265
|
+
element.value = valueOrValues.toString();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (options.useInputEventForNative) {
|
|
269
|
+
testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } });
|
|
270
|
+
}
|
|
271
|
+
if (options.useChangeEventForNative) {
|
|
272
|
+
testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
|
|
253
273
|
}
|
|
254
|
-
testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } });
|
|
255
|
-
testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
|
|
256
274
|
return Promise.resolve(true);
|
|
257
275
|
}
|
|
258
276
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"punkt-testing-utils.umd.js","sources":["../src/index.ts"],"sourcesContent":["import DomTestingLibrary, {\n FindAllByBoundAttribute,\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByTestId,\n findAllByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByTestId,\n getAllByText,\n getElementError,\n} from '@testing-library/dom'\nimport {\n 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-datepicker',\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\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, 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 useInputEvent?: boolean,\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 asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | HTMLElement, query: QueryTypes) =>\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,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n) => {\n return 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,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n try {\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, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp, container?: HTMLElement): Promise<PTLElementType> =>\n findPktElementBy(testingLibrary)('label', label, container)\n\nconst getPktElementByText = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('text', text, container)\n\nconst findPktElementByText =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('text', text, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(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 useInputEvent = false,\n ): Promise<boolean> => {\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 ('value' in element) {\n element.value = valueOrValues.toString()\n }\n\n testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\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 if (element.tagName === 'LABEL') {\n const label = element as HTMLLabelElement\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"],"names":["getElementError"],"mappings":";;;;AA4BO,QAAM,wBAAwB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,sBAAsB;AAAA,IAC1B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AAsEa,QAAA,yBAAmF,CAC9F,YACG;AACH,UAAM,QAA6B;AAAA,MACjC,WAAW,QAAQ;AAAA,MACnB,oBAAoB,QAAQ;AAAA,MAC5B,uBAAuB,QAAQ;AAAA,MAC/B,iBAAiB,QAAQ;AAAA,MACzB,eAAe,QAAQ;AAAA,MACvB,mBAAmB,QAAQ;AAAA,MAC3B,sBAAsB,QAAQ;AAAA,MAC9B,gBAAgB,QAAQ;AAAA,MACxB,cAAc,QAAQ;AAAA,IACxB;AACO,WAAA;AAAA,MACL,2BAA2B,mBAAmB,OAAO,qBAAqB;AAAA,MAC1E;AAAA,MACA,0BAA0B,mB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C,CAAA,EAAG,KAAK,MAAM,KAAK,CAAC;AAAA,QAC7D;AAAA,MAAA;AAGK,aAAA,MAAM,mBAAmB,cAAc;AAAA,QAC5C;AAAA,QACA,gBAAgB,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;AAAA,MACxC;AAAA,IAAA;AAAA,EAEJ;;;;;"}
|
|
1
|
+
{"version":3,"file":"punkt-testing-utils.umd.js","sources":["../src/index.ts"],"sourcesContent":["import DomTestingLibrary, {\n FindAllByBoundAttribute,\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByTestId,\n findAllByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByTestId,\n getAllByText,\n getElementError,\n} from '@testing-library/dom'\nimport {\n 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-datepicker',\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\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, 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 asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | HTMLElement, query: QueryTypes) =>\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,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n) => {\n return 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,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n try {\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, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp, container?: HTMLElement): Promise<PTLElementType> =>\n findPktElementBy(testingLibrary)('label', label, container)\n\nconst getPktElementByText = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('text', text, container)\n\nconst findPktElementByText =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('text', text, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(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 if (element.tagName === 'LABEL') {\n const label = element as HTMLLabelElement\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"],"names":["getElementError"],"mappings":";;;;AA4BO,QAAM,wBAAwB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,sBAAsB;AAAA,IAC1B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL;AA4Ea,QAAA,yBAAmF,CAC9F,YACG;AACH,UAAM,QAA6B;AAAA,MACjC,WAAW,QAAQ;AAAA,MACnB,oBAAoB,QAAQ;AAAA,MAC5B,uBAAuB,QAAQ;AAAA,MAC/B,iBAAiB,QAAQ;AAAA,MACzB,eAAe,QAAQ;AAAA,MACvB,mBAAmB,QAAQ;AAAA,MAC3B,sBAAsB,QAAQ;AAAA,MAC9B,gBAAgB,QAAQ;AAAA,MACxB,cAAc,QAAQ;AAAA,IACxB;AACO,WAAA;AAAA,MACL,2BAA2B,mBAAmB,OAAO,qBAAqB;AAAA,MAC1E;AAAA,MACA,0BAA0B,mBAAmB,OAAO,oBAAoB;AAAA,MACxE,sBAAsB,mBAAmB,OAAO,oBAAoB;AAAA,MACpE,qBAAqB,mBAAmB,OAAO,mBAAmB;AAAA,MAClE,qBAAqB,mBAAmB,OAAO,mBAAmB;AAAA,MAClE,8BAA8B,mBAAmB,OAAO,4BAA4B;AAAA,MACpF,oBAAoB,mBAAmB,OAAO,kBAAkB;AAAA,MAChE,gBAAgB,mBAAmB,OAAO,cAAc;AAAA,MACxD,8BAA8B,mBAAmB,OAAO,4BAA4B;AAAA,MACpF,6BAA6B,mBAAmB,OAAO,2BAA2B;AAAA,MAClF,8BAA8B,mBAAmB,OAAO,4BAA4B;AAAA,IACtF;AAAA,EACF;AAYA,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;AAAA,QAC5C;AAAA,QACA,gBAAgB,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;AAAA,MACxC;AAAA,IAAA;AAAA,EAEJ;;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oslokommune/punkt-testing-utils",
|
|
3
|
-
"version": "13.2.
|
|
3
|
+
"version": "13.2.1",
|
|
4
4
|
"description": "Test-utilities for Punkt",
|
|
5
5
|
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
67
67
|
},
|
|
68
68
|
"license": "MIT",
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "8644dd757c4d3adb7735e42089f33366629730bf"
|
|
70
70
|
}
|