@oslokommune/punkt-testing-utils 12.24.4 → 12.26.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
@@ -9,12 +9,15 @@ export type PktElementValueType = string | number | Date;
9
9
  export type PktTestingLibrary = {
10
10
  findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>;
11
11
  getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType;
12
- getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>) => Array<PktOption>;
12
+ getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, onlySelected?: boolean) => Array<PktOption>;
13
13
  getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[];
14
14
  setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>;
15
15
  setPktElementValue: (labelOrElement: LabelOrElement, valueOrValues: PktElementValueType | Array<PktElementValueType>, useInputEvent?: boolean) => Promise<boolean>;
16
- pktClickButton: (labelOrElement: LabelOrElement<PktRadioButton>) => Promise<boolean>;
16
+ pktClickButton: (labelOrElement: LabelOrElement<PktRadioButton | HTMLInputElement | HTMLButtonElement>) => Promise<boolean>;
17
17
  waitForPktElementsToBeDefined: () => Promise<any>;
18
+ setPktSelectedOptionsByLabel: (labelOrElement: LabelOrElement<PktSelect>, ...desiredOptionLabels: Array<string>) => Promise<any>;
19
+ getPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => PTLElementType;
20
+ findPktElementByDisplayValue: (labelOrElement: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>;
18
21
  };
19
22
  export declare const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary;
20
23
  /**
@@ -24,5 +27,5 @@ export declare const setupPktTestingLibrary: (options: PktTestingLibraryOptions)
24
27
  * @property {string | null} 1 - Tekstinnholdet, <option>tekstinnhold</option>
25
28
  * @property {boolean} 2 - Om denne er valgt (selected)
26
29
  */
27
- export type PktOption = [string, string | null, boolean];
30
+ export type PktOption = [string, string | undefined, boolean];
28
31
  export {};
@@ -27,7 +27,10 @@ const setupPktTestingLibrary = (options) => {
27
27
  getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),
28
28
  getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),
29
29
  setPktElementValue: withTestingLibrary(tools, setPktElementValue),
30
- pktClickButton: withTestingLibrary(tools, pktClickButton)
30
+ pktClickButton: withTestingLibrary(tools, pktClickButton),
31
+ setPktSelectedOptionsByLabel: withTestingLibrary(tools, setPktSelectedOptionsByLabel),
32
+ getPktElementByDisplayValue: withTestingLibrary(tools, getPktElementByDisplayValue),
33
+ findPktElementByDisplayValue: withTestingLibrary(tools, findPktElementByDisplayValue)
31
34
  };
32
35
  };
33
36
  const syncQueryFunctionResolver = (testingLibrary) => (queryType) => {
@@ -80,7 +83,7 @@ const waitForPktElementsToBeDefined = async () => await Promise.all(
80
83
  }
81
84
  }).filter((promise) => promise)
82
85
  );
83
- const findPossibleWrappingPktCustomElement = (innerElement, isByRole, args) => {
86
+ const findPossibleWrappingPktCustomElement = (testingLibrary) => (innerElement, isByRole, args) => {
84
87
  if (!innerElement === null) {
85
88
  throw getElementError(`Finner ikke noe element med ${isByRole ? "role" : "label"} "${args[0]}"`, document.body);
86
89
  }
@@ -92,9 +95,13 @@ const findPossibleWrappingPktCustomElement = (innerElement, isByRole, args) => {
92
95
  }
93
96
  };
94
97
  const getPktElementBy = (testingLibrary) => (query = "label", identifier, container) => {
95
- const queryFunc = syncQueryFunctionResolver(testingLibrary)(query);
96
- const innerElement = doElementSearch(identifier, query, queryFunc, container)[0];
97
- return findPossibleWrappingPktCustomElement(innerElement, false, []);
98
+ try {
99
+ const queryFunc = syncQueryFunctionResolver(testingLibrary)(query);
100
+ const innerElement = doElementSearch(identifier, query, queryFunc, container)[0];
101
+ return findPossibleWrappingPktCustomElement(testingLibrary)(innerElement, false, []);
102
+ } catch (e) {
103
+ return fallbackSearchForPktSelectByLabel()(identifier, query, container);
104
+ }
98
105
  };
99
106
  const removeElementBySelector = (ancestor, selector) => {
100
107
  const elements = Array.from(ancestor.querySelectorAll(selector));
@@ -110,11 +117,13 @@ function getPureLabelText(label) {
110
117
  removeElementBySelector(clonedLabel, ".pkt-input-suffix");
111
118
  removeElementBySelector(clonedLabel, ".pkt-input-prefix");
112
119
  removeElementBySelector(clonedLabel, ".pkt-input-icon");
120
+ removeElementBySelector(clonedLabel, ".pkt-input__counter");
113
121
  removeElementBySelector(clonedLabel, "option");
122
+ removeElementBySelector(clonedLabel, ".pkt-alert--error");
114
123
  return ((_a = clonedLabel.textContent) == null ? void 0 : _a.trim()) || null;
115
124
  }
116
125
  const getPureLabelTextForLabelOwner = (labelOwner) => {
117
- const label = "labels" in labelOwner && labelOwner.labels instanceof NodeList && labelOwner.labels.length > 0 && labelOwner.labels[0] || labelOwner.querySelector("label");
126
+ const label = "labels" in labelOwner && labelOwner.labels instanceof NodeList && labelOwner.labels.length > 0 && labelOwner.labels[0] || ["input", ...PKT_CUSTOM_FORMFIELDS].includes(labelOwner.tagName.toLowerCase()) && labelOwner.querySelector("label") || null;
118
127
  if (label) {
119
128
  return getPureLabelText(label);
120
129
  } else {
@@ -129,28 +138,30 @@ const labelMatcher = (labelTextToMatch) => (nodeContent, element) => {
129
138
  return false;
130
139
  }
131
140
  };
132
- const doElementSearch = (identifier, query, queryFunc, container = document.body) => {
133
- try {
134
- return typeof identifier === "string" && query === "label" ? queryFunc(container, labelMatcher(identifier.trim())) : queryFunc(container, identifier);
135
- } catch (e) {
136
- if (typeof identifier === "string" && query === "label") {
137
- const matchingLabel = Array.from(document.body.querySelectorAll("label")).find(
138
- (labelElement) => getPureLabelText(labelElement) === identifier
139
- );
140
- const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select"));
141
- if (labelOwner) {
142
- return [labelOwner];
143
- } else {
144
- throw getElementError(`Fant ikke noe element med ${query} "${identifier}"`, document.body);
145
- }
141
+ const fallbackSearchForPktSelectByLabel = (testingLibrary) => (identifier, query, container = document.body) => {
142
+ if (typeof identifier === "string" && query === "label") {
143
+ const matchingLabel = Array.from(container.querySelectorAll("label")).find(
144
+ (labelElement) => getPureLabelText(labelElement) === identifier
145
+ );
146
+ const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select"));
147
+ if (!labelOwner) {
148
+ throw getElementError(`Fant ikke noe element med label "${identifier}"`, container);
146
149
  }
147
- throw getElementError(`Fant ikke noe element med ${query} "${identifier}"`, document.body);
150
+ return labelOwner;
148
151
  }
152
+ throw getElementError(`Fant ikke noe element med ${query} "${identifier}"`, container);
153
+ };
154
+ const doElementSearch = (identifier, query, queryFunc, container = document.body) => {
155
+ return typeof identifier === "string" && query === "label" ? queryFunc(container, labelMatcher(identifier.trim())) : queryFunc(container, identifier);
149
156
  };
150
157
  const findPktElementBy = (testingLibrary) => async (query = "label", identifier, container) => {
151
- const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query);
152
- const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0];
153
- return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []));
158
+ try {
159
+ const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query);
160
+ const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0];
161
+ return Promise.resolve(findPossibleWrappingPktCustomElement(testingLibrary)(innerElement, false, []));
162
+ } catch (e) {
163
+ return fallbackSearchForPktSelectByLabel()(identifier, query, container);
164
+ }
154
165
  };
155
166
  const getPktElementByLabel = (testingLibrary) => (label, container) => getPktElementBy(testingLibrary)("label", label, container);
156
167
  const findPktElementByLabel = (testingLibrary) => async (label, container) => findPktElementBy(testingLibrary)("label", label, container);
@@ -161,32 +172,38 @@ const setPktElementChecked = (testingLibrary) => asyncFuncWithStringIdentifierOr
161
172
  const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } });
162
173
  return Promise.resolve(returnValue);
163
174
  });
175
+ const getPktElementByDisplayValue = (testingLibrary) => (text, container) => getPktElementBy(testingLibrary)("displayValue", text, container);
176
+ const findPktElementByDisplayValue = (testingLibrary) => (text, container) => findPktElementBy(testingLibrary)("displayValue", text, container);
164
177
  const getPktSelectOptions = (testingLibrary) => syncFuncWithStringIdentifierOrElement(testingLibrary)(
165
- (selectElement) => {
178
+ (selectElement, onlySelected) => {
166
179
  const optionElements = Array.from(
167
- selectElement.querySelectorAll(
168
- ":scope > option, :scope > optgroup > option, :scope > data, :scope > optgroup > data"
169
- )
180
+ selectElement.querySelectorAll("option:not(.pkt-hide), data:not(.pkt.hide)")
170
181
  );
182
+ const filter = onlySelected ? ([, , selected]) => selected : (_) => true;
171
183
  const currentValue = selectElement.value;
172
- return optionElements.map((optionElement) => [
173
- optionElement.value,
174
- optionElement.textContent,
175
- optionElement.value === currentValue
176
- ]);
184
+ return optionElements.map(
185
+ (optionElement) => {
186
+ var _a;
187
+ return [optionElement.value, (_a = optionElement.textContent) == null ? void 0 : _a.trim(), optionElement.value === currentValue];
188
+ }
189
+ ).filter(filter);
177
190
  }
178
191
  );
179
192
  const getAllPktElementsByLabelText = (testingLibrary) => (label, container) => {
180
193
  const innerElements = testingLibrary.getAllByLabelText(container || document.body, label);
181
- return innerElements.map((element) => findPossibleWrappingPktCustomElement(element, false, []));
194
+ return innerElements.map((element) => findPossibleWrappingPktCustomElement()(element, false, []));
182
195
  };
183
196
  const setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
184
197
  async (element, valueOrValues, useInputEvent = false) => {
185
- if (Array.isArray(valueOrValues) && !(element.tagName === "PKT-SELECT" && "multiple" in element && element.multiple)) {
186
- throw new Error("Only a multi-select PktSelect can have multiple values");
198
+ if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === "PKT-SELECT") {
199
+ throw new Error("Multi-verdi <pkt-select> støttes ikke");
187
200
  }
188
201
  if (element.tagName === "PKT-SELECT") {
189
- testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
202
+ const pktSelect = element;
203
+ const multiple = pktSelect.multiple;
204
+ const valueAsArray = Array.isArray(valueOrValues) ? valueOrValues : [valueOrValues];
205
+ const newValue = multiple && valueAsArray || valueAsArray.length == 0 && "" || valueAsArray[0];
206
+ testingLibrary.fireEvent.change(element, { target: { value: newValue } });
190
207
  return Promise.resolve(true);
191
208
  } else {
192
209
  const returnValue = useInputEvent ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } }) : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
@@ -198,6 +215,21 @@ const pktClickButton = (testingLibrary) => asyncFuncWithStringIdentifierOrElemen
198
215
  const returnValue = testingLibrary.fireEvent.click(element);
199
216
  return Promise.resolve(returnValue);
200
217
  }, "text");
218
+ const setPktSelectedOptionsByLabel = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
219
+ async (pktSelect, ...desiredOptionLabels) => {
220
+ const availableOptions = getPktSelectOptions(testingLibrary)(pktSelect);
221
+ const selectedOptions = desiredOptionLabels.map((optionLabel) => availableOptions.find(([_, label]) => label === optionLabel)).filter((possibleOption) => possibleOption);
222
+ if (selectedOptions.length !== desiredOptionLabels.length) {
223
+ throw new Error(
224
+ "Noen av option'ene finnes ikke i denne PktSelect'en. Du valgte " + JSON.stringify(desiredOptionLabels) + ", mens valgmulighetene er " + JSON.stringify(availableOptions.map(([, label]) => label))
225
+ );
226
+ }
227
+ return await setPktElementValue(testingLibrary)(
228
+ pktSelect,
229
+ selectedOptions.map(([value]) => value)
230
+ );
231
+ }
232
+ );
201
233
  export {
202
234
  PKT_CUSTOM_FORMFIELDS,
203
235
  setupPktTestingLibrary
@@ -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 PktDatepicker,\n PktInputWrapper,\n PktProgressbar,\n PktRadioButton,\n PktSelect,\n PktTextarea,\n} from '@oslokommune/punkt-elements'\nimport { AllByBoundAttribute } from '@testing-library/dom/types/queries'\n\nexport const PKT_CUSTOM_FORMFIELDS = [\n 'pkt-datepicker',\n 'pkt-progressbar',\n 'pkt-textarea',\n 'pkt-textinput',\n 'pkt-select',\n]\nconst PKT_CUSTOM_ELEMENTS = ['pkt-input-wrapper', ...PKT_CUSTOM_FORMFIELDS]\n\ntype PTLElementType =\n | PktDatepicker\n | PktProgressbar\n | PktTextarea\n | PktInputWrapper\n | PktSelect\n | PktRadioButton\n | HTMLInputElement\n | HTMLSelectElement\n | HTMLTextAreaElement\n\nexport type PktTestingLibraryOptions = Pick<\n typeof DomTestingLibrary,\n | 'fireEvent'\n | 'findAllByLabelText'\n | 'findAllByTestId'\n | 'findAllByDisplayValue'\n | 'findAllByText'\n | 'getAllByLabelText'\n | 'getAllByTestId'\n | 'getAllByDisplayValue'\n | 'getAllByText'\n>\n\ntype TestingLibraryTools = {\n fireEvent: typeof DomTestingLibrary.fireEvent\n findAllByLabelText: typeof DomTestingLibrary.findAllByLabelText\n findAllByTestId: typeof DomTestingLibrary.findAllByTestId\n findAllByDisplayValue: typeof DomTestingLibrary.findAllByDisplayValue\n findAllByText: typeof DomTestingLibrary.findAllByText\n getAllByLabelText: typeof DomTestingLibrary.getAllByLabelText\n getAllByTestId: typeof DomTestingLibrary.getAllByTestId\n getAllByDisplayValue: typeof DomTestingLibrary.getAllByDisplayValue\n getAllByText: typeof DomTestingLibrary.getAllByText\n}\n\nexport type LabelOrElement<ElementType = PTLElementType> = string | RegExp | ElementType\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent?: boolean,\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<PktRadioButton>) => Promise<boolean>\n waitForPktElementsToBeDefined: () => Promise<any>\n}\n\nexport const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary = (\n options: PktTestingLibraryOptions,\n) => {\n const tools: PktTestingLibraryOptions = {\n fireEvent: options.fireEvent,\n findAllByLabelText: options.findAllByLabelText,\n findAllByDisplayValue: options.findAllByDisplayValue,\n findAllByTestId: options.findAllByTestId,\n findAllByText: options.findAllByText,\n getAllByLabelText: options.getAllByLabelText,\n getAllByDisplayValue: options.getAllByDisplayValue,\n getAllByTestId: options.getAllByTestId,\n getAllByText: options.getAllByText,\n }\n return {\n findPktElementByLabelText: withTestingLibrary(tools, findPktElementByLabel),\n waitForPktElementsToBeDefined,\n getPktElementByLabelText: withTestingLibrary(tools, getPktElementByLabel),\n setPktElementChecked: withTestingLibrary(tools, setPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n }\n}\n\ntype SyncQueries = typeof getAllByText | typeof getAllByLabelText | typeof getAllByTestId | typeof getAllByDisplayValue\ntype AsyncQueries =\n | FindAllByBoundAttribute\n | typeof findAllByText\n | typeof findAllByLabelText\n | typeof findAllByTestId\n | typeof findAllByDisplayValue\n\ntype QueryTypes = 'label' | 'text' | 'displayValue' | 'testid'\n\nconst syncQueryFunctionResolver =\n (testingLibrary: TestingLibraryTools) =>\n (queryType: QueryTypes): SyncQueries => {\n const queries: Record<QueryTypes, SyncQueries> = {\n text: testingLibrary.getAllByText,\n label: testingLibrary.getAllByLabelText,\n testid: testingLibrary.getAllByTestId,\n displayValue: testingLibrary.getAllByDisplayValue,\n }\n const query = queries[queryType]\n if (query) {\n return query\n } else {\n throw new Error('Unsupported query type: ' + queryType)\n }\n }\n\nconst asyncQueryFunctionResolver =\n (testingLibrary: TestingLibraryTools) =>\n (queryType: QueryTypes): AsyncQueries => {\n const queries: Record<QueryTypes, AsyncQueries> = {\n text: testingLibrary.findAllByText,\n label: testingLibrary.findAllByLabelText,\n testid: testingLibrary.findAllByTestId,\n displayValue: testingLibrary.findAllByDisplayValue,\n }\n const query = queries[queryType]\n if (query) {\n return query\n } else {\n throw new Error('Unsupported query type: ' + queryType)\n }\n }\n\nconst syncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType>(elementOrIdentifier: string | RegExp | ElementType, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? (getPktElementBy(testingLibrary)(query, elementOrIdentifier) as ElementType)\n : elementOrIdentifier\n\nconst asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | ElementType, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? ((await findPktElementBy(testingLibrary)(query, elementOrIdentifier)) as ElementType)\n : elementOrIdentifier\n\nconst asyncFuncWithStringIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType, ResultType>(\n func: (element: ElementType, ...restArgs: Array<any>) => Promise<ResultType>,\n query: QueryTypes = 'label',\n ) => {\n return async (labelOrPktElement: string | RegExp | ElementType, ...restArgs: Array<any>) => {\n const element = await asyncResolveIdentifierOrElement(testingLibrary)<ElementType>(labelOrPktElement, query)\n return await func(element, ...restArgs)\n }\n }\n\nconst syncFuncWithStringIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType, ResultType>(\n func: (element: ElementType, ...restArgs: Array<any>) => ResultType,\n query: QueryTypes = 'label',\n ) => {\n return (labelOrPktElement: string | RegExp | ElementType, ...restArgs: Array<any>) => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<ElementType>(labelOrPktElement, query)\n return func(element, ...restArgs)\n }\n }\n\nconst withTestingLibrary = <F>(testingLibrary: TestingLibraryTools, fn: (testingLibrary: TestingLibraryTools) => F) =>\n fn(testingLibrary)\n\n/**\n * Sørger for at alle brukte custom elements fra Punkt er definerte og erstattet med implementasjoner.\n * Bør kalles etter `render`, før noen operasjoner og antakelser gjøres.\n *\n * F.eks.:\n * <code>\n * render(<div><PktTextinput id=\"textinput\" name={'textInput'} label=\"My text input\" aria-label=\"My text input\" /></div>);\n * await waitForPktElementsToBeDefined();\n *\n * await setPktElementValue(\"My text input\", \"new value\");\n * </code>\n */\nconst waitForPktElementsToBeDefined = async () =>\n await Promise.all(\n PKT_CUSTOM_ELEMENTS.map((elementName) => {\n if (document.querySelector(elementName) !== null) {\n return window.customElements.whenDefined(elementName)\n }\n }).filter((promise) => promise),\n )\n\nconst findPossibleWrappingPktCustomElement = <R extends PTLElementType>(\n innerElement: HTMLElement | null,\n isByRole: boolean,\n args: Array<any>,\n): PTLElementType => {\n if (!innerElement === null) {\n throw getElementError(`Finner ikke noe element med ${isByRole ? 'role' : 'label'} \"${args[0]}\"`, document.body)\n }\n const pktElement = innerElement?.closest(PKT_CUSTOM_FORMFIELDS.join(', ')) as R | null\n if (pktElement) {\n return pktElement as R\n } else {\n return innerElement as R\n }\n}\n\nconst getPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n (query: QueryTypes = 'label', identifier: string | RegExp, container?: HTMLElement): PTLElementType => {\n const queryFunc = syncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = doElementSearch(identifier, query, queryFunc, container)[0]\n return findPossibleWrappingPktCustomElement(innerElement, false, [])\n }\n\nconst removeElementBySelector = (ancestor: HTMLElement, selector: string) => {\n const elements = Array.from(ancestor.querySelectorAll(selector))\n elements.forEach((element) => {\n element.parentNode?.removeChild(element)\n })\n}\n\nfunction getPureLabelText(label: Node) {\n const clonedLabel = label.cloneNode(true) as HTMLElement\n removeElementBySelector(clonedLabel, 'pkt-helptext')\n removeElementBySelector(clonedLabel, '.pkt-input-suffix')\n removeElementBySelector(clonedLabel, '.pkt-input-prefix')\n removeElementBySelector(clonedLabel, '.pkt-input-icon')\n removeElementBySelector(clonedLabel, 'option')\n return clonedLabel.textContent?.trim() || null\n}\n\nconst getPureLabelTextForLabelOwner = (labelOwner: HTMLElement): string | null => {\n const label =\n ('labels' in labelOwner &&\n labelOwner.labels instanceof NodeList &&\n labelOwner.labels.length > 0 &&\n labelOwner.labels[0]) ||\n (labelOwner.querySelector('label') as HTMLLabelElement | null)\n if (label) {\n return getPureLabelText(label)\n } else {\n return null\n }\n}\n\nconst labelMatcher = (labelTextToMatch: string) => (nodeContent: string, element: Element | null) => {\n if (element instanceof HTMLElement) {\n const labelWithoutHelptext = getPureLabelTextForLabelOwner(element as HTMLElement)\n return labelWithoutHelptext === labelTextToMatch\n } else {\n return false\n }\n}\n\nconst doElementSearch = <T>(\n identifier: string | RegExp,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n) => {\n try {\n return typeof identifier === 'string' && query === 'label'\n ? queryFunc(container, labelMatcher(identifier.trim()))\n : queryFunc(container, identifier)\n } catch (e) {\n if (typeof identifier === 'string' && query === 'label') {\n // Spesial-case for <pkt-select> som ikke har aria-label\n const matchingLabel: HTMLLabelElement | undefined = Array.from(document.body.querySelectorAll('label')).find(\n (labelElement) => getPureLabelText(labelElement) === identifier,\n )\n const labelOwner = matchingLabel?.control || matchingLabel?.closest('pkt-select')\n if (labelOwner) {\n return [labelOwner]\n } else {\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, document.body)\n }\n }\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, document.body)\n }\n}\n\nconst findPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n async (\n query: QueryTypes = 'label',\n identifier: string | RegExp,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0]\n\n return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []))\n }\n\nconst getPktElementByLabel =\n (testingLibrary: TestingLibraryTools) => (label: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp, container?: HTMLElement): Promise<PTLElementType> =>\n findPktElementBy(testingLibrary)('label', label, container)\n\nconst getPktElementByText = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('text', text, container)\n\nconst findPktElementByText =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('text', text, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)((element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Only elements with a checked attribute can be checked')\n }\n const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n return Promise.resolve(returnValue)\n })\n\n/**\n * Representerer en option i en PktSelect.\n *\n * @property {string} 0 - verdien (value)\n * @property {string | null} 1 - Tekstinnholdet, <option>tekstinnhold</option>\n * @property {boolean} 2 - Om denne er valgt (selected)\n */\nexport type PktOption = [string, string | null, boolean]\n\nconst getPktSelectOptions = (testingLibrary: TestingLibraryTools) =>\n syncFuncWithStringIdentifierOrElement(testingLibrary)<PktSelect, Array<PktOption>>(\n (selectElement: PktSelect): Array<PktOption> => {\n const optionElements: Array<HTMLOptionElement> = Array.from(\n selectElement.querySelectorAll(\n ':scope > option, :scope > optgroup > option, :scope > data, :scope > optgroup > data',\n ),\n )\n const currentValue = selectElement.value\n return optionElements.map((optionElement) => [\n optionElement.value,\n optionElement.textContent,\n optionElement.value === currentValue,\n ])\n },\n )\n\nconst getAllPktElementsByLabelText =\n (testingLibrary: TestingLibraryTools) =>\n (label: string, container?: HTMLElement): Element[] => {\n const innerElements = testingLibrary.getAllByLabelText(container || document.body, label)\n return innerElements.map((element) => findPossibleWrappingPktCustomElement(element, false, []))\n }\n\nconst setPktElementValue = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (\n element: PTLElementType,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent = false,\n ): Promise<boolean> => {\n if (\n Array.isArray(valueOrValues) &&\n !(element.tagName === 'PKT-SELECT' && 'multiple' in element && element.multiple)\n ) {\n throw new Error('Only a multi-select PktSelect can have multiple values')\n }\n if (element.tagName === 'PKT-SELECT') {\n testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(true)\n } else {\n const returnValue = useInputEvent\n ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(returnValue)\n }\n },\n )\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PktRadioButton) => {\n const returnValue = testingLibrary.fireEvent.click(element)\n return Promise.resolve(returnValue)\n }, 'text')\n"],"names":[],"mappings":";AAsBO,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,sBAAsB,CAAC,qBAAqB,GAAG,qBAAqB;AAyD7D,MAAA,yBAAmF,CAC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AAA,QAAQ,QAAQ,WAAW;AACpC,GAAG,MAAM;"}
1
+ {"version":3,"file":"punkt-testing-utils.es.js","sources":["../src/index.ts"],"sourcesContent":["import DomTestingLibrary, {\n FindAllByBoundAttribute,\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByTestId,\n findAllByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByTestId,\n getAllByText,\n getElementError,\n} from '@testing-library/dom'\nimport {\n PktDatepicker,\n PktInputWrapper,\n PktProgressbar,\n PktRadioButton,\n PktSelect,\n PktTextarea,\n} from '@oslokommune/punkt-elements'\nimport { AllByBoundAttribute } from '@testing-library/dom/types/queries'\n\nexport const PKT_CUSTOM_FORMFIELDS = [\n 'pkt-datepicker',\n 'pkt-progressbar',\n 'pkt-textarea',\n 'pkt-textinput',\n 'pkt-select',\n]\nconst PKT_CUSTOM_ELEMENTS = ['pkt-input-wrapper', ...PKT_CUSTOM_FORMFIELDS]\n\ntype PTLElementType =\n | PktDatepicker\n | PktProgressbar\n | PktTextarea\n | PktInputWrapper\n | PktSelect\n | PktRadioButton\n | HTMLInputElement\n | HTMLSelectElement\n | HTMLTextAreaElement\n\nexport type PktTestingLibraryOptions = Pick<\n typeof DomTestingLibrary,\n | 'fireEvent'\n | 'findAllByLabelText'\n | 'findAllByTestId'\n | 'findAllByDisplayValue'\n | 'findAllByText'\n | 'getAllByLabelText'\n | 'getAllByTestId'\n | 'getAllByDisplayValue'\n | 'getAllByText'\n>\n\ntype TestingLibraryTools = {\n fireEvent: typeof DomTestingLibrary.fireEvent\n findAllByLabelText: typeof DomTestingLibrary.findAllByLabelText\n findAllByTestId: typeof DomTestingLibrary.findAllByTestId\n findAllByDisplayValue: typeof DomTestingLibrary.findAllByDisplayValue\n findAllByText: typeof DomTestingLibrary.findAllByText\n getAllByLabelText: typeof DomTestingLibrary.getAllByLabelText\n getAllByTestId: typeof DomTestingLibrary.getAllByTestId\n getAllByDisplayValue: typeof DomTestingLibrary.getAllByDisplayValue\n getAllByText: typeof DomTestingLibrary.getAllByText\n}\n\nexport type LabelOrElement<ElementType = PTLElementType> = string | RegExp | ElementType\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, onlySelected ?: boolean) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent?: boolean,\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<PktRadioButton | 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: PktTestingLibraryOptions = {\n fireEvent: options.fireEvent,\n findAllByLabelText: options.findAllByLabelText,\n findAllByDisplayValue: options.findAllByDisplayValue,\n findAllByTestId: options.findAllByTestId,\n findAllByText: options.findAllByText,\n getAllByLabelText: options.getAllByLabelText,\n getAllByDisplayValue: options.getAllByDisplayValue,\n getAllByTestId: options.getAllByTestId,\n getAllByText: options.getAllByText,\n }\n return {\n findPktElementByLabelText: withTestingLibrary(tools, findPktElementByLabel),\n waitForPktElementsToBeDefined,\n getPktElementByLabelText: withTestingLibrary(tools, getPktElementByLabel),\n setPktElementChecked: withTestingLibrary(tools, setPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n 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 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)((element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Only elements with a checked attribute can be checked')\n }\n const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n return Promise.resolve(returnValue)\n })\n\nconst getPktElementByDisplayValue = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('displayValue', text, container)\n\nconst findPktElementByDisplayValue = (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: PktRadioButton) => {\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":";AAsBO,MAAM,wBAAwB;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,sBAAsB,CAAC,qBAAqB,GAAG,qBAAqB;AA+D7D,MAAA,yBAAmF,CAC9F,YACG;AACH,QAAM,QAAkC;AAAA,IACtC,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,8BAA8B,mBAAmB,OAAO,4BAA4B;AAAA,IACpF,oBAAoB,mBAAmB,OAAO,kBAAkB;AAAA,IAChE,gBAAgB,mBAAm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C,YAAA,cAAc,gBAChB,eAAe,UAAU,MAAM,SAAS,EAAE,QAAQ,EAAE,OAAO,cAAc,EAAG,CAAA,IAC5E,eAAe,UAAU,OAAO,SAAS,EAAE,QAAQ,EAAE,OAAO,cAAc,EAAA,CAAG;AAC1E,aAAA,QAAQ,QAAQ,WAAW;AAAA,IACpC;AAAA,EACF;AACF;AAEF,MAAM,iBAAiB,CAAC,mBACtB,uCAAuC,cAAc,EAAE,OAAO,YAA4B;AACxF,QAAM,cAAc,eAAe,UAAU,MAAM,OAAO;AACnD,SAAA,QAAQ,QAAQ,WAAW;AACpC,GAAG,MAAM;AAEX,MAAM,+BAA+B,CAAC,mBACpC,uCAAuC,cAAc;AAAA,EACnD,OAAO,cAAyB,wBAAuC;AACrE,UAAM,mBAAmB,oBAAoB,cAAc,EAAE,SAAS;AACtE,UAAM,kBAAkB,oBACrB,IAAI,CAAC,gBAAgB,iBAAiB,KAAK,CAAC,CAAC,GAAG,KAAK,MAAM,UAAU,WAAW,CAAC,EACjF,OAAO,CAAC,mBAAmB,cAAc;AACxC,QAAA,gBAAgB,WAAW,oBAAoB,QAAQ;AACzD,YAAM,IAAI;AAAA,QACR,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;"}
@@ -30,7 +30,10 @@
30
30
  getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),
31
31
  getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),
32
32
  setPktElementValue: withTestingLibrary(tools, setPktElementValue),
33
- pktClickButton: withTestingLibrary(tools, pktClickButton)
33
+ pktClickButton: withTestingLibrary(tools, pktClickButton),
34
+ setPktSelectedOptionsByLabel: withTestingLibrary(tools, setPktSelectedOptionsByLabel),
35
+ getPktElementByDisplayValue: withTestingLibrary(tools, getPktElementByDisplayValue),
36
+ findPktElementByDisplayValue: withTestingLibrary(tools, findPktElementByDisplayValue)
34
37
  };
35
38
  };
36
39
  const syncQueryFunctionResolver = (testingLibrary) => (queryType) => {
@@ -83,7 +86,7 @@
83
86
  }
84
87
  }).filter((promise) => promise)
85
88
  );
86
- const findPossibleWrappingPktCustomElement = (innerElement, isByRole, args) => {
89
+ const findPossibleWrappingPktCustomElement = (testingLibrary) => (innerElement, isByRole, args) => {
87
90
  if (!innerElement === null) {
88
91
  throw dom.getElementError(`Finner ikke noe element med ${isByRole ? "role" : "label"} "${args[0]}"`, document.body);
89
92
  }
@@ -95,9 +98,13 @@
95
98
  }
96
99
  };
97
100
  const getPktElementBy = (testingLibrary) => (query = "label", identifier, container) => {
98
- const queryFunc = syncQueryFunctionResolver(testingLibrary)(query);
99
- const innerElement = doElementSearch(identifier, query, queryFunc, container)[0];
100
- return findPossibleWrappingPktCustomElement(innerElement, false, []);
101
+ try {
102
+ const queryFunc = syncQueryFunctionResolver(testingLibrary)(query);
103
+ const innerElement = doElementSearch(identifier, query, queryFunc, container)[0];
104
+ return findPossibleWrappingPktCustomElement(testingLibrary)(innerElement, false, []);
105
+ } catch (e) {
106
+ return fallbackSearchForPktSelectByLabel()(identifier, query, container);
107
+ }
101
108
  };
102
109
  const removeElementBySelector = (ancestor, selector) => {
103
110
  const elements = Array.from(ancestor.querySelectorAll(selector));
@@ -113,11 +120,13 @@
113
120
  removeElementBySelector(clonedLabel, ".pkt-input-suffix");
114
121
  removeElementBySelector(clonedLabel, ".pkt-input-prefix");
115
122
  removeElementBySelector(clonedLabel, ".pkt-input-icon");
123
+ removeElementBySelector(clonedLabel, ".pkt-input__counter");
116
124
  removeElementBySelector(clonedLabel, "option");
125
+ removeElementBySelector(clonedLabel, ".pkt-alert--error");
117
126
  return ((_a = clonedLabel.textContent) == null ? void 0 : _a.trim()) || null;
118
127
  }
119
128
  const getPureLabelTextForLabelOwner = (labelOwner) => {
120
- const label = "labels" in labelOwner && labelOwner.labels instanceof NodeList && labelOwner.labels.length > 0 && labelOwner.labels[0] || labelOwner.querySelector("label");
129
+ const label = "labels" in labelOwner && labelOwner.labels instanceof NodeList && labelOwner.labels.length > 0 && labelOwner.labels[0] || ["input", ...PKT_CUSTOM_FORMFIELDS].includes(labelOwner.tagName.toLowerCase()) && labelOwner.querySelector("label") || null;
121
130
  if (label) {
122
131
  return getPureLabelText(label);
123
132
  } else {
@@ -132,28 +141,30 @@
132
141
  return false;
133
142
  }
134
143
  };
135
- const doElementSearch = (identifier, query, queryFunc, container = document.body) => {
136
- try {
137
- return typeof identifier === "string" && query === "label" ? queryFunc(container, labelMatcher(identifier.trim())) : queryFunc(container, identifier);
138
- } catch (e) {
139
- if (typeof identifier === "string" && query === "label") {
140
- const matchingLabel = Array.from(document.body.querySelectorAll("label")).find(
141
- (labelElement) => getPureLabelText(labelElement) === identifier
142
- );
143
- const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select"));
144
- if (labelOwner) {
145
- return [labelOwner];
146
- } else {
147
- throw dom.getElementError(`Fant ikke noe element med ${query} "${identifier}"`, document.body);
148
- }
144
+ const fallbackSearchForPktSelectByLabel = (testingLibrary) => (identifier, query, container = document.body) => {
145
+ if (typeof identifier === "string" && query === "label") {
146
+ const matchingLabel = Array.from(container.querySelectorAll("label")).find(
147
+ (labelElement) => getPureLabelText(labelElement) === identifier
148
+ );
149
+ const labelOwner = (matchingLabel == null ? void 0 : matchingLabel.control) || (matchingLabel == null ? void 0 : matchingLabel.closest("pkt-select"));
150
+ if (!labelOwner) {
151
+ throw dom.getElementError(`Fant ikke noe element med label "${identifier}"`, container);
149
152
  }
150
- throw dom.getElementError(`Fant ikke noe element med ${query} "${identifier}"`, document.body);
153
+ return labelOwner;
151
154
  }
155
+ throw dom.getElementError(`Fant ikke noe element med ${query} "${identifier}"`, container);
156
+ };
157
+ const doElementSearch = (identifier, query, queryFunc, container = document.body) => {
158
+ return typeof identifier === "string" && query === "label" ? queryFunc(container, labelMatcher(identifier.trim())) : queryFunc(container, identifier);
152
159
  };
153
160
  const findPktElementBy = (testingLibrary) => async (query = "label", identifier, container) => {
154
- const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query);
155
- const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0];
156
- return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []));
161
+ try {
162
+ const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query);
163
+ const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0];
164
+ return Promise.resolve(findPossibleWrappingPktCustomElement(testingLibrary)(innerElement, false, []));
165
+ } catch (e) {
166
+ return fallbackSearchForPktSelectByLabel()(identifier, query, container);
167
+ }
157
168
  };
158
169
  const getPktElementByLabel = (testingLibrary) => (label, container) => getPktElementBy(testingLibrary)("label", label, container);
159
170
  const findPktElementByLabel = (testingLibrary) => async (label, container) => findPktElementBy(testingLibrary)("label", label, container);
@@ -164,32 +175,38 @@
164
175
  const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } });
165
176
  return Promise.resolve(returnValue);
166
177
  });
178
+ const getPktElementByDisplayValue = (testingLibrary) => (text, container) => getPktElementBy(testingLibrary)("displayValue", text, container);
179
+ const findPktElementByDisplayValue = (testingLibrary) => (text, container) => findPktElementBy(testingLibrary)("displayValue", text, container);
167
180
  const getPktSelectOptions = (testingLibrary) => syncFuncWithStringIdentifierOrElement(testingLibrary)(
168
- (selectElement) => {
181
+ (selectElement, onlySelected) => {
169
182
  const optionElements = Array.from(
170
- selectElement.querySelectorAll(
171
- ":scope > option, :scope > optgroup > option, :scope > data, :scope > optgroup > data"
172
- )
183
+ selectElement.querySelectorAll("option:not(.pkt-hide), data:not(.pkt.hide)")
173
184
  );
185
+ const filter = onlySelected ? ([, , selected]) => selected : (_) => true;
174
186
  const currentValue = selectElement.value;
175
- return optionElements.map((optionElement) => [
176
- optionElement.value,
177
- optionElement.textContent,
178
- optionElement.value === currentValue
179
- ]);
187
+ return optionElements.map(
188
+ (optionElement) => {
189
+ var _a;
190
+ return [optionElement.value, (_a = optionElement.textContent) == null ? void 0 : _a.trim(), optionElement.value === currentValue];
191
+ }
192
+ ).filter(filter);
180
193
  }
181
194
  );
182
195
  const getAllPktElementsByLabelText = (testingLibrary) => (label, container) => {
183
196
  const innerElements = testingLibrary.getAllByLabelText(container || document.body, label);
184
- return innerElements.map((element) => findPossibleWrappingPktCustomElement(element, false, []));
197
+ return innerElements.map((element) => findPossibleWrappingPktCustomElement()(element, false, []));
185
198
  };
186
199
  const setPktElementValue = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
187
200
  async (element, valueOrValues, useInputEvent = false) => {
188
- if (Array.isArray(valueOrValues) && !(element.tagName === "PKT-SELECT" && "multiple" in element && element.multiple)) {
189
- throw new Error("Only a multi-select PktSelect can have multiple values");
201
+ if (Array.isArray(valueOrValues) && valueOrValues.length > 1 && element.tagName === "PKT-SELECT") {
202
+ throw new Error("Multi-verdi <pkt-select> støttes ikke");
190
203
  }
191
204
  if (element.tagName === "PKT-SELECT") {
192
- testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
205
+ const pktSelect = element;
206
+ const multiple = pktSelect.multiple;
207
+ const valueAsArray = Array.isArray(valueOrValues) ? valueOrValues : [valueOrValues];
208
+ const newValue = multiple && valueAsArray || valueAsArray.length == 0 && "" || valueAsArray[0];
209
+ testingLibrary.fireEvent.change(element, { target: { value: newValue } });
193
210
  return Promise.resolve(true);
194
211
  } else {
195
212
  const returnValue = useInputEvent ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } }) : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } });
@@ -201,6 +218,21 @@
201
218
  const returnValue = testingLibrary.fireEvent.click(element);
202
219
  return Promise.resolve(returnValue);
203
220
  }, "text");
221
+ const setPktSelectedOptionsByLabel = (testingLibrary) => asyncFuncWithStringIdentifierOrElement(testingLibrary)(
222
+ async (pktSelect, ...desiredOptionLabels) => {
223
+ const availableOptions = getPktSelectOptions(testingLibrary)(pktSelect);
224
+ const selectedOptions = desiredOptionLabels.map((optionLabel) => availableOptions.find(([_, label]) => label === optionLabel)).filter((possibleOption) => possibleOption);
225
+ if (selectedOptions.length !== desiredOptionLabels.length) {
226
+ throw new Error(
227
+ "Noen av option'ene finnes ikke i denne PktSelect'en. Du valgte " + JSON.stringify(desiredOptionLabels) + ", mens valgmulighetene er " + JSON.stringify(availableOptions.map(([, label]) => label))
228
+ );
229
+ }
230
+ return await setPktElementValue(testingLibrary)(
231
+ pktSelect,
232
+ selectedOptions.map(([value]) => value)
233
+ );
234
+ }
235
+ );
204
236
  exports2.PKT_CUSTOM_FORMFIELDS = PKT_CUSTOM_FORMFIELDS;
205
237
  exports2.setupPktTestingLibrary = setupPktTestingLibrary;
206
238
  Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
@@ -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 PktDatepicker,\n PktInputWrapper,\n PktProgressbar,\n PktRadioButton,\n PktSelect,\n PktTextarea,\n} from '@oslokommune/punkt-elements'\nimport { AllByBoundAttribute } from '@testing-library/dom/types/queries'\n\nexport const PKT_CUSTOM_FORMFIELDS = [\n 'pkt-datepicker',\n 'pkt-progressbar',\n 'pkt-textarea',\n 'pkt-textinput',\n 'pkt-select',\n]\nconst PKT_CUSTOM_ELEMENTS = ['pkt-input-wrapper', ...PKT_CUSTOM_FORMFIELDS]\n\ntype PTLElementType =\n | PktDatepicker\n | PktProgressbar\n | PktTextarea\n | PktInputWrapper\n | PktSelect\n | PktRadioButton\n | HTMLInputElement\n | HTMLSelectElement\n | HTMLTextAreaElement\n\nexport type PktTestingLibraryOptions = Pick<\n typeof DomTestingLibrary,\n | 'fireEvent'\n | 'findAllByLabelText'\n | 'findAllByTestId'\n | 'findAllByDisplayValue'\n | 'findAllByText'\n | 'getAllByLabelText'\n | 'getAllByTestId'\n | 'getAllByDisplayValue'\n | 'getAllByText'\n>\n\ntype TestingLibraryTools = {\n fireEvent: typeof DomTestingLibrary.fireEvent\n findAllByLabelText: typeof DomTestingLibrary.findAllByLabelText\n findAllByTestId: typeof DomTestingLibrary.findAllByTestId\n findAllByDisplayValue: typeof DomTestingLibrary.findAllByDisplayValue\n findAllByText: typeof DomTestingLibrary.findAllByText\n getAllByLabelText: typeof DomTestingLibrary.getAllByLabelText\n getAllByTestId: typeof DomTestingLibrary.getAllByTestId\n getAllByDisplayValue: typeof DomTestingLibrary.getAllByDisplayValue\n getAllByText: typeof DomTestingLibrary.getAllByText\n}\n\nexport type LabelOrElement<ElementType = PTLElementType> = string | RegExp | ElementType\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent?: boolean,\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<PktRadioButton>) => Promise<boolean>\n waitForPktElementsToBeDefined: () => Promise<any>\n}\n\nexport const setupPktTestingLibrary: (options: PktTestingLibraryOptions) => PktTestingLibrary = (\n options: PktTestingLibraryOptions,\n) => {\n const tools: PktTestingLibraryOptions = {\n fireEvent: options.fireEvent,\n findAllByLabelText: options.findAllByLabelText,\n findAllByDisplayValue: options.findAllByDisplayValue,\n findAllByTestId: options.findAllByTestId,\n findAllByText: options.findAllByText,\n getAllByLabelText: options.getAllByLabelText,\n getAllByDisplayValue: options.getAllByDisplayValue,\n getAllByTestId: options.getAllByTestId,\n getAllByText: options.getAllByText,\n }\n return {\n findPktElementByLabelText: withTestingLibrary(tools, findPktElementByLabel),\n waitForPktElementsToBeDefined,\n getPktElementByLabelText: withTestingLibrary(tools, getPktElementByLabel),\n setPktElementChecked: withTestingLibrary(tools, setPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n }\n}\n\ntype SyncQueries = typeof getAllByText | typeof getAllByLabelText | typeof getAllByTestId | typeof getAllByDisplayValue\ntype AsyncQueries =\n | FindAllByBoundAttribute\n | typeof findAllByText\n | typeof findAllByLabelText\n | typeof findAllByTestId\n | typeof findAllByDisplayValue\n\ntype QueryTypes = 'label' | 'text' | 'displayValue' | 'testid'\n\nconst syncQueryFunctionResolver =\n (testingLibrary: TestingLibraryTools) =>\n (queryType: QueryTypes): SyncQueries => {\n const queries: Record<QueryTypes, SyncQueries> = {\n text: testingLibrary.getAllByText,\n label: testingLibrary.getAllByLabelText,\n testid: testingLibrary.getAllByTestId,\n displayValue: testingLibrary.getAllByDisplayValue,\n }\n const query = queries[queryType]\n if (query) {\n return query\n } else {\n throw new Error('Unsupported query type: ' + queryType)\n }\n }\n\nconst asyncQueryFunctionResolver =\n (testingLibrary: TestingLibraryTools) =>\n (queryType: QueryTypes): AsyncQueries => {\n const queries: Record<QueryTypes, AsyncQueries> = {\n text: testingLibrary.findAllByText,\n label: testingLibrary.findAllByLabelText,\n testid: testingLibrary.findAllByTestId,\n displayValue: testingLibrary.findAllByDisplayValue,\n }\n const query = queries[queryType]\n if (query) {\n return query\n } else {\n throw new Error('Unsupported query type: ' + queryType)\n }\n }\n\nconst syncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType>(elementOrIdentifier: string | RegExp | ElementType, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? (getPktElementBy(testingLibrary)(query, elementOrIdentifier) as ElementType)\n : elementOrIdentifier\n\nconst asyncResolveIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n async <ElementType>(elementOrIdentifier: string | RegExp | ElementType, query: QueryTypes) =>\n typeof elementOrIdentifier === 'string' || elementOrIdentifier instanceof RegExp\n ? ((await findPktElementBy(testingLibrary)(query, elementOrIdentifier)) as ElementType)\n : elementOrIdentifier\n\nconst asyncFuncWithStringIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType, ResultType>(\n func: (element: ElementType, ...restArgs: Array<any>) => Promise<ResultType>,\n query: QueryTypes = 'label',\n ) => {\n return async (labelOrPktElement: string | RegExp | ElementType, ...restArgs: Array<any>) => {\n const element = await asyncResolveIdentifierOrElement(testingLibrary)<ElementType>(labelOrPktElement, query)\n return await func(element, ...restArgs)\n }\n }\n\nconst syncFuncWithStringIdentifierOrElement =\n (testingLibrary: TestingLibraryTools) =>\n <ElementType, ResultType>(\n func: (element: ElementType, ...restArgs: Array<any>) => ResultType,\n query: QueryTypes = 'label',\n ) => {\n return (labelOrPktElement: string | RegExp | ElementType, ...restArgs: Array<any>) => {\n const element = syncResolveIdentifierOrElement(testingLibrary)<ElementType>(labelOrPktElement, query)\n return func(element, ...restArgs)\n }\n }\n\nconst withTestingLibrary = <F>(testingLibrary: TestingLibraryTools, fn: (testingLibrary: TestingLibraryTools) => F) =>\n fn(testingLibrary)\n\n/**\n * Sørger for at alle brukte custom elements fra Punkt er definerte og erstattet med implementasjoner.\n * Bør kalles etter `render`, før noen operasjoner og antakelser gjøres.\n *\n * F.eks.:\n * <code>\n * render(<div><PktTextinput id=\"textinput\" name={'textInput'} label=\"My text input\" aria-label=\"My text input\" /></div>);\n * await waitForPktElementsToBeDefined();\n *\n * await setPktElementValue(\"My text input\", \"new value\");\n * </code>\n */\nconst waitForPktElementsToBeDefined = async () =>\n await Promise.all(\n PKT_CUSTOM_ELEMENTS.map((elementName) => {\n if (document.querySelector(elementName) !== null) {\n return window.customElements.whenDefined(elementName)\n }\n }).filter((promise) => promise),\n )\n\nconst findPossibleWrappingPktCustomElement = <R extends PTLElementType>(\n innerElement: HTMLElement | null,\n isByRole: boolean,\n args: Array<any>,\n): PTLElementType => {\n if (!innerElement === null) {\n throw getElementError(`Finner ikke noe element med ${isByRole ? 'role' : 'label'} \"${args[0]}\"`, document.body)\n }\n const pktElement = innerElement?.closest(PKT_CUSTOM_FORMFIELDS.join(', ')) as R | null\n if (pktElement) {\n return pktElement as R\n } else {\n return innerElement as R\n }\n}\n\nconst getPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n (query: QueryTypes = 'label', identifier: string | RegExp, container?: HTMLElement): PTLElementType => {\n const queryFunc = syncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = doElementSearch(identifier, query, queryFunc, container)[0]\n return findPossibleWrappingPktCustomElement(innerElement, false, [])\n }\n\nconst removeElementBySelector = (ancestor: HTMLElement, selector: string) => {\n const elements = Array.from(ancestor.querySelectorAll(selector))\n elements.forEach((element) => {\n element.parentNode?.removeChild(element)\n })\n}\n\nfunction getPureLabelText(label: Node) {\n const clonedLabel = label.cloneNode(true) as HTMLElement\n removeElementBySelector(clonedLabel, 'pkt-helptext')\n removeElementBySelector(clonedLabel, '.pkt-input-suffix')\n removeElementBySelector(clonedLabel, '.pkt-input-prefix')\n removeElementBySelector(clonedLabel, '.pkt-input-icon')\n removeElementBySelector(clonedLabel, 'option')\n return clonedLabel.textContent?.trim() || null\n}\n\nconst getPureLabelTextForLabelOwner = (labelOwner: HTMLElement): string | null => {\n const label =\n ('labels' in labelOwner &&\n labelOwner.labels instanceof NodeList &&\n labelOwner.labels.length > 0 &&\n labelOwner.labels[0]) ||\n (labelOwner.querySelector('label') as HTMLLabelElement | null)\n if (label) {\n return getPureLabelText(label)\n } else {\n return null\n }\n}\n\nconst labelMatcher = (labelTextToMatch: string) => (nodeContent: string, element: Element | null) => {\n if (element instanceof HTMLElement) {\n const labelWithoutHelptext = getPureLabelTextForLabelOwner(element as HTMLElement)\n return labelWithoutHelptext === labelTextToMatch\n } else {\n return false\n }\n}\n\nconst doElementSearch = <T>(\n identifier: string | RegExp,\n query: QueryTypes,\n queryFunc: (...args: Parameters<AllByBoundAttribute>) => T,\n container: HTMLElement = document.body,\n) => {\n try {\n return typeof identifier === 'string' && query === 'label'\n ? queryFunc(container, labelMatcher(identifier.trim()))\n : queryFunc(container, identifier)\n } catch (e) {\n if (typeof identifier === 'string' && query === 'label') {\n // Spesial-case for <pkt-select> som ikke har aria-label\n const matchingLabel: HTMLLabelElement | undefined = Array.from(document.body.querySelectorAll('label')).find(\n (labelElement) => getPureLabelText(labelElement) === identifier,\n )\n const labelOwner = matchingLabel?.control || matchingLabel?.closest('pkt-select')\n if (labelOwner) {\n return [labelOwner]\n } else {\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, document.body)\n }\n }\n throw getElementError(`Fant ikke noe element med ${query} \"${identifier}\"`, document.body)\n }\n}\n\nconst findPktElementBy =\n (testingLibrary: TestingLibraryTools) =>\n async (\n query: QueryTypes = 'label',\n identifier: string | RegExp,\n container?: HTMLElement,\n ): Promise<PTLElementType> => {\n const queryFunc = asyncQueryFunctionResolver(testingLibrary)(query)\n const innerElement = (await doElementSearch(identifier, query, queryFunc, container))[0]\n\n return Promise.resolve(findPossibleWrappingPktCustomElement(innerElement, false, []))\n }\n\nconst getPktElementByLabel =\n (testingLibrary: TestingLibraryTools) => (label: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('label', label, container)\n\nconst findPktElementByLabel =\n (testingLibrary: TestingLibraryTools) =>\n async (label: string | RegExp, container?: HTMLElement): Promise<PTLElementType> =>\n findPktElementBy(testingLibrary)('label', label, container)\n\nconst getPktElementByText = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('text', text, container)\n\nconst findPktElementByText =\n (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n findPktElementBy(testingLibrary)('text', text, container)\n\nconst setPktElementChecked = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)((element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Only elements with a checked attribute can be checked')\n }\n const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n return Promise.resolve(returnValue)\n })\n\n/**\n * Representerer en option i en PktSelect.\n *\n * @property {string} 0 - verdien (value)\n * @property {string | null} 1 - Tekstinnholdet, <option>tekstinnhold</option>\n * @property {boolean} 2 - Om denne er valgt (selected)\n */\nexport type PktOption = [string, string | null, boolean]\n\nconst getPktSelectOptions = (testingLibrary: TestingLibraryTools) =>\n syncFuncWithStringIdentifierOrElement(testingLibrary)<PktSelect, Array<PktOption>>(\n (selectElement: PktSelect): Array<PktOption> => {\n const optionElements: Array<HTMLOptionElement> = Array.from(\n selectElement.querySelectorAll(\n ':scope > option, :scope > optgroup > option, :scope > data, :scope > optgroup > data',\n ),\n )\n const currentValue = selectElement.value\n return optionElements.map((optionElement) => [\n optionElement.value,\n optionElement.textContent,\n optionElement.value === currentValue,\n ])\n },\n )\n\nconst getAllPktElementsByLabelText =\n (testingLibrary: TestingLibraryTools) =>\n (label: string, container?: HTMLElement): Element[] => {\n const innerElements = testingLibrary.getAllByLabelText(container || document.body, label)\n return innerElements.map((element) => findPossibleWrappingPktCustomElement(element, false, []))\n }\n\nconst setPktElementValue = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(\n async (\n element: PTLElementType,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent = false,\n ): Promise<boolean> => {\n if (\n Array.isArray(valueOrValues) &&\n !(element.tagName === 'PKT-SELECT' && 'multiple' in element && element.multiple)\n ) {\n throw new Error('Only a multi-select PktSelect can have multiple values')\n }\n if (element.tagName === 'PKT-SELECT') {\n testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(true)\n } else {\n const returnValue = useInputEvent\n ? testingLibrary.fireEvent.input(element, { target: { value: valueOrValues } })\n : testingLibrary.fireEvent.change(element, { target: { value: valueOrValues } })\n return Promise.resolve(returnValue)\n }\n },\n )\n\nconst pktClickButton = (testingLibrary: TestingLibraryTools) =>\n asyncFuncWithStringIdentifierOrElement(testingLibrary)(async (element: PktRadioButton) => {\n const returnValue = testingLibrary.fireEvent.click(element)\n return Promise.resolve(returnValue)\n }, 'text')\n"],"names":["getElementError"],"mappings":";;;;AAsBO,QAAM,wBAAwB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,sBAAsB,CAAC,qBAAqB,GAAG,qBAAqB;AAyD7D,QAAA,yBAAmF,CAC9F,YACG;AACH,UAAM,QAAkC;AAAA,MACtC,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;AAEjB,WAAA;AAAA,MACL,2BAA2B,mBAAmB,OAAO,qBAAqB;AAAA,MAC1E;AAAA,MACA,0BAA0B,mBAAmB,OAAO,oBAAoB;AAAA,MACxE,sBAAsB,mBAAmB,OAAO,oBAAoB;AAAA,MACpE,q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ACD,CAAC,OAAe,cAAuC;AACrD,UAAM,gBAAgB,eAAe,kBAAkB,aAAa,SAAS,MAAM,KAAK;AACjF,WAAA,cAAc,IAAI,CAAC,YAAY,qCAAqC,SAAS,OAAO,CAAE,CAAA,CAAC;AAAA,EAChG;AAEF,QAAM,qBAAqB,CAAC,mBAC1B,uCAAuC,cAAc;AAAA,IACnD,OACE,SACA,eACA,gBAAgB,UACK;AAEnB,UAAA,MAAM,QAAQ,aAAa,KAC3B,EAAE,QAAQ,YAAY,gBAAgB,cAAc,WAAW,QAAQ,WACvE;AACM,cAAA,IAAI,MAAM,wDAAwD;AAAA,MAC1E;AACI,UAAA,QAAQ,YAAY,cAAc;AACrB,uBAAA,UAAU,OAAO,SAAS,EAAE,QAAQ,EAAE,OAAO,cAAc,EAAA,CAAG;AACtE,eAAA,QAAQ,QAAQ,IAAI;AAAA,MAAA,OACtB;AACC,cAAA,cAAc,gBAChB,eAAe,UAAU,MAAM,SAAS,EAAE,QAAQ,EAAE,OAAO,cAAc,EAAG,CAAA,IAC5E,eAAe,UAAU,OAAO,SAAS,EAAE,QAAQ,EAAE,OAAO,cAAc,EAAA,CAAG;AAC1E,eAAA,QAAQ,QAAQ,WAAW;AAAA,MACpC;AAAA,IACF;AAAA,EACF;AAEF,QAAM,iBAAiB,CAAC,mBACtB,uCAAuC,cAAc,EAAE,OAAO,YAA4B;AACxF,UAAM,cAAc,eAAe,UAAU,MAAM,OAAO;AACnD,WAAA,QAAQ,QAAQ,WAAW;AAAA,EACpC,GAAG,MAAM;;;;;"}
1
+ {"version":3,"file":"punkt-testing-utils.umd.js","sources":["../src/index.ts"],"sourcesContent":["import DomTestingLibrary, {\n FindAllByBoundAttribute,\n findAllByDisplayValue,\n findAllByLabelText,\n findAllByTestId,\n findAllByText,\n getAllByDisplayValue,\n getAllByLabelText,\n getAllByTestId,\n getAllByText,\n getElementError,\n} from '@testing-library/dom'\nimport {\n PktDatepicker,\n PktInputWrapper,\n PktProgressbar,\n PktRadioButton,\n PktSelect,\n PktTextarea,\n} from '@oslokommune/punkt-elements'\nimport { AllByBoundAttribute } from '@testing-library/dom/types/queries'\n\nexport const PKT_CUSTOM_FORMFIELDS = [\n 'pkt-datepicker',\n 'pkt-progressbar',\n 'pkt-textarea',\n 'pkt-textinput',\n 'pkt-select',\n]\nconst PKT_CUSTOM_ELEMENTS = ['pkt-input-wrapper', ...PKT_CUSTOM_FORMFIELDS]\n\ntype PTLElementType =\n | PktDatepicker\n | PktProgressbar\n | PktTextarea\n | PktInputWrapper\n | PktSelect\n | PktRadioButton\n | HTMLInputElement\n | HTMLSelectElement\n | HTMLTextAreaElement\n\nexport type PktTestingLibraryOptions = Pick<\n typeof DomTestingLibrary,\n | 'fireEvent'\n | 'findAllByLabelText'\n | 'findAllByTestId'\n | 'findAllByDisplayValue'\n | 'findAllByText'\n | 'getAllByLabelText'\n | 'getAllByTestId'\n | 'getAllByDisplayValue'\n | 'getAllByText'\n>\n\ntype TestingLibraryTools = {\n fireEvent: typeof DomTestingLibrary.fireEvent\n findAllByLabelText: typeof DomTestingLibrary.findAllByLabelText\n findAllByTestId: typeof DomTestingLibrary.findAllByTestId\n findAllByDisplayValue: typeof DomTestingLibrary.findAllByDisplayValue\n findAllByText: typeof DomTestingLibrary.findAllByText\n getAllByLabelText: typeof DomTestingLibrary.getAllByLabelText\n getAllByTestId: typeof DomTestingLibrary.getAllByTestId\n getAllByDisplayValue: typeof DomTestingLibrary.getAllByDisplayValue\n getAllByText: typeof DomTestingLibrary.getAllByText\n}\n\nexport type LabelOrElement<ElementType = PTLElementType> = string | RegExp | ElementType\n\nexport type PktElementValueType = string | number | Date\n\nexport type PktTestingLibrary = {\n findPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => Promise<PTLElementType>\n getPktElementByLabelText: (label: string | RegExp, container?: HTMLElement) => PTLElementType\n getPktSelectOptions: (labelOrElement: LabelOrElement<PktSelect>, onlySelected ?: boolean) => Array<PktOption>\n getAllPktElementsByLabelText: (label: string, container?: HTMLElement) => Element[]\n setPktElementChecked: (labelOrElement: LabelOrElement, checked: boolean) => Promise<boolean>\n setPktElementValue: (\n labelOrElement: LabelOrElement,\n valueOrValues: PktElementValueType | Array<PktElementValueType>,\n useInputEvent?: boolean,\n ) => Promise<boolean>\n pktClickButton: (labelOrElement: LabelOrElement<PktRadioButton | 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: PktTestingLibraryOptions = {\n fireEvent: options.fireEvent,\n findAllByLabelText: options.findAllByLabelText,\n findAllByDisplayValue: options.findAllByDisplayValue,\n findAllByTestId: options.findAllByTestId,\n findAllByText: options.findAllByText,\n getAllByLabelText: options.getAllByLabelText,\n getAllByDisplayValue: options.getAllByDisplayValue,\n getAllByTestId: options.getAllByTestId,\n getAllByText: options.getAllByText,\n }\n return {\n findPktElementByLabelText: withTestingLibrary(tools, findPktElementByLabel),\n waitForPktElementsToBeDefined,\n getPktElementByLabelText: withTestingLibrary(tools, getPktElementByLabel),\n setPktElementChecked: withTestingLibrary(tools, setPktElementChecked),\n getPktSelectOptions: withTestingLibrary(tools, getPktSelectOptions),\n getAllPktElementsByLabelText: withTestingLibrary(tools, getAllPktElementsByLabelText),\n setPktElementValue: withTestingLibrary(tools, setPktElementValue),\n pktClickButton: withTestingLibrary(tools, pktClickButton),\n 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 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)((element: PTLElementType, checked: boolean) => {\n if (!('checked' in element)) {\n throw new Error('Only elements with a checked attribute can be checked')\n }\n const returnValue = testingLibrary.fireEvent.change(element, { target: { checked } })\n return Promise.resolve(returnValue)\n })\n\nconst getPktElementByDisplayValue = (testingLibrary: TestingLibraryTools) => (text: string | RegExp, container?: HTMLElement) =>\n getPktElementBy(testingLibrary)('displayValue', text, container)\n\nconst findPktElementByDisplayValue = (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: PktRadioButton) => {\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":";;;;AAsBO,QAAM,wBAAwB;AAAA,IACnC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,QAAM,sBAAsB,CAAC,qBAAqB,GAAG,qBAAqB;AA+D7D,QAAA,yBAAmF,CAC9F,YACG;AACH,UAAM,QAAkC;AAAA,MACtC,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;AAEjB,WAAA;AAAA,MACL,2BAA2B,mBAAmB,OAAO,qBAAqB;AAAA,MAC1E;AAAA,MACA,0BAA0B,mBAAmB,OAAO,oBAAoB;AAAA,MACxE,sBAAsB,mBAAmB,OAAO,oBAAoB;AAAA,MACpE,qBAAqB,mBAAmB,OAAO,mBAAmB;AAAA,MAClE,8BAA8B,mBAAmB,OAAO,4BAA4B;AAAA,MACpF,oBAAoB,mBAAmB,OAAO,kBAAkB;AAAA,MAChE,gBAAgB,mBAAmB,OAAO,cAAc;AAAA,MACxD,8BAA8B,mBAAmB,OAAO,4BAA4B;AAAA,MACpF,6BAA6B,mBAAmB,OAAO,2BAA2B;AAAA,MAClF,8BAA8B,mBAAmB,OAAO,4BAA4B;AAAA,IAAA;AAAA,EAExF;AAYA,QAAM,4BACJ,CAAC,mBACD,CAAC,cAAuC;AACtC,UAAM,UAA2C;AAAA,MAC/C,MAAM,eAAe;AAAA,MACrB,OAAO,eAAe;AAAA,MACtB,QAAQ,eAA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AQ,QAAQ,WAAW;AAAA,MACpC;AAAA,IACF;AAAA,EACF;AAEF,QAAM,iBAAiB,CAAC,mBACtB,uCAAuC,cAAc,EAAE,OAAO,YAA4B;AACxF,UAAM,cAAc,eAAe,UAAU,MAAM,OAAO;AACnD,WAAA,QAAQ,QAAQ,WAAW;AAAA,EACpC,GAAG,MAAM;AAEX,QAAM,+BAA+B,CAAC,mBACpC,uCAAuC,cAAc;AAAA,IACnD,OAAO,cAAyB,wBAAuC;AACrE,YAAM,mBAAmB,oBAAoB,cAAc,EAAE,SAAS;AACtE,YAAM,kBAAkB,oBACrB,IAAI,CAAC,gBAAgB,iBAAiB,KAAK,CAAC,CAAC,GAAG,KAAK,MAAM,UAAU,WAAW,CAAC,EACjF,OAAO,CAAC,mBAAmB,cAAc;AACxC,UAAA,gBAAgB,WAAW,oBAAoB,QAAQ;AACzD,cAAM,IAAI;AAAA,UACR,oEACE,KAAK,UAAU,mBAAmB,IAClC,+BACA,KAAK,UAAU,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;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oslokommune/punkt-testing-utils",
3
- "version": "12.24.4",
3
+ "version": "12.26.0",
4
4
  "description": "Test-utilities for Punkt",
5
5
  "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.24.0",
21
- "@oslokommune/punkt-react": "12.24.0",
20
+ "@oslokommune/punkt-elements": "^12.26.0",
21
+ "@oslokommune/punkt-react": "^12.26.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": "74f00c77b644c4fec56e7010ca8d1948363e5885"
68
+ "gitHead": "d53ac4282cddb23a055e3d81337eb533d3abd068"
69
69
  }