@thisisagile/easy-test-react 17.30.8 → 17.30.10

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.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  ElementTester
3
- } from "./chunk-NDS2MSSJ.mjs";
3
+ } from "./chunk-ENAZCQPP.mjs";
4
4
  import "./chunk-UIR5DDLV.mjs";
5
5
  export {
6
6
  ElementTester
package/dist/Tester.d.ts CHANGED
@@ -1,25 +1,34 @@
1
1
  import { ReactElement } from 'react';
2
- import { Id } from '@thisisagile/easy';
2
+ import { Id, Uri } from '@thisisagile/easy';
3
3
  import { ElementTester } from './ElementTester';
4
4
  export declare class Tester {
5
5
  readonly container: HTMLElement;
6
6
  constructor(container: HTMLElement);
7
+ get isEmpty(): boolean;
7
8
  static render: (component: ReactElement) => Promise<Tester>;
8
9
  static renderSync: (component: ReactElement) => Tester;
9
- byText: (text: string, index?: number) => HTMLElement;
10
- atText: (text: string, index?: number) => ElementTester;
10
+ byAlt: (alt: string, index?: number) => HTMLElement;
11
+ atAlt: (alt: string, index?: number) => ElementTester;
11
12
  byId: (id: Id, index?: number) => HTMLElement;
12
13
  atId: (id: Id, index?: number) => ElementTester;
14
+ byLabel: (label: string, index?: number) => HTMLElement;
15
+ atLabel: (label: string, index?: number) => ElementTester;
16
+ byPlaceholder: (placeholder: string, index?: number) => HTMLElement;
17
+ atPlaceholder: (placeholder: string, index?: number) => ElementTester;
18
+ byHref: (href: string | Uri, index?: number) => HTMLElement;
19
+ atHref: (href: string | Uri, index?: number) => ElementTester;
20
+ byQuery: (query: string, index?: number) => HTMLElement;
21
+ atQuery: (query: string, index?: number) => ElementTester;
13
22
  byRole: (role: string, index?: number) => HTMLElement;
14
23
  atRole: (role: string, index?: number) => ElementTester;
15
24
  byRow: (index?: number) => HTMLElement;
16
25
  atRow: (index?: number) => ElementTester;
26
+ byText: (text: string, index?: number) => HTMLElement;
27
+ atText: (text: string, index?: number) => ElementTester;
17
28
  byTitle: (title: string, index?: number) => HTMLElement;
18
29
  atTitle: (title: string, index?: number) => ElementTester;
19
- byPlaceholder: (placeholder: string, index?: number) => HTMLElement;
20
- atPlaceholder: (placeholder: string, index?: number) => ElementTester;
21
- byQuery: (query: string, index?: number) => HTMLElement;
22
- atQuery: (query: string, index?: number) => ElementTester;
30
+ byValue: (value: string, index?: number) => HTMLElement;
31
+ atValue: (value: string, index?: number) => ElementTester;
23
32
  submit: (id?: Id) => ElementTester;
24
33
  debug: () => void;
25
34
  }
package/dist/Tester.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  Tester,
3
3
  renders,
4
4
  rendersWait
5
- } from "./chunk-NDS2MSSJ.mjs";
5
+ } from "./chunk-ENAZCQPP.mjs";
6
6
  import "./chunk-UIR5DDLV.mjs";
7
7
  export {
8
8
  Tester,
@@ -4,6 +4,7 @@ import {
4
4
 
5
5
  // src/Tester.ts
6
6
  import { render, screen } from "@testing-library/react";
7
+ import { asString } from "@thisisagile/easy";
7
8
 
8
9
  // src/ElementTester.ts
9
10
  import { fireEvent, waitFor, waitForElementToBeRemoved } from "@testing-library/react";
@@ -33,29 +34,38 @@ var ElementTester = class {
33
34
  };
34
35
 
35
36
  // src/Tester.ts
37
+ var byIndex = (getAll, index = 0) => getAll()[index];
36
38
  var Tester = class _Tester {
37
39
  constructor(container) {
38
40
  this.container = container;
39
41
  }
42
+ get isEmpty() {
43
+ return this.container.innerHTML === "";
44
+ }
40
45
  static render = (component) => waitForRender(component).then((c) => new _Tester(c.container));
41
46
  static renderSync = (component) => new _Tester(render(component).container);
42
- byText = (text, index) => index ? screen.getAllByText(text)[index] : screen.getByText(text);
43
- atText = (text, index) => new ElementTester(() => this.byText(text, index));
44
- byId = (id, index) => index ? screen.getAllByTestId(id.toString())[index] : screen.getByTestId(id.toString());
47
+ byAlt = (alt, index) => byIndex(() => screen.getAllByAltText(alt), index);
48
+ atAlt = (alt, index) => new ElementTester(() => this.byAlt(alt, index));
49
+ byId = (id, index) => byIndex(() => screen.getAllByTestId(id.toString()), index);
45
50
  atId = (id, index) => new ElementTester(() => this.byId(id, index));
46
- byRole = (role, index) => index ? screen.getAllByRole(role)[index] : screen.getByRole(role);
51
+ byLabel = (label, index) => byIndex(() => screen.getAllByLabelText(label), index);
52
+ atLabel = (label, index) => new ElementTester(() => this.byLabel(label, index));
53
+ byPlaceholder = (placeholder, index) => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);
54
+ atPlaceholder = (placeholder, index) => new ElementTester(() => this.byPlaceholder(placeholder, index));
55
+ byHref = (href, index) => this.byQuery(`a[href*="${asString(href)}"]`, index);
56
+ atHref = (href, index) => new ElementTester(() => this.byHref(href, index));
57
+ byQuery = (query, index) => byIndex(() => Array.from(this.container.querySelectorAll(query)), index);
58
+ atQuery = (query, index) => new ElementTester(() => this.byQuery(query, index));
59
+ byRole = (role, index) => byIndex(() => screen.getAllByRole(role), index);
47
60
  atRole = (role, index) => new ElementTester(() => this.byRole(role, index));
48
- byRow = (index) => index ? screen.getAllByRole("row")[index] : screen.getByRole("row");
61
+ byRow = (index) => byIndex(() => screen.getAllByRole("row"), index);
49
62
  atRow = (index) => new ElementTester(() => this.byRow(index));
50
- byTitle = (title, index) => index ? screen.getAllByTitle(title)[index] : screen.getByTitle(title);
63
+ byText = (text, index) => byIndex(() => screen.getAllByText(text), index);
64
+ atText = (text, index) => new ElementTester(() => this.byText(text, index));
65
+ byTitle = (title, index) => byIndex(() => screen.getAllByTitle(title), index);
51
66
  atTitle = (title, index) => new ElementTester(() => this.byTitle(title, index));
52
- byPlaceholder = (placeholder, index) => index ? screen.getAllByPlaceholderText(placeholder)[index] : screen.getByPlaceholderText(placeholder);
53
- atPlaceholder = (placeholder, index) => new ElementTester(() => this.byPlaceholder(placeholder, index));
54
- byQuery = (query, index = 0) => {
55
- const elements = this.container.querySelectorAll(query);
56
- return elements[index];
57
- };
58
- atQuery = (query, index) => new ElementTester(() => this.byQuery(query, index));
67
+ byValue = (value, index) => byIndex(() => screen.getAllByDisplayValue(value), index);
68
+ atValue = (value, index) => new ElementTester(() => this.byValue(value, index));
59
69
  submit = (id = "btn-submit") => this.atId(id);
60
70
  debug = () => screen.debug();
61
71
  };
@@ -68,4 +78,4 @@ export {
68
78
  renders,
69
79
  ElementTester
70
80
  };
71
- //# sourceMappingURL=chunk-NDS2MSSJ.mjs.map
81
+ //# sourceMappingURL=chunk-ENAZCQPP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/Tester.ts","../src/ElementTester.ts"],"sourcesContent":["import { render, screen } from '@testing-library/react';\nimport { ReactElement } from 'react';\nimport { asString, Id, Uri } from '@thisisagile/easy';\nimport { waitForRender } from './waitForRender';\nimport { ElementTester } from './ElementTester';\n\nconst byIndex = (getAll: () => HTMLElement[], index: number = 0): HTMLElement => getAll()[index];\n\nexport class Tester {\n constructor(public readonly container: HTMLElement) {}\n\n get isEmpty(): boolean {\n return this.container.innerHTML === '';\n }\n\n static render = (component: ReactElement): Promise<Tester> => waitForRender(component).then(c => new Tester(c.container));\n\n static renderSync = (component: ReactElement): Tester => new Tester(render(component).container);\n\n byAlt = (alt: string, index?: number): HTMLElement => byIndex(() => screen.getAllByAltText(alt), index);\n\n atAlt = (alt: string, index?: number): ElementTester => new ElementTester(() => this.byAlt(alt, index));\n\n byId = (id: Id, index?: number): HTMLElement => byIndex(() => screen.getAllByTestId(id.toString()), index);\n\n atId = (id: Id, index?: number): ElementTester => new ElementTester(() => this.byId(id, index));\n\n byLabel = (label: string, index?: number): HTMLElement => byIndex(() => screen.getAllByLabelText(label), index);\n\n atLabel = (label: string, index?: number): ElementTester => new ElementTester(() => this.byLabel(label, index));\n\n byPlaceholder = (placeholder: string, index?: number): HTMLElement => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);\n\n atPlaceholder = (placeholder: string, index?: number): ElementTester => new ElementTester(() => this.byPlaceholder(placeholder, index));\n\n byHref = (href: string | Uri, index?: number): HTMLElement => this.byQuery(`a[href*=\"${asString(href)}\"]`, index);\n\n atHref = (href: string | Uri, index?: number): ElementTester => new ElementTester(() => this.byHref(href, index));\n\n byQuery = (query: string, index?: number): HTMLElement => byIndex(() => Array.from(this.container.querySelectorAll<HTMLElement>(query)), index);\n\n atQuery = (query: string, index?: number): ElementTester => new ElementTester(() => this.byQuery(query, index));\n\n byRole = (role: string, index?: number): HTMLElement => byIndex(() => screen.getAllByRole(role), index);\n\n atRole = (role: string, index?: number): ElementTester => new ElementTester(() => this.byRole(role, index));\n\n byRow = (index?: number): HTMLElement => byIndex(() => screen.getAllByRole('row'), index);\n\n atRow = (index?: number): ElementTester => new ElementTester(() => this.byRow(index));\n\n byText = (text: string, index?: number): HTMLElement => byIndex(() => screen.getAllByText(text), index);\n\n atText = (text: string, index?: number): ElementTester => new ElementTester(() => this.byText(text, index));\n\n byTitle = (title: string, index?: number): HTMLElement => byIndex(() => screen.getAllByTitle(title), index);\n\n atTitle = (title: string, index?: number): ElementTester => new ElementTester(() => this.byTitle(title, index));\n\n byValue = (value: string, index?: number): HTMLElement => byIndex(() => screen.getAllByDisplayValue(value), index);\n\n atValue = (value: string, index?: number): ElementTester => new ElementTester(() => this.byValue(value, index));\n\n submit = (id: Id = 'btn-submit'): ElementTester => this.atId(id);\n debug = () => screen.debug();\n}\n\nexport const rendersWait = async (component: ReactElement): Promise<Tester> => await Tester.render(component);\nexport const renders = (component: ReactElement): Tester => Tester.renderSync(component);\n","import { fireEvent, waitFor, waitForElementToBeRemoved } from '@testing-library/react';\nimport { isDefined, tryTo } from '@thisisagile/easy';\nimport { Tester } from './Tester';\n\nexport class ElementTester {\n constructor(readonly element: () => Element) {}\n\n get value(): string {\n return (this.element() as any)?.value as string;\n }\n\n get isValid(): boolean {\n return tryTo(() => this.element())\n .is.defined()\n .map(() => true)\n .or(false);\n }\n\n get then(): Tester {\n return new Tester(this.element() as HTMLElement);\n }\n\n click = (): this | undefined => (this.element() && fireEvent.click(this.element()) ? this : undefined);\n awaitClick = (): Promise<boolean> => waitFor(() => fireEvent.click(this.element()));\n keyDown = (key: string): this | undefined => (this.element() && fireEvent.keyDown(this.element(), { key }) ? this : undefined);\n mouseDown = (index?: number): this | undefined =>\n this.element() && fireEvent.mouseDown(isDefined(index) ? this.element().children[index] : this.element()) ? this : undefined;\n pressEnter = (): this | undefined => this.keyDown('Enter');\n clear = (): boolean => this.type('');\n type = (value: string): boolean => fireEvent.change(this.element(), { target: { value } });\n wait = (): Promise<Element> => waitFor(this.element);\n waitForRemove = (): Promise<void> => waitForElementToBeRemoved(this.element);\n}\n"],"mappings":";;;;;AAAA,SAAS,QAAQ,cAAc;AAE/B,SAAS,gBAAyB;;;ACFlC,SAAS,WAAW,SAAS,iCAAiC;AAC9D,SAAS,WAAW,aAAa;AAG1B,IAAM,gBAAN,MAAoB;AAAA,EACzB,YAAqB,SAAwB;AAAxB;AAAA,EAAyB;AAAA,EAE9C,IAAI,QAAgB;AAClB,WAAQ,KAAK,QAAQ,GAAW;AAAA,EAClC;AAAA,EAEA,IAAI,UAAmB;AACrB,WAAO,MAAM,MAAM,KAAK,QAAQ,CAAC,EAC9B,GAAG,QAAQ,EACX,IAAI,MAAM,IAAI,EACd,GAAG,KAAK;AAAA,EACb;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,IAAI,OAAO,KAAK,QAAQ,CAAgB;AAAA,EACjD;AAAA,EAEA,QAAQ,MAAyB,KAAK,QAAQ,KAAK,UAAU,MAAM,KAAK,QAAQ,CAAC,IAAI,OAAO;AAAA,EAC5F,aAAa,MAAwB,QAAQ,MAAM,UAAU,MAAM,KAAK,QAAQ,CAAC,CAAC;AAAA,EAClF,UAAU,CAAC,QAAmC,KAAK,QAAQ,KAAK,UAAU,QAAQ,KAAK,QAAQ,GAAG,EAAE,IAAI,CAAC,IAAI,OAAO;AAAA,EACpH,YAAY,CAAC,UACX,KAAK,QAAQ,KAAK,UAAU,UAAU,UAAU,KAAK,IAAI,KAAK,QAAQ,EAAE,SAAS,KAAK,IAAI,KAAK,QAA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gC,QAAQ,MAAM,OAAO,qBAAqB,KAAK,GAAG,KAAK;AAAA,EAEjH,UAAU,CAAC,OAAe,UAAkC,IAAI,cAAc,MAAM,KAAK,QAAQ,OAAO,KAAK,CAAC;AAAA,EAE9G,SAAS,CAAC,KAAS,iBAAgC,KAAK,KAAK,EAAE;AAAA,EAC/D,QAAQ,MAAM,OAAO,MAAM;AAC7B;AAEO,IAAM,cAAc,OAAO,cAA6C,MAAM,OAAO,OAAO,SAAS;AACrG,IAAM,UAAU,CAAC,cAAoC,OAAO,WAAW,SAAS;","names":[]}
package/dist/index.js CHANGED
@@ -31,10 +31,11 @@ module.exports = __toCommonJS(src_exports);
31
31
 
32
32
  // src/ElementTester.ts
33
33
  var import_react4 = require("@testing-library/react");
34
- var import_easy = require("@thisisagile/easy");
34
+ var import_easy2 = require("@thisisagile/easy");
35
35
 
36
36
  // src/Tester.ts
37
37
  var import_react3 = require("@testing-library/react");
38
+ var import_easy = require("@thisisagile/easy");
38
39
 
39
40
  // src/waitForRender.ts
40
41
  var import_react = require("@testing-library/react");
@@ -49,29 +50,38 @@ async function waitForRender(ui, options) {
49
50
  }
50
51
 
51
52
  // src/Tester.ts
53
+ var byIndex = (getAll, index = 0) => getAll()[index];
52
54
  var Tester = class _Tester {
53
55
  constructor(container) {
54
56
  this.container = container;
55
57
  }
58
+ get isEmpty() {
59
+ return this.container.innerHTML === "";
60
+ }
56
61
  static render = (component) => waitForRender(component).then((c) => new _Tester(c.container));
57
62
  static renderSync = (component) => new _Tester((0, import_react3.render)(component).container);
58
- byText = (text, index) => index ? import_react3.screen.getAllByText(text)[index] : import_react3.screen.getByText(text);
59
- atText = (text, index) => new ElementTester(() => this.byText(text, index));
60
- byId = (id, index) => index ? import_react3.screen.getAllByTestId(id.toString())[index] : import_react3.screen.getByTestId(id.toString());
63
+ byAlt = (alt, index) => byIndex(() => import_react3.screen.getAllByAltText(alt), index);
64
+ atAlt = (alt, index) => new ElementTester(() => this.byAlt(alt, index));
65
+ byId = (id, index) => byIndex(() => import_react3.screen.getAllByTestId(id.toString()), index);
61
66
  atId = (id, index) => new ElementTester(() => this.byId(id, index));
62
- byRole = (role, index) => index ? import_react3.screen.getAllByRole(role)[index] : import_react3.screen.getByRole(role);
67
+ byLabel = (label, index) => byIndex(() => import_react3.screen.getAllByLabelText(label), index);
68
+ atLabel = (label, index) => new ElementTester(() => this.byLabel(label, index));
69
+ byPlaceholder = (placeholder, index) => byIndex(() => import_react3.screen.getAllByPlaceholderText(placeholder), index);
70
+ atPlaceholder = (placeholder, index) => new ElementTester(() => this.byPlaceholder(placeholder, index));
71
+ byHref = (href, index) => this.byQuery(`a[href*="${(0, import_easy.asString)(href)}"]`, index);
72
+ atHref = (href, index) => new ElementTester(() => this.byHref(href, index));
73
+ byQuery = (query, index) => byIndex(() => Array.from(this.container.querySelectorAll(query)), index);
74
+ atQuery = (query, index) => new ElementTester(() => this.byQuery(query, index));
75
+ byRole = (role, index) => byIndex(() => import_react3.screen.getAllByRole(role), index);
63
76
  atRole = (role, index) => new ElementTester(() => this.byRole(role, index));
64
- byRow = (index) => index ? import_react3.screen.getAllByRole("row")[index] : import_react3.screen.getByRole("row");
77
+ byRow = (index) => byIndex(() => import_react3.screen.getAllByRole("row"), index);
65
78
  atRow = (index) => new ElementTester(() => this.byRow(index));
66
- byTitle = (title, index) => index ? import_react3.screen.getAllByTitle(title)[index] : import_react3.screen.getByTitle(title);
79
+ byText = (text, index) => byIndex(() => import_react3.screen.getAllByText(text), index);
80
+ atText = (text, index) => new ElementTester(() => this.byText(text, index));
81
+ byTitle = (title, index) => byIndex(() => import_react3.screen.getAllByTitle(title), index);
67
82
  atTitle = (title, index) => new ElementTester(() => this.byTitle(title, index));
68
- byPlaceholder = (placeholder, index) => index ? import_react3.screen.getAllByPlaceholderText(placeholder)[index] : import_react3.screen.getByPlaceholderText(placeholder);
69
- atPlaceholder = (placeholder, index) => new ElementTester(() => this.byPlaceholder(placeholder, index));
70
- byQuery = (query, index = 0) => {
71
- const elements = this.container.querySelectorAll(query);
72
- return elements[index];
73
- };
74
- atQuery = (query, index) => new ElementTester(() => this.byQuery(query, index));
83
+ byValue = (value, index) => byIndex(() => import_react3.screen.getAllByDisplayValue(value), index);
84
+ atValue = (value, index) => new ElementTester(() => this.byValue(value, index));
75
85
  submit = (id = "btn-submit") => this.atId(id);
76
86
  debug = () => import_react3.screen.debug();
77
87
  };
@@ -87,7 +97,7 @@ var ElementTester = class {
87
97
  return this.element()?.value;
88
98
  }
89
99
  get isValid() {
90
- return (0, import_easy.tryTo)(() => this.element()).is.defined().map(() => true).or(false);
100
+ return (0, import_easy2.tryTo)(() => this.element()).is.defined().map(() => true).or(false);
91
101
  }
92
102
  get then() {
93
103
  return new Tester(this.element());
@@ -95,7 +105,7 @@ var ElementTester = class {
95
105
  click = () => this.element() && import_react4.fireEvent.click(this.element()) ? this : void 0;
96
106
  awaitClick = () => (0, import_react4.waitFor)(() => import_react4.fireEvent.click(this.element()));
97
107
  keyDown = (key) => this.element() && import_react4.fireEvent.keyDown(this.element(), { key }) ? this : void 0;
98
- mouseDown = (index) => this.element() && import_react4.fireEvent.mouseDown((0, import_easy.isDefined)(index) ? this.element().children[index] : this.element()) ? this : void 0;
108
+ mouseDown = (index) => this.element() && import_react4.fireEvent.mouseDown((0, import_easy2.isDefined)(index) ? this.element().children[index] : this.element()) ? this : void 0;
99
109
  pressEnter = () => this.keyDown("Enter");
100
110
  clear = () => this.type("");
101
111
  type = (value) => import_react4.fireEvent.change(this.element(), { target: { value } });
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/ElementTester.ts","../src/Tester.ts","../src/waitForRender.ts"],"sourcesContent":["export * from './ElementTester';\nexport * from './Tester';\nexport * from './waitForRender';\n\nexport const mockTimezone = () => {\n jest.spyOn(Intl.DateTimeFormat.prototype, 'resolvedOptions').mockReturnValue(Intl.DateTimeFormat('en-US', { timeZone: 'UTC' }).resolvedOptions());\n};\nmockTimezone();\n","import { fireEvent, waitFor, waitForElementToBeRemoved } from '@testing-library/react';\nimport { isDefined, tryTo } from '@thisisagile/easy';\nimport { Tester } from './Tester';\n\nexport class ElementTester {\n constructor(readonly element: () => Element) {}\n\n get value(): string {\n return (this.element() as any)?.value as string;\n }\n\n get isValid(): boolean {\n return tryTo(() => this.element())\n .is.defined()\n .map(() => true)\n .or(false);\n }\n\n get then(): Tester {\n return new Tester(this.element() as HTMLElement);\n }\n\n click = (): this | undefined => (this.element() && fireEvent.click(this.element()) ? this : undefined);\n awaitClick = (): Promise<boolean> => waitFor(() => fireEvent.click(this.element()));\n keyDown = (key: string): this | undefined => (this.element() && fireEvent.keyDown(this.element(), { key }) ? this : undefined);\n mouseDown = (index?: number): this | undefined =>\n this.element() && fireEvent.mouseDown(isDefined(index) ? this.element().children[index] : this.element()) ? this : undefined;\n pressEnter = (): this | undefined => this.keyDown('Enter');\n clear = (): boolean => this.type('');\n type = (value: string): boolean => fireEvent.change(this.element(), { target: { value } });\n wait = (): Promise<Element> => waitFor(this.element);\n waitForRemove = (): Promise<void> => waitForElementToBeRemoved(this.element);\n}\n","import { render, screen } from '@testing-library/react';\nimport { ReactElement } from 'react';\nimport { Id } from '@thisisagile/easy';\nimport { waitForRender } from './waitForRender';\nimport { ElementTester } from './ElementTester';\n\nexport class Tester {\n constructor(public readonly container: HTMLElement) {}\n\n static render = (component: ReactElement): Promise<Tester> => waitForRender(component).then(c => new Tester(c.container));\n static renderSync = (component: ReactElement): Tester => new Tester(render(component).container);\n\n byText = (text: string, index?: number): HTMLElement => (index ? screen.getAllByText(text)[index] : screen.getByText(text));\n atText = (text: string, index?: number): ElementTester => new ElementTester(() => this.byText(text, index));\n byId = (id: Id, index?: number): HTMLElement => (index ? screen.getAllByTestId(id.toString())[index] : screen.getByTestId(id.toString()));\n atId = (id: Id, index?: number): ElementTester => new ElementTester(() => this.byId(id, index));\n byRole = (role: string, index?: number): HTMLElement => (index ? screen.getAllByRole(role)[index] : screen.getByRole(role));\n atRole = (role: string, index?: number): ElementTester => new ElementTester(() => this.byRole(role, index));\n byRow = (index?: number): HTMLElement => (index ? screen.getAllByRole('row')[index] : screen.getByRole('row'));\n atRow = (index?: number): ElementTester => new ElementTester(() => this.byRow(index));\n byTitle = (title: string, index?: number): HTMLElement => (index ? screen.getAllByTitle(title)[index] : screen.getByTitle(title));\n atTitle = (title: string, index?: number): ElementTester => new ElementTester(() => this.byTitle(title, index));\n byPlaceholder = (placeholder: string, index?: number): HTMLElement =>\n index ? screen.getAllByPlaceholderText(placeholder)[index] : screen.getByPlaceholderText(placeholder);\n atPlaceholder = (placeholder: string, index?: number): ElementTester => new ElementTester(() => this.byPlaceholder(placeholder, index));\n byQuery = (query: string, index: number = 0): HTMLElement => {\n const elements = this.container.querySelectorAll(query);\n return elements[index] as HTMLElement;\n };\n atQuery = (query: string, index?: number): ElementTester => new ElementTester(() => this.byQuery(query, index));\n submit = (id: Id = 'btn-submit'): ElementTester => this.atId(id);\n debug = () => screen.debug();\n}\n\nexport const rendersWait = async (component: ReactElement): Promise<Tester> => await Tester.render(component);\nexport const renders = (component: ReactElement): Tester => Tester.renderSync(component);\n","import { render, RenderOptions, RenderResult, waitFor } from '@testing-library/react';\nimport { act, ReactElement } from 'react';\n\n/* istanbul ignore next */\nexport async function waitForRender(ui: ReactElement, options?: Omit<RenderOptions, 'queries'>): Promise<RenderResult> {\n let r = {} as RenderResult;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n await act(async () => {\n r = render(ui, options);\n await waitFor(() => r.container, { container: r.container });\n });\n return r;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA8D;AAC9D,kBAAiC;;;ACDjC,IAAAC,gBAA+B;;;ACA/B,mBAA6D;AAC7D,IAAAC,gBAAkC;AAGlC,eAAsB,cAAc,IAAkB,SAAiE;AACrH,MAAI,IAAI,CAAC;AAET,YAAM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Q,MAAM,wBAAU,MAAM,KAAK,QAAQ,CAAC,CAAC;AAAA,EAClF,UAAU,CAAC,QAAmC,KAAK,QAAQ,KAAK,wBAAU,QAAQ,KAAK,QAAQ,GAAG,EAAE,IAAI,CAAC,IAAI,OAAO;AAAA,EACpH,YAAY,CAAC,UACX,KAAK,QAAQ,KAAK,wBAAU,cAAU,uBAAU,KAAK,IAAI,KAAK,QAAQ,EAAE,SAAS,KAAK,IAAI,KAAK,QAAQ,CAAC,IAAI,OAAO;AAAA,EACrH,aAAa,MAAwB,KAAK,QAAQ,OAAO;AAAA,EACzD,QAAQ,MAAe,KAAK,KAAK,EAAE;AAAA,EACnC,OAAO,CAAC,UAA2B,wBAAU,OAAO,KAAK,QAAQ,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAAA,EACzF,OAAO,UAAwB,uBAAQ,KAAK,OAAO;AAAA,EACnD,gBAAgB,UAAqB,yCAA0B,KAAK,OAAO;AAC7E;;;AD5BO,IAAM,eAAe,MAAM;AAChC,OAAK,MAAM,KAAK,eAAe,WAAW,iBAAiB,EAAE,gBAAgB,KAAK,eAAe,SAAS,EAAE,UAAU,MAAM,CAAC,EAAE,gBAAgB,CAAC;AAClJ;AACA,aAAa;","names":["import_react","import_react","import_react"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/ElementTester.ts","../src/Tester.ts","../src/waitForRender.ts"],"sourcesContent":["export * from './ElementTester';\nexport * from './Tester';\nexport * from './waitForRender';\n\nexport const mockTimezone = () => {\n jest.spyOn(Intl.DateTimeFormat.prototype, 'resolvedOptions').mockReturnValue(Intl.DateTimeFormat('en-US', { timeZone: 'UTC' }).resolvedOptions());\n};\nmockTimezone();\n","import { fireEvent, waitFor, waitForElementToBeRemoved } from '@testing-library/react';\nimport { isDefined, tryTo } from '@thisisagile/easy';\nimport { Tester } from './Tester';\n\nexport class ElementTester {\n constructor(readonly element: () => Element) {}\n\n get value(): string {\n return (this.element() as any)?.value as string;\n }\n\n get isValid(): boolean {\n return tryTo(() => this.element())\n .is.defined()\n .map(() => true)\n .or(false);\n }\n\n get then(): Tester {\n return new Tester(this.element() as HTMLElement);\n }\n\n click = (): this | undefined => (this.element() && fireEvent.click(this.element()) ? this : undefined);\n awaitClick = (): Promise<boolean> => waitFor(() => fireEvent.click(this.element()));\n keyDown = (key: string): this | undefined => (this.element() && fireEvent.keyDown(this.element(), { key }) ? this : undefined);\n mouseDown = (index?: number): this | undefined =>\n this.element() && fireEvent.mouseDown(isDefined(index) ? this.element().children[index] : this.element()) ? this : undefined;\n pressEnter = (): this | undefined => this.keyDown('Enter');\n clear = (): boolean => this.type('');\n type = (value: string): boolean => fireEvent.change(this.element(), { target: { value } });\n wait = (): Promise<Element> => waitFor(this.element);\n waitForRemove = (): Promise<void> => waitForElementToBeRemoved(this.element);\n}\n","import { render, screen } from '@testing-library/react';\nimport { ReactElement } from 'react';\nimport { asString, Id, Uri } from '@thisisagile/easy';\nimport { waitForRender } from './waitForRender';\nimport { ElementTester } from './ElementTester';\n\nconst byIndex = (getAll: () => HTMLElement[], index: number = 0): HTMLElement => getAll()[index];\n\nexport class Tester {\n constructor(public readonly container: HTMLElement) {}\n\n get isEmpty(): boolean {\n return this.container.innerHTML === '';\n }\n\n static render = (component: ReactElement): Promise<Tester> => waitForRender(component).then(c => new Tester(c.container));\n\n static renderSync = (component: ReactElement): Tester => new Tester(render(component).container);\n\n byAlt = (alt: string, index?: number): HTMLElement => byIndex(() => screen.getAllByAltText(alt), index);\n\n atAlt = (alt: string, index?: number): ElementTester => new ElementTester(() => this.byAlt(alt, index));\n\n byId = (id: Id, index?: number): HTMLElement => byIndex(() => screen.getAllByTestId(id.toString()), index);\n\n atId = (id: Id, index?: number): ElementTester => new ElementTester(() => this.byId(id, index));\n\n byLabel = (label: string, index?: number): HTMLElement => byIndex(() => screen.getAllByLabelText(label), index);\n\n atLabel = (label: string, index?: number): ElementTester => new ElementTester(() => this.byLabel(label, index));\n\n byPlaceholder = (placeholder: string, index?: number): HTMLElement => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);\n\n atPlaceholder = (placeholder: string, index?: number): ElementTester => new ElementTester(() => this.byPlaceholder(placeholder, index));\n\n byHref = (href: string | Uri, index?: number): HTMLElement => this.byQuery(`a[href*=\"${asString(href)}\"]`, index);\n\n atHref = (href: string | Uri, index?: number): ElementTester => new ElementTester(() => this.byHref(href, index));\n\n byQuery = (query: string, index?: number): HTMLElement => byIndex(() => Array.from(this.container.querySelectorAll<HTMLElement>(query)), index);\n\n atQuery = (query: string, index?: number): ElementTester => new ElementTester(() => this.byQuery(query, index));\n\n byRole = (role: string, index?: number): HTMLElement => byIndex(() => screen.getAllByRole(role), index);\n\n atRole = (role: string, index?: number): ElementTester => new ElementTester(() => this.byRole(role, index));\n\n byRow = (index?: number): HTMLElement => byIndex(() => screen.getAllByRole('row'), index);\n\n atRow = (index?: number): ElementTester => new ElementTester(() => this.byRow(index));\n\n byText = (text: string, index?: number): HTMLElement => byIndex(() => screen.getAllByText(text), index);\n\n atText = (text: string, index?: number): ElementTester => new ElementTester(() => this.byText(text, index));\n\n byTitle = (title: string, index?: number): HTMLElement => byIndex(() => screen.getAllByTitle(title), index);\n\n atTitle = (title: string, index?: number): ElementTester => new ElementTester(() => this.byTitle(title, index));\n\n byValue = (value: string, index?: number): HTMLElement => byIndex(() => screen.getAllByDisplayValue(value), index);\n\n atValue = (value: string, index?: number): ElementTester => new ElementTester(() => this.byValue(value, index));\n\n submit = (id: Id = 'btn-submit'): ElementTester => this.atId(id);\n debug = () => screen.debug();\n}\n\nexport const rendersWait = async (component: ReactElement): Promise<Tester> => await Tester.render(component);\nexport const renders = (component: ReactElement): Tester => Tester.renderSync(component);\n","import { render, RenderOptions, RenderResult, waitFor } from '@testing-library/react';\nimport { act, ReactElement } from 'react';\n\n/* istanbul ignore next */\nexport async function waitForRender(ui: ReactElement, options?: Omit<RenderOptions, 'queries'>): Promise<RenderResult> {\n let r = {} as RenderResult;\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n await act(async () => {\n r = render(ui, options);\n await waitFor(() => r.container, { container: r.container });\n });\n return r;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA8D;AAC9D,IAAAC,eAAiC;;;ACDjC,IAAAC,gBAA+B;AAE/B,kBAAkC;;;ACFlC,mBAA6D;AAC7D,IAAAC,gBAAkC;AAGlC,eAAsB,cAAc,IAAkB,SAAiE;AACrH,MAAI,IAAI,CAAC;AAET,YAAM,mBAAI,YAAY;AACpB,YAAI,qBAAO,IAAI,OAAO;AACtB,cAAM,sBAAQ,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,CAAC;AAAA,EAC7D,CAAC;AACD,SAAO;AACT;;;ADNA,IAAM,UAAU,CAAC,QAA6B,QAAgB,MAAmB,OAAO,EAAE,KAAK;AAExF,IAAM,SAAN,MAAM,QAAO;AAAA,EAClB,YAA4B,WAAwB;AAAxB;AAAA,EAAyB;AAAA,EAErD,IAAI,UAAmB;AACrB,WAAO,KAAK,UAAU,cAAc;AAAA,EACtC;AAAA,EAEA,OAAO,SAAS,CAAC,cAA6C,cAAc,SAAS,EAAE,KAAK,OAAK,IAAI,QAAO,EAAE,SAAS,CAAC;AAAA,EAExH,OAAO,aAAa,CAAC,cAAoC,IAAI,YAAO,sBAAO,SAAS,EAAE,SAAS;AAAA,EAE/F,QAAQ,CAAC,KAAa,UAAgC,QAAQ,MAAM,qBAAO,gBAAgB,GAAG,GAAG,KAAK;AAAA,EAEtG,QAAQ,CAAC,KAAa,UAAkC,IAAI,cAAc,MAAM,KAAK,MAAM,KAAK,KAAK,CAAC;AAAA,EAEtG,OAAO,CAAC,IAAQ,UAAgC,QAAQ,MAAM,qBAAO,eAAe,GAAG,SAAS,CAAC,GAAG,KAAK;AAAA,EAEzG,OAAO,CAAC,IAAQ,UAAkC,IAAI,cAAc,MAAM,KAAK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,YAAY,CAAC,UACX,KAAK,QAAQ,KAAK,wBAAU,cAAU,wBAAU,KAAK,IAAI,KAAK,QAAQ,EAAE,SAAS,KAAK,IAAI,KAAK,QAAQ,CAAC,IAAI,OAAO;AAAA,EACrH,aAAa,MAAwB,KAAK,QAAQ,OAAO;AAAA,EACzD,QAAQ,MAAe,KAAK,KAAK,EAAE;AAAA,EACnC,OAAO,CAAC,UAA2B,wBAAU,OAAO,KAAK,QAAQ,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;AAAA,EACzF,OAAO,UAAwB,uBAAQ,KAAK,OAAO;AAAA,EACnD,gBAAgB,UAAqB,yCAA0B,KAAK,OAAO;AAC7E;;;AD5BO,IAAM,eAAe,MAAM;AAChC,OAAK,MAAM,KAAK,eAAe,WAAW,iBAAiB,EAAE,gBAAgB,KAAK,eAAe,SAAS,EAAE,UAAU,MAAM,CAAC,EAAE,gBAAgB,CAAC;AAClJ;AACA,aAAa;","names":["import_react","import_easy","import_react","import_react"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thisisagile/easy-test-react",
3
- "version": "17.30.8",
3
+ "version": "17.30.10",
4
4
  "description": "Straightforward wrapper library for testing-library/react",
5
5
  "author": "Sander Hoogendoorn",
6
6
  "license": "MIT",
@@ -44,7 +44,7 @@
44
44
  "@testing-library/dom": "^10.4.0",
45
45
  "@testing-library/jest-dom": "^6.6.3",
46
46
  "@testing-library/react": "^16.3.0",
47
- "@thisisagile/easy": "^17.30.8",
47
+ "@thisisagile/easy": "^17.30.10",
48
48
  "@types/react": "^18.3.18",
49
49
  "react": "^18.3.1",
50
50
  "react-dom": "^18.3.1"
package/src/Tester.ts CHANGED
@@ -1,33 +1,66 @@
1
1
  import { render, screen } from '@testing-library/react';
2
2
  import { ReactElement } from 'react';
3
- import { Id } from '@thisisagile/easy';
3
+ import { asString, Id, Uri } from '@thisisagile/easy';
4
4
  import { waitForRender } from './waitForRender';
5
5
  import { ElementTester } from './ElementTester';
6
6
 
7
+ const byIndex = (getAll: () => HTMLElement[], index: number = 0): HTMLElement => getAll()[index];
8
+
7
9
  export class Tester {
8
10
  constructor(public readonly container: HTMLElement) {}
9
11
 
12
+ get isEmpty(): boolean {
13
+ return this.container.innerHTML === '';
14
+ }
15
+
10
16
  static render = (component: ReactElement): Promise<Tester> => waitForRender(component).then(c => new Tester(c.container));
17
+
11
18
  static renderSync = (component: ReactElement): Tester => new Tester(render(component).container);
12
19
 
13
- byText = (text: string, index?: number): HTMLElement => (index ? screen.getAllByText(text)[index] : screen.getByText(text));
14
- atText = (text: string, index?: number): ElementTester => new ElementTester(() => this.byText(text, index));
15
- byId = (id: Id, index?: number): HTMLElement => (index ? screen.getAllByTestId(id.toString())[index] : screen.getByTestId(id.toString()));
20
+ byAlt = (alt: string, index?: number): HTMLElement => byIndex(() => screen.getAllByAltText(alt), index);
21
+
22
+ atAlt = (alt: string, index?: number): ElementTester => new ElementTester(() => this.byAlt(alt, index));
23
+
24
+ byId = (id: Id, index?: number): HTMLElement => byIndex(() => screen.getAllByTestId(id.toString()), index);
25
+
16
26
  atId = (id: Id, index?: number): ElementTester => new ElementTester(() => this.byId(id, index));
17
- byRole = (role: string, index?: number): HTMLElement => (index ? screen.getAllByRole(role)[index] : screen.getByRole(role));
27
+
28
+ byLabel = (label: string, index?: number): HTMLElement => byIndex(() => screen.getAllByLabelText(label), index);
29
+
30
+ atLabel = (label: string, index?: number): ElementTester => new ElementTester(() => this.byLabel(label, index));
31
+
32
+ byPlaceholder = (placeholder: string, index?: number): HTMLElement => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);
33
+
34
+ atPlaceholder = (placeholder: string, index?: number): ElementTester => new ElementTester(() => this.byPlaceholder(placeholder, index));
35
+
36
+ byHref = (href: string | Uri, index?: number): HTMLElement => this.byQuery(`a[href*="${asString(href)}"]`, index);
37
+
38
+ atHref = (href: string | Uri, index?: number): ElementTester => new ElementTester(() => this.byHref(href, index));
39
+
40
+ byQuery = (query: string, index?: number): HTMLElement => byIndex(() => Array.from(this.container.querySelectorAll<HTMLElement>(query)), index);
41
+
42
+ atQuery = (query: string, index?: number): ElementTester => new ElementTester(() => this.byQuery(query, index));
43
+
44
+ byRole = (role: string, index?: number): HTMLElement => byIndex(() => screen.getAllByRole(role), index);
45
+
18
46
  atRole = (role: string, index?: number): ElementTester => new ElementTester(() => this.byRole(role, index));
19
- byRow = (index?: number): HTMLElement => (index ? screen.getAllByRole('row')[index] : screen.getByRole('row'));
47
+
48
+ byRow = (index?: number): HTMLElement => byIndex(() => screen.getAllByRole('row'), index);
49
+
20
50
  atRow = (index?: number): ElementTester => new ElementTester(() => this.byRow(index));
21
- byTitle = (title: string, index?: number): HTMLElement => (index ? screen.getAllByTitle(title)[index] : screen.getByTitle(title));
51
+
52
+ byText = (text: string, index?: number): HTMLElement => byIndex(() => screen.getAllByText(text), index);
53
+
54
+ atText = (text: string, index?: number): ElementTester => new ElementTester(() => this.byText(text, index));
55
+
56
+ byTitle = (title: string, index?: number): HTMLElement => byIndex(() => screen.getAllByTitle(title), index);
57
+
22
58
  atTitle = (title: string, index?: number): ElementTester => new ElementTester(() => this.byTitle(title, index));
23
- byPlaceholder = (placeholder: string, index?: number): HTMLElement =>
24
- index ? screen.getAllByPlaceholderText(placeholder)[index] : screen.getByPlaceholderText(placeholder);
25
- atPlaceholder = (placeholder: string, index?: number): ElementTester => new ElementTester(() => this.byPlaceholder(placeholder, index));
26
- byQuery = (query: string, index: number = 0): HTMLElement => {
27
- const elements = this.container.querySelectorAll(query);
28
- return elements[index] as HTMLElement;
29
- };
30
- atQuery = (query: string, index?: number): ElementTester => new ElementTester(() => this.byQuery(query, index));
59
+
60
+ byValue = (value: string, index?: number): HTMLElement => byIndex(() => screen.getAllByDisplayValue(value), index);
61
+
62
+ atValue = (value: string, index?: number): ElementTester => new ElementTester(() => this.byValue(value, index));
63
+
31
64
  submit = (id: Id = 'btn-submit'): ElementTester => this.atId(id);
32
65
  debug = () => screen.debug();
33
66
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/Tester.ts","../src/ElementTester.ts"],"sourcesContent":["import { render, screen } from '@testing-library/react';\nimport { ReactElement } from 'react';\nimport { Id } from '@thisisagile/easy';\nimport { waitForRender } from './waitForRender';\nimport { ElementTester } from './ElementTester';\n\nexport class Tester {\n constructor(public readonly container: HTMLElement) {}\n\n static render = (component: ReactElement): Promise<Tester> => waitForRender(component).then(c => new Tester(c.container));\n static renderSync = (component: ReactElement): Tester => new Tester(render(component).container);\n\n byText = (text: string, index?: number): HTMLElement => (index ? screen.getAllByText(text)[index] : screen.getByText(text));\n atText = (text: string, index?: number): ElementTester => new ElementTester(() => this.byText(text, index));\n byId = (id: Id, index?: number): HTMLElement => (index ? screen.getAllByTestId(id.toString())[index] : screen.getByTestId(id.toString()));\n atId = (id: Id, index?: number): ElementTester => new ElementTester(() => this.byId(id, index));\n byRole = (role: string, index?: number): HTMLElement => (index ? screen.getAllByRole(role)[index] : screen.getByRole(role));\n atRole = (role: string, index?: number): ElementTester => new ElementTester(() => this.byRole(role, index));\n byRow = (index?: number): HTMLElement => (index ? screen.getAllByRole('row')[index] : screen.getByRole('row'));\n atRow = (index?: number): ElementTester => new ElementTester(() => this.byRow(index));\n byTitle = (title: string, index?: number): HTMLElement => (index ? screen.getAllByTitle(title)[index] : screen.getByTitle(title));\n atTitle = (title: string, index?: number): ElementTester => new ElementTester(() => this.byTitle(title, index));\n byPlaceholder = (placeholder: string, index?: number): HTMLElement =>\n index ? screen.getAllByPlaceholderText(placeholder)[index] : screen.getByPlaceholderText(placeholder);\n atPlaceholder = (placeholder: string, index?: number): ElementTester => new ElementTester(() => this.byPlaceholder(placeholder, index));\n byQuery = (query: string, index: number = 0): HTMLElement => {\n const elements = this.container.querySelectorAll(query);\n return elements[index] as HTMLElement;\n };\n atQuery = (query: string, index?: number): ElementTester => new ElementTester(() => this.byQuery(query, index));\n submit = (id: Id = 'btn-submit'): ElementTester => this.atId(id);\n debug = () => screen.debug();\n}\n\nexport const rendersWait = async (component: ReactElement): Promise<Tester> => await Tester.render(component);\nexport const renders = (component: ReactElement): Tester => Tester.renderSync(component);\n","import { fireEvent, waitFor, waitForElementToBeRemoved } from '@testing-library/react';\nimport { isDefined, tryTo } from '@thisisagile/easy';\nimport { Tester } from './Tester';\n\nexport class ElementTester {\n constructor(readonly element: () => Element) {}\n\n get value(): string {\n return (this.element() as any)?.value as string;\n }\n\n get isValid(): boolean {\n return tryTo(() => this.element())\n .is.defined()\n .map(() => true)\n .or(false);\n }\n\n get then(): Tester {\n return new Tester(this.element() as HTMLElement);\n }\n\n click = (): this | undefined => (this.element() && fireEvent.click(this.element()) ? this : undefined);\n awaitClick = (): Promise<boolean> => waitFor(() => fireEvent.click(this.element()));\n keyDown = (key: string): this | undefined => (this.element() && fireEvent.keyDown(this.element(), { key }) ? this : undefined);\n mouseDown = (index?: number): this | undefined =>\n this.element() && fireEvent.mouseDown(isDefined(index) ? this.element().children[index] : this.element()) ? this : undefined;\n pressEnter = (): this | undefined => this.keyDown('Enter');\n clear = (): boolean => this.type('');\n type = (value: string): boolean => fireEvent.change(this.element(), { target: { value } });\n wait = (): Promise<Element> => waitFor(this.element);\n waitForRemove = (): Promise<void> => waitForElementToBeRemoved(this.element);\n}\n"],"mappings":";;;;;AAAA,SAAS,QAAQ,cAAc;;;ACA/B,SAAS,WAAW,SAAS,iCAAiC;AAC9D,SAAS,WAAW,aAAa;AAG1B,IAAM,gBAAN,MAAoB;AAAA,EACzB,YAAqB,SAAwB;AAAxB;AAAA,EAAyB;AAAA,EAE9C,IAAI,QAAgB;AAClB,WAAQ,KAAK,QAAQ,GAAW;AAAA,EAClC;AAAA,EAEA,IAAI,UAAmB;AACrB,WAAO,MAAM,MAAM,KAAK,QAAQ,CAAC,EAC9B,GAAG,QAAQ,EACX,IAAI,MAAM,IAAI,EACd,GAAG,KAAK;AAAA,EACb;AAAA,EAEA,IAAI,OAAe;AACjB,WAAO,IAAI,OAAO,KAAK,QAAQ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