@oslokommune/punkt-testing-utils 12.31.2 → 12.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { default as DomTestingLibrary } from '@testing-library/dom';
|
|
2
|
-
import { PktButton, PktBackLink, PktCheckbox, PktDatepicker, PktHelptext, PktIcon, PktInputWrapper, PktLoader, PktProgressbar, PktRadioButton, PktSelect, PktTextarea } from '@oslokommune/punkt-elements';
|
|
2
|
+
import { PktButton, PktBackLink, PktCheckbox, PktCombobox, PktDatepicker, PktHelptext, PktIcon, PktInputWrapper, PktLoader, PktProgressbar, PktRadioButton, PktSelect, PktTextarea } from '@oslokommune/punkt-elements';
|
|
3
3
|
|
|
4
4
|
export declare const PKT_CUSTOM_FORMFIELDS: string[];
|
|
5
|
-
type PTLElementType = PktBackLink | PktButton | PktCheckbox | PktDatepicker | PktHelptext | PktIcon | PktInputWrapper | PktLoader | PktProgressbar | PktRadioButton | PktSelect | PktTextarea | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
5
|
+
type PTLElementType = PktBackLink | PktButton | PktCheckbox | PktCombobox | PktDatepicker | PktHelptext | PktIcon | PktInputWrapper | PktLoader | PktProgressbar | PktRadioButton | PktSelect | PktTextarea | HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
6
6
|
export type PktTestingLibraryOptions = Pick<typeof DomTestingLibrary, 'fireEvent' | 'findAllByLabelText' | 'findAllByTestId' | 'findAllByDisplayValue' | 'findAllByText' | 'getAllByLabelText' | 'getAllByTestId' | 'getAllByDisplayValue' | 'getAllByText'>;
|
|
7
7
|
export type LabelOrElement<ElementType = PTLElementType> = string | RegExp | ElementType;
|
|
8
8
|
export type PktElementValueType = string | number | Date;
|
|
@@ -3,6 +3,7 @@ const PKT_CUSTOM_FORMFIELDS = [
|
|
|
3
3
|
"pkt-button",
|
|
4
4
|
"pkt-backlink",
|
|
5
5
|
"pkt-checkbox",
|
|
6
|
+
"pkt-combobox",
|
|
6
7
|
"pkt-datepicker",
|
|
7
8
|
"pkt-progressbar",
|
|
8
9
|
"pkt-radiobutton",
|
|
@@ -10,7 +11,14 @@ const PKT_CUSTOM_FORMFIELDS = [
|
|
|
10
11
|
"pkt-textarea",
|
|
11
12
|
"pkt-textinput"
|
|
12
13
|
];
|
|
13
|
-
const PKT_CUSTOM_ELEMENTS = [
|
|
14
|
+
const PKT_CUSTOM_ELEMENTS = [
|
|
15
|
+
"pkt-input-wrapper",
|
|
16
|
+
"pkt-icon",
|
|
17
|
+
"pkt-helptext",
|
|
18
|
+
"pkt-loader",
|
|
19
|
+
"pkt-backlink",
|
|
20
|
+
...PKT_CUSTOM_FORMFIELDS
|
|
21
|
+
];
|
|
14
22
|
const setupPktTestingLibrary = (options) => {
|
|
15
23
|
const tools = {
|
|
16
24
|
fireEvent: options.fireEvent,
|
|
@@ -124,6 +132,7 @@ function getPureLabelText(label) {
|
|
|
124
132
|
removeElementBySelector(clonedLabel, ".pkt-input-icon");
|
|
125
133
|
removeElementBySelector(clonedLabel, ".pkt-input__counter");
|
|
126
134
|
removeElementBySelector(clonedLabel, "option");
|
|
135
|
+
removeElementBySelector(clonedLabel, "pkt-listbox");
|
|
127
136
|
removeElementBySelector(clonedLabel, ".pkt-alert--error");
|
|
128
137
|
removeElementBySelector(clonedLabel, ".pkt-tag");
|
|
129
138
|
removeElementBySelector(clonedLabel, ".pkt-input-check__input-helptext");
|
|
@@ -151,7 +160,7 @@ const fallbackSearchForPktSelectByLabel = (testingLibrary) => (identifier, query
|
|
|
151
160
|
const matchingLabel = Array.from(container.querySelectorAll("label")).find(
|
|
152
161
|
(labelElement) => getPureLabelText(labelElement) === identifier
|
|
153
162
|
);
|
|
154
|
-
const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select"));
|
|
163
|
+
const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select")) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-combobox"));
|
|
155
164
|
if (!labelOwner) {
|
|
156
165
|
throw getElementError(`Fant ikke noe element med label "${identifier}"`, container);
|
|
157
166
|
}
|
|
@@ -224,9 +233,9 @@ const getAllPktElementsByLabelText = (testingLibrary) => (label, container) => {
|
|
|
224
233
|
const setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
|
|
225
234
|
async (element, valueOrValues, useInputEvent = false) => {
|
|
226
235
|
if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === "PKT-SELECT") {
|
|
227
|
-
throw new Error("Multi-verdi <pkt-select> støttes ikke");
|
|
236
|
+
throw new Error("Multi-verdi <pkt-select> støttes ikke. Bruk <pkt-combobox> i stedet.");
|
|
228
237
|
}
|
|
229
|
-
if (element.tagName === "PKT-SELECT") {
|
|
238
|
+
if (element.tagName === "PKT-SELECT" || element.tagName === "PKT-COMBOBOX") {
|
|
230
239
|
const pktSelect = element;
|
|
231
240
|
const multiple = pktSelect.multiple;
|
|
232
241
|
const valueAsArray = Array.isArray(valueOrValues) ? valueOrValues : [valueOrValues];
|
|
@@ -252,7 +261,7 @@ const setPktSelectedOptionsByLabel = (testingLibrary) => asyncFuncWithStringIden
|
|
|
252
261
|
const selectedOptions = desiredOptionLabels.map((optionLabel) => availableOptions.find(([_, label]) => label === optionLabel)).filter((possibleOption) => possibleOption);
|
|
253
262
|
if (selectedOptions.length !== desiredOptionLabels.length) {
|
|
254
263
|
throw new Error(
|
|
255
|
-
"Noen av option'ene finnes ikke i denne
|
|
264
|
+
"Noen av option'ene finnes ikke i denne komponenten. Du valgte " + JSON.stringify(desiredOptionLabels) + ", mens valgmulighetene er " + JSON.stringify(availableOptions.map(([, label]) => label))
|
|
256
265
|
);
|
|
257
266
|
}
|
|
258
267
|
return await setPktElementValue(testingLibrary)(
|
|
@@ -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 PktButton,\n PktBackLink,\n PktCheckbox,\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-button',\n 'pkt-backlink',\n 'pkt-checkbox',\n 'pkt-datepicker',\n 'pkt-progressbar',\n 'pkt-radiobutton',\n 'pkt-select',\n 'pkt-textarea',\n 'pkt-textinput',\n]\nconst PKT_CUSTOM_ELEMENTS = ['pkt-input-wrapper', 'pkt-icon', 'pkt-helptext', 'pkt-loader', ...PKT_CUSTOM_FORMFIELDS]\n\ntype PTLElementType =\n | PktBackLink\n | PktButton\n | PktCheckbox\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-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 = matchingLabel?.control || matchingLabel?.closest('pkt-select')\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 }\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 = (testingLibrary: TestingLibraryTools) => (labelOrElement: LabelOrElement) => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<PTLElementType>(labelOrElement, 'label')\n return element.querySelectorAll(':checked').length > 0\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')\n }\n if (element.tagName === 'PKT-SELECT') {\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 const returnValue = useInputEvent\n ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(returnValue)\n }\n },\n )\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType) => {\n if (element.tagName === 'PKT-RADIOBUTTON') {\n throw new Error('Klikk på <pkt-radiobutton> støttes ikke - bruk setPktElementChecked i stedet')\n }\n const returnValue = testingLibrary.fireEvent.click(element)\n return Promise.resolve(returnValue)\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 PktSelect'en. 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,CAAC,qBAAqB,YAAY,gBAAgB,cAAc,GAAG,qBAAqB;AAsEvG,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,EAAA;AAEjB,SAAA;AAAA,IACL,2BAA2B,mBAAmB,OAAO,qBAAqB;AAAA,IAC1E;AAAA,IACA,0BAA0B,mBAAmB,OAAO,oBAAoB;AAAA,IACxE,sBAAsB,mBAAmB,OAAO,oBAAoB;AAAA,IACpE,qBAAqB,mBAAmB,OAAO,mBAAmB;AAAA,IAClE,qBAAqB,mBAAmB,OAAO,mBAAmB;AAAA,IAClE,8BAA8B,mBAAmB,OAAO,4BAA4B;AAAA,IACpF,oBAAoB,mBAAmB,OAAO,kBAAkB;AAAA,IAChE,gBAAgB,mBAAmB,OAAO,cAAc;AAAA,IACxD,8BAA8B,mBAAmB,OAAO,4BAA4B;AAAA,IACpF,6BAA6B,mBAAm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W,CAAC,EACjF,OAAO,CAAC,mBAAmB,cAAc;AACxC,QAAA,gBAAgB,WAAW,oBAAoB,QAAQ;AACzD,YAAM,IAAI;AAAA,QACR,oEACE,KAAK,UAAU,mBAAmB,IAClC,+BACA,KAAK,UAAU,iBAAiB,IAAI,CAAC,CAAG,EAAA,KAAK,MAAM,KAAK,CAAC;AAAA,MAAA;AAAA,IAE/D;AAEO,WAAA,MAAM,mBAAmB,cAAc;AAAA,MAC5C;AAAA,MACA,gBAAgB,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;AAAA,IAAA;AAAA,EAE1C;AACF;"}
|
|
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 PktButton,\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-button',\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 | PktButton\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 }\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 = (testingLibrary: TestingLibraryTools) => (labelOrElement: LabelOrElement) => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<PTLElementType>(labelOrElement, 'label')\n return element.querySelectorAll(':checked').length > 0\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 const returnValue = useInputEvent\n ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(returnValue)\n }\n },\n )\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType) => {\n if (element.tagName === 'PKT-RADIOBUTTON') {\n throw new Error('Klikk på <pkt-radiobutton> støttes ikke - bruk setPktElementChecked i stedet')\n }\n const returnValue = testingLibrary.fireEvent.click(element)\n return Promise.resolve(returnValue)\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":";AA6BO,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;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;AAuEa,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,QA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 +14,14 @@
|
|
|
13
14
|
"pkt-textarea",
|
|
14
15
|
"pkt-textinput"
|
|
15
16
|
];
|
|
16
|
-
const PKT_CUSTOM_ELEMENTS = [
|
|
17
|
+
const PKT_CUSTOM_ELEMENTS = [
|
|
18
|
+
"pkt-input-wrapper",
|
|
19
|
+
"pkt-icon",
|
|
20
|
+
"pkt-helptext",
|
|
21
|
+
"pkt-loader",
|
|
22
|
+
"pkt-backlink",
|
|
23
|
+
...PKT_CUSTOM_FORMFIELDS
|
|
24
|
+
];
|
|
17
25
|
const setupPktTestingLibrary = (options) => {
|
|
18
26
|
const tools = {
|
|
19
27
|
fireEvent: options.fireEvent,
|
|
@@ -127,6 +135,7 @@
|
|
|
127
135
|
removeElementBySelector(clonedLabel, ".pkt-input-icon");
|
|
128
136
|
removeElementBySelector(clonedLabel, ".pkt-input__counter");
|
|
129
137
|
removeElementBySelector(clonedLabel, "option");
|
|
138
|
+
removeElementBySelector(clonedLabel, "pkt-listbox");
|
|
130
139
|
removeElementBySelector(clonedLabel, ".pkt-alert--error");
|
|
131
140
|
removeElementBySelector(clonedLabel, ".pkt-tag");
|
|
132
141
|
removeElementBySelector(clonedLabel, ".pkt-input-check__input-helptext");
|
|
@@ -154,7 +163,7 @@
|
|
|
154
163
|
const matchingLabel = Array.from(container.querySelectorAll("label")).find(
|
|
155
164
|
(labelElement) => getPureLabelText(labelElement) === identifier
|
|
156
165
|
);
|
|
157
|
-
const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select"));
|
|
166
|
+
const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select")) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-combobox"));
|
|
158
167
|
if (!labelOwner) {
|
|
159
168
|
throw dom.getElementError(`Fant ikke noe element med label "${identifier}"`, container);
|
|
160
169
|
}
|
|
@@ -227,9 +236,9 @@
|
|
|
227
236
|
const setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
|
|
228
237
|
async (element, valueOrValues, useInputEvent = false) => {
|
|
229
238
|
if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === "PKT-SELECT") {
|
|
230
|
-
throw new Error("Multi-verdi <pkt-select> støttes ikke");
|
|
239
|
+
throw new Error("Multi-verdi <pkt-select> støttes ikke. Bruk <pkt-combobox> i stedet.");
|
|
231
240
|
}
|
|
232
|
-
if (element.tagName === "PKT-SELECT") {
|
|
241
|
+
if (element.tagName === "PKT-SELECT" || element.tagName === "PKT-COMBOBOX") {
|
|
233
242
|
const pktSelect = element;
|
|
234
243
|
const multiple = pktSelect.multiple;
|
|
235
244
|
const valueAsArray = Array.isArray(valueOrValues) ? valueOrValues : [valueOrValues];
|
|
@@ -255,7 +264,7 @@
|
|
|
255
264
|
const selectedOptions = desiredOptionLabels.map((optionLabel) => availableOptions.find(([_, label]) => label === optionLabel)).filter((possibleOption) => possibleOption);
|
|
256
265
|
if (selectedOptions.length !== desiredOptionLabels.length) {
|
|
257
266
|
throw new Error(
|
|
258
|
-
"Noen av option'ene finnes ikke i denne
|
|
267
|
+
"Noen av option'ene finnes ikke i denne komponenten. Du valgte " + JSON.stringify(desiredOptionLabels) + ", mens valgmulighetene er " + JSON.stringify(availableOptions.map(([, label]) => label))
|
|
259
268
|
);
|
|
260
269
|
}
|
|
261
270
|
return await setPktElementValue(testingLibrary)(
|
|
@@ -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 PktButton,\n PktBackLink,\n PktCheckbox,\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-button',\n 'pkt-backlink',\n 'pkt-checkbox',\n 'pkt-datepicker',\n 'pkt-progressbar',\n 'pkt-radiobutton',\n 'pkt-select',\n 'pkt-textarea',\n 'pkt-textinput',\n]\nconst PKT_CUSTOM_ELEMENTS = ['pkt-input-wrapper', 'pkt-icon', 'pkt-helptext', 'pkt-loader', ...PKT_CUSTOM_FORMFIELDS]\n\ntype PTLElementType =\n | PktBackLink\n | PktButton\n | PktCheckbox\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-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 = matchingLabel?.control || matchingLabel?.closest('pkt-select')\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 }\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 = (testingLibrary: TestingLibraryTools) => (labelOrElement: LabelOrElement) => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<PTLElementType>(labelOrElement, 'label')\n return element.querySelectorAll(':checked').length > 0\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')\n }\n if (element.tagName === 'PKT-SELECT') {\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 const returnValue = useInputEvent\n ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(returnValue)\n }\n },\n )\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType) => {\n if (element.tagName === 'PKT-RADIOBUTTON') {\n throw new Error('Klikk på <pkt-radiobutton> støttes ikke - bruk setPktElementChecked i stedet')\n }\n const returnValue = testingLibrary.fireEvent.click(element)\n return Promise.resolve(returnValue)\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 PktSelect'en. 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;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U,iBAAiB,IAAI,CAAC,CAAG,EAAA,KAAK,MAAM,KAAK,CAAC;AAAA,QAAA;AAAA,MAE/D;AAEO,aAAA,MAAM,mBAAmB,cAAc;AAAA,QAC5C;AAAA,QACA,gBAAgB,IAAI,CAAC,CAAC,KAAK,MAAM,KAAK;AAAA,MAAA;AAAA,IAE1C;AAAA,EACF;;;;;"}
|
|
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 PktButton,\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-button',\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 | PktButton\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 }\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 = (testingLibrary: TestingLibraryTools) => (labelOrElement: LabelOrElement) => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<PTLElementType>(labelOrElement, 'label')\n return element.querySelectorAll(':checked').length > 0\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 const returnValue = useInputEvent\n ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(returnValue)\n }\n },\n )\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PTLElementType) => {\n if (element.tagName === 'PKT-RADIOBUTTON') {\n throw new Error('Klikk på <pkt-radiobutton> støttes ikke - bruk setPktElementChecked i stedet')\n }\n const returnValue = testingLibrary.fireEvent.click(element)\n return Promise.resolve(returnValue)\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":";;;;AA6BO,QAAM,wBAAwB;AAAA,IACnC;AAAA,IACA;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;AAuEa,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,IAAA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
"homepage": "https://punkt.oslo.kommune.no",
|
|
6
6
|
"author": "Team Designsystem, Oslo Origo",
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"element-internals-polyfill": "^1.3.10"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@oslokommune/punkt-elements": "^12.
|
|
21
|
-
"@oslokommune/punkt-react": "^12.
|
|
20
|
+
"@oslokommune/punkt-elements": "^12.32.0",
|
|
21
|
+
"@oslokommune/punkt-react": "^12.32.0",
|
|
22
22
|
"@testing-library/jest-dom": "^6.1.0",
|
|
23
23
|
"@types/jest": "^29.5.0",
|
|
24
24
|
"@types/testing-library__jest-dom": "^5.14.9",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"url": "https://github.com/oslokommune/punkt/issues"
|
|
66
66
|
},
|
|
67
67
|
"license": "MIT",
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "8d17b2b21d83b498b237d837747e753c64570285"
|
|
69
69
|
}
|