@thisisagile/easy-test-react 19.1.3 → 20.0.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/ElementTester.d.ts +21 -18
- package/dist/ElementTester.js +35 -0
- package/dist/ElementTester.js.map +1 -0
- package/dist/Tester.d.ts +39 -36
- package/dist/Tester.js +55 -0
- package/dist/Tester.js.map +1 -0
- package/dist/index.d.ts +7 -3
- package/dist/index.js +9 -134
- package/dist/index.js.map +1 -1
- package/dist/waitForRender.d.ts +5 -2
- package/dist/waitForRender.js +16 -0
- package/dist/waitForRender.js.map +1 -0
- package/package.json +12 -10
- package/dist/ElementTester.mjs +0 -8
- package/dist/ElementTester.mjs.map +0 -1
- package/dist/Tester.mjs +0 -12
- package/dist/Tester.mjs.map +0 -1
- package/dist/chunk-DAQNFE75.mjs +0 -88
- package/dist/chunk-DAQNFE75.mjs.map +0 -1
- package/dist/chunk-UIR5DDLV.mjs +0 -16
- package/dist/chunk-UIR5DDLV.mjs.map +0 -1
- package/dist/index.mjs +0 -24
- package/dist/index.mjs.map +0 -1
- package/dist/waitForRender.mjs +0 -7
- package/dist/waitForRender.mjs.map +0 -1
package/dist/ElementTester.d.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import { Tester } from
|
|
1
|
+
import { Tester } from "./Tester.js";
|
|
2
|
+
//#region src/ElementTester.d.ts
|
|
2
3
|
export declare class ElementTester {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
readonly element: () => Element;
|
|
5
|
+
constructor(element: () => Element);
|
|
6
|
+
get value(): string;
|
|
7
|
+
get isValid(): boolean;
|
|
8
|
+
get then(): Tester;
|
|
9
|
+
click: () => this | undefined;
|
|
10
|
+
awaitClick: () => Promise<boolean>;
|
|
11
|
+
submit: () => this | undefined;
|
|
12
|
+
awaitSubmit: () => Promise<boolean>;
|
|
13
|
+
keyDown: (key: string) => this | undefined;
|
|
14
|
+
mouseDown: (index?: number) => this | undefined;
|
|
15
|
+
pressEnter: () => this | undefined;
|
|
16
|
+
clear: () => boolean;
|
|
17
|
+
type: (value: string) => boolean;
|
|
18
|
+
blur: () => this | undefined;
|
|
19
|
+
wait: () => Promise<Element>;
|
|
20
|
+
waitForRemove: () => Promise<void>;
|
|
20
21
|
}
|
|
22
|
+
//#endregion
|
|
23
|
+
//# sourceMappingURL=ElementTester.d.ts.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Tester } from "./Tester.js";
|
|
2
|
+
import { fireEvent, waitFor, waitForElementToBeRemoved } from "@testing-library/react";
|
|
3
|
+
import { isDefined, tryTo } from "@thisisagile/easy";
|
|
4
|
+
//#region src/ElementTester.ts
|
|
5
|
+
var ElementTester = class {
|
|
6
|
+
element;
|
|
7
|
+
constructor(element) {
|
|
8
|
+
this.element = element;
|
|
9
|
+
}
|
|
10
|
+
get value() {
|
|
11
|
+
return this.element()?.value;
|
|
12
|
+
}
|
|
13
|
+
get isValid() {
|
|
14
|
+
return tryTo(() => this.element()).is.defined().map(() => true).or(false);
|
|
15
|
+
}
|
|
16
|
+
get then() {
|
|
17
|
+
return new Tester(this.element());
|
|
18
|
+
}
|
|
19
|
+
click = () => this.element() && fireEvent.click(this.element()) ? this : void 0;
|
|
20
|
+
awaitClick = () => waitFor(() => fireEvent.click(this.element()));
|
|
21
|
+
submit = () => this.element() && fireEvent.submit(this.element()) ? this : void 0;
|
|
22
|
+
awaitSubmit = () => waitFor(() => fireEvent.submit(this.element()));
|
|
23
|
+
keyDown = (key) => this.element() && fireEvent.keyDown(this.element(), { key }) ? this : void 0;
|
|
24
|
+
mouseDown = (index) => this.element() && fireEvent.mouseDown(isDefined(index) ? this.element().children[index] : this.element()) ? this : void 0;
|
|
25
|
+
pressEnter = () => this.keyDown("Enter");
|
|
26
|
+
clear = () => this.type("");
|
|
27
|
+
type = (value) => fireEvent.change(this.element(), { target: { value } });
|
|
28
|
+
blur = () => this.element() && fireEvent.blur(this.element()) ? this : void 0;
|
|
29
|
+
wait = () => waitFor(this.element);
|
|
30
|
+
waitForRemove = () => waitForElementToBeRemoved(this.element);
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { ElementTester };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=ElementTester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ElementTester.js","names":[],"sources":["../src/ElementTester.ts"],"sourcesContent":["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 submit = (): this | undefined => (this.element() && fireEvent.submit(this.element()) ? this : undefined);\n awaitSubmit = (): Promise<boolean> => waitFor(() => fireEvent.submit(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 blur = (): this | undefined => (this.element() && fireEvent.blur(this.element()) ? this : undefined);\n wait = (): Promise<Element>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,0BAA0B,KAAK,OAAO;AAC7E"}
|
package/dist/Tester.d.ts
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Id, Uri } from
|
|
3
|
-
import {
|
|
1
|
+
import { ElementTester } from "./ElementTester.js";
|
|
2
|
+
import { Id, Uri } from "@thisisagile/easy";
|
|
3
|
+
import { ReactElement } from "react";
|
|
4
|
+
//#region src/Tester.d.ts
|
|
4
5
|
export declare class Tester {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
6
|
+
readonly container: HTMLElement;
|
|
7
|
+
constructor(container: HTMLElement);
|
|
8
|
+
get isEmpty(): boolean;
|
|
9
|
+
static render: (component: ReactElement) => Promise<Tester>;
|
|
10
|
+
static renderSync: (component: ReactElement) => Tester;
|
|
11
|
+
byAlt: (alt: string, index?: number) => HTMLElement;
|
|
12
|
+
atAlt: (alt: string, index?: number) => ElementTester;
|
|
13
|
+
byId: (id: Id, index?: number) => HTMLElement;
|
|
14
|
+
atId: (id: Id, index?: number) => ElementTester;
|
|
15
|
+
byLabel: (label: string, index?: number) => HTMLElement;
|
|
16
|
+
atLabel: (label: string, index?: number) => ElementTester;
|
|
17
|
+
byPlaceholder: (placeholder: string, index?: number) => HTMLElement;
|
|
18
|
+
atPlaceholder: (placeholder: string, index?: number) => ElementTester;
|
|
19
|
+
byHref: (href: string | Uri, index?: number) => HTMLElement;
|
|
20
|
+
atHref: (href: string | Uri, index?: number) => ElementTester;
|
|
21
|
+
byQuery: (query: string, index?: number) => HTMLElement;
|
|
22
|
+
atQuery: (query: string, index?: number) => ElementTester;
|
|
23
|
+
byRole: (role: string, index?: number) => HTMLElement;
|
|
24
|
+
atRole: (role: string, index?: number) => ElementTester;
|
|
25
|
+
byRow: (index?: number) => HTMLElement;
|
|
26
|
+
atRow: (index?: number) => ElementTester;
|
|
27
|
+
byText: (text: string, index?: number) => HTMLElement;
|
|
28
|
+
atText: (text: string, index?: number) => ElementTester;
|
|
29
|
+
byTitle: (title: string, index?: number) => HTMLElement;
|
|
30
|
+
atTitle: (title: string, index?: number) => ElementTester;
|
|
31
|
+
byValue: (value: string, index?: number) => HTMLElement;
|
|
32
|
+
atValue: (value: string, index?: number) => ElementTester;
|
|
33
|
+
byField: (field: Id, index?: number) => HTMLElement;
|
|
34
|
+
atField: (field: Id, index?: number) => ElementTester;
|
|
35
|
+
byName: (name: Id, index?: number) => HTMLElement;
|
|
36
|
+
atName: (name: Id, index?: number) => ElementTester;
|
|
37
|
+
submit: (id?: Id) => ElementTester;
|
|
38
|
+
debug: () => void;
|
|
38
39
|
}
|
|
39
40
|
export declare const rendersWait: (component: ReactElement) => Promise<Tester>;
|
|
40
41
|
export declare const renders: (component: ReactElement) => Tester;
|
|
42
|
+
//#endregion
|
|
43
|
+
//# sourceMappingURL=Tester.d.ts.map
|
package/dist/Tester.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { waitForRender } from "./waitForRender.js";
|
|
2
|
+
import { ElementTester } from "./ElementTester.js";
|
|
3
|
+
import { render, screen } from "@testing-library/react";
|
|
4
|
+
import { asString } from "@thisisagile/easy";
|
|
5
|
+
//#region src/Tester.ts
|
|
6
|
+
const byIndex = (getAll, index = 0) => getAll()[index];
|
|
7
|
+
var Tester = class Tester {
|
|
8
|
+
container;
|
|
9
|
+
constructor(container) {
|
|
10
|
+
this.container = container;
|
|
11
|
+
}
|
|
12
|
+
get isEmpty() {
|
|
13
|
+
return this.container.innerHTML === "";
|
|
14
|
+
}
|
|
15
|
+
static render = (component) => waitForRender(component).then((c) => new Tester(c.container));
|
|
16
|
+
static renderSync = (component) => new Tester(render(component).container);
|
|
17
|
+
byAlt = (alt, index) => byIndex(() => screen.getAllByAltText(alt), index);
|
|
18
|
+
atAlt = (alt, index) => new ElementTester(() => this.byAlt(alt, index));
|
|
19
|
+
byId = (id, index) => byIndex(() => screen.getAllByTestId(id.toString()), index);
|
|
20
|
+
atId = (id, index) => new ElementTester(() => this.byId(id, index));
|
|
21
|
+
byLabel = (label, index) => byIndex(() => screen.getAllByLabelText(label), index);
|
|
22
|
+
atLabel = (label, index) => new ElementTester(() => this.byLabel(label, index));
|
|
23
|
+
byPlaceholder = (placeholder, index) => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);
|
|
24
|
+
atPlaceholder = (placeholder, index) => new ElementTester(() => this.byPlaceholder(placeholder, index));
|
|
25
|
+
byHref = (href, index) => this.byQuery(`a[href*="${asString(href)}"]`, index);
|
|
26
|
+
atHref = (href, index) => new ElementTester(() => this.byHref(href, index));
|
|
27
|
+
byQuery = (query, index) => byIndex(() => Array.from(this.container.querySelectorAll(query)), index);
|
|
28
|
+
atQuery = (query, index) => new ElementTester(() => this.byQuery(query, index));
|
|
29
|
+
byRole = (role, index) => byIndex(() => screen.getAllByRole(role), index);
|
|
30
|
+
atRole = (role, index) => new ElementTester(() => this.byRole(role, index));
|
|
31
|
+
byRow = (index) => byIndex(() => screen.getAllByRole("row"), index);
|
|
32
|
+
atRow = (index) => new ElementTester(() => this.byRow(index));
|
|
33
|
+
byText = (text, index) => byIndex(() => screen.getAllByText(text), index);
|
|
34
|
+
atText = (text, index) => new ElementTester(() => this.byText(text, index));
|
|
35
|
+
byTitle = (title, index) => byIndex(() => screen.getAllByTitle(title), index);
|
|
36
|
+
atTitle = (title, index) => new ElementTester(() => this.byTitle(title, index));
|
|
37
|
+
byValue = (value, index) => byIndex(() => screen.getAllByDisplayValue(value), index);
|
|
38
|
+
atValue = (value, index) => new ElementTester(() => this.byValue(value, index));
|
|
39
|
+
byField = (field, index) => this.byQuery([
|
|
40
|
+
"input",
|
|
41
|
+
"select",
|
|
42
|
+
"textarea"
|
|
43
|
+
].map((t) => `${t}[name="${asString(field)}"]`).join(), index);
|
|
44
|
+
atField = (field, index) => new ElementTester(() => this.byField(field, index));
|
|
45
|
+
byName = (name, index) => this.byField(name, index);
|
|
46
|
+
atName = (name, index) => this.atField(name, index);
|
|
47
|
+
submit = (id = "btn-submit") => this.atId(id);
|
|
48
|
+
debug = () => screen.debug();
|
|
49
|
+
};
|
|
50
|
+
const rendersWait = async (component) => await Tester.render(component);
|
|
51
|
+
const renders = (component) => Tester.renderSync(component);
|
|
52
|
+
//#endregion
|
|
53
|
+
export { Tester, renders, rendersWait };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=Tester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tester.js","names":[],"sources":["../src/Tester.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 byField = (field: Id, index?: number): HTMLElement => this.byQuery(['input', 'select', 'textarea'].map(t => `${t}[name=\"${asString(field)}\"]`).join(), index);\n\n atField = (field: Id, index?: number): ElementTester => new ElementTester(() => this.byField(field, index));\n\n byName = (name: Id, index?: number): HTMLElement => this.byField(name, index);\n\n atName = (name: Id, index?: number): ElementTester => this.atField(name, 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"],"mappings":";;;;;AAMA,MAAM,WAAW,QAA6B,QAAgB,MAAmB,OAAO,CAAC,CAAC;AAE1F,IAAa,SAAb,MAAa,OAAO;CACU;CAA5B,YAAY,WAAwC;EAAxB,KAAA,YAAA;CAAyB;CAErD,IAAI,UAAmB;EACrB,OAAO,KAAK,UAAU,cAAc;CACtC;CAEA,OAAO,UAAU,cAA6C,cAAc,SAAS,CAAC,CAAC,MAAK,MAAK,IAAI,OAAO,EAAE,SAAS,CAAC;CAExH,OAAO,cAAc,cAAoC,IAAI,OAAO,OAAO,SAAS,CAAC,CAAC,SAAS;CAE/F,SAAS,KAAa,UAAgC,cAAc,OAAO,gBAAgB,GAAG,GAAG,KAAK;CAEtG,SAAS,KAAa,UAAkC,IAAI,oBAAoB,KAAK,MAAM,KAAK,KAAK,CAAC;CAEtG,QAAQ,IAAQ,UAAgC,cAAc,OAAO,eAAe,GAAG,SAAS,CAAC,GAAG,KAAK;CAEzG,QAAQ,IAAQ,UAAkC,IAAI,oBAAoB,KAAK,KAAK,IAAI,KAAK,CAAC;CAE9F,WAAW,OAAe,UAAgC,cAAc,OAAO,kBAAkB,KAAK,GAAG,KAAK;CAE9G,WAAW,OAAe,UAAkC,IAAI,oBAAoB,KAAK,QAAQ,OAAO,KAAK,CAAC;CAE9G,iBAAiB,aAAqB,UAAgC,cAAc,OAAO,wBAAwB,WAAW,GAAG,KAAK;CAEtI,iBAAiB,aAAqB,UAAkC,IAAI,oBAAoB,KAAK,cAAc,aAAa,KAAK,CAAC;CAEtI,UAAU,MAAoB,UAAgC,KAAK,QAAQ,YAAY,SAAS,IAAI,EAAE,KAAK,KAAK;CAEhH,UAAU,MAAoB,UAAkC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AK,EAAE;CAC/D,cAAc,OAAO,MAAM;AAC7B;AAEA,MAAa,cAAc,OAAO,cAA6C,MAAM,OAAO,OAAO,SAAS;AAC5G,MAAa,WAAW,cAAoC,OAAO,WAAW,SAAS"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { Tester, renders, rendersWait } from "./Tester.js";
|
|
2
|
+
import { ElementTester } from "./ElementTester.js";
|
|
3
|
+
import { waitForRender } from "./waitForRender.js";
|
|
4
|
+
//#region src/index.d.ts
|
|
4
5
|
export declare const mockTimezone: () => void;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { ElementTester, Tester, renders, rendersWait, waitForRender };
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,137 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
ElementTester: () => ElementTester,
|
|
24
|
-
Tester: () => Tester,
|
|
25
|
-
mockTimezone: () => mockTimezone,
|
|
26
|
-
renders: () => renders,
|
|
27
|
-
rendersWait: () => rendersWait,
|
|
28
|
-
waitForRender: () => waitForRender
|
|
29
|
-
});
|
|
30
|
-
module.exports = __toCommonJS(src_exports);
|
|
31
|
-
|
|
32
|
-
// src/ElementTester.ts
|
|
33
|
-
var import_react4 = require("@testing-library/react");
|
|
34
|
-
var import_easy2 = require("@thisisagile/easy");
|
|
35
|
-
|
|
36
|
-
// src/Tester.ts
|
|
37
|
-
var import_react3 = require("@testing-library/react");
|
|
38
|
-
var import_easy = require("@thisisagile/easy");
|
|
39
|
-
|
|
40
|
-
// src/waitForRender.ts
|
|
41
|
-
var import_react = require("@testing-library/react");
|
|
42
|
-
var import_react2 = require("react");
|
|
43
|
-
async function waitForRender(ui, options) {
|
|
44
|
-
let r = {};
|
|
45
|
-
await (0, import_react2.act)(async () => {
|
|
46
|
-
r = (0, import_react.render)(ui, options);
|
|
47
|
-
await (0, import_react.waitFor)(() => r.container, { container: r.container });
|
|
48
|
-
});
|
|
49
|
-
return r;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// src/Tester.ts
|
|
53
|
-
var byIndex = (getAll, index = 0) => getAll()[index];
|
|
54
|
-
var Tester = class _Tester {
|
|
55
|
-
constructor(container) {
|
|
56
|
-
this.container = container;
|
|
57
|
-
}
|
|
58
|
-
get isEmpty() {
|
|
59
|
-
return this.container.innerHTML === "";
|
|
60
|
-
}
|
|
61
|
-
static render = (component) => waitForRender(component).then((c) => new _Tester(c.container));
|
|
62
|
-
static renderSync = (component) => new _Tester((0, import_react3.render)(component).container);
|
|
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);
|
|
66
|
-
atId = (id, index) => new ElementTester(() => this.byId(id, index));
|
|
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);
|
|
76
|
-
atRole = (role, index) => new ElementTester(() => this.byRole(role, index));
|
|
77
|
-
byRow = (index) => byIndex(() => import_react3.screen.getAllByRole("row"), index);
|
|
78
|
-
atRow = (index) => new ElementTester(() => this.byRow(index));
|
|
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);
|
|
82
|
-
atTitle = (title, index) => new ElementTester(() => this.byTitle(title, index));
|
|
83
|
-
byValue = (value, index) => byIndex(() => import_react3.screen.getAllByDisplayValue(value), index);
|
|
84
|
-
atValue = (value, index) => new ElementTester(() => this.byValue(value, index));
|
|
85
|
-
byField = (field, index) => this.byQuery(["input", "select", "textarea"].map((t) => `${t}[name="${(0, import_easy.asString)(field)}"]`).join(), index);
|
|
86
|
-
atField = (field, index) => new ElementTester(() => this.byField(field, index));
|
|
87
|
-
byName = (name, index) => this.byField(name, index);
|
|
88
|
-
atName = (name, index) => this.atField(name, index);
|
|
89
|
-
submit = (id = "btn-submit") => this.atId(id);
|
|
90
|
-
debug = () => import_react3.screen.debug();
|
|
91
|
-
};
|
|
92
|
-
var rendersWait = async (component) => await Tester.render(component);
|
|
93
|
-
var renders = (component) => Tester.renderSync(component);
|
|
94
|
-
|
|
95
|
-
// src/ElementTester.ts
|
|
96
|
-
var ElementTester = class {
|
|
97
|
-
constructor(element) {
|
|
98
|
-
this.element = element;
|
|
99
|
-
}
|
|
100
|
-
get value() {
|
|
101
|
-
return this.element()?.value;
|
|
102
|
-
}
|
|
103
|
-
get isValid() {
|
|
104
|
-
return (0, import_easy2.tryTo)(() => this.element()).is.defined().map(() => true).or(false);
|
|
105
|
-
}
|
|
106
|
-
get then() {
|
|
107
|
-
return new Tester(this.element());
|
|
108
|
-
}
|
|
109
|
-
click = () => this.element() && import_react4.fireEvent.click(this.element()) ? this : void 0;
|
|
110
|
-
awaitClick = () => (0, import_react4.waitFor)(() => import_react4.fireEvent.click(this.element()));
|
|
111
|
-
submit = () => this.element() && import_react4.fireEvent.submit(this.element()) ? this : void 0;
|
|
112
|
-
awaitSubmit = () => (0, import_react4.waitFor)(() => import_react4.fireEvent.submit(this.element()));
|
|
113
|
-
keyDown = (key) => this.element() && import_react4.fireEvent.keyDown(this.element(), { key }) ? this : void 0;
|
|
114
|
-
mouseDown = (index) => this.element() && import_react4.fireEvent.mouseDown((0, import_easy2.isDefined)(index) ? this.element().children[index] : this.element()) ? this : void 0;
|
|
115
|
-
pressEnter = () => this.keyDown("Enter");
|
|
116
|
-
clear = () => this.type("");
|
|
117
|
-
type = (value) => import_react4.fireEvent.change(this.element(), { target: { value } });
|
|
118
|
-
blur = () => this.element() && import_react4.fireEvent.blur(this.element()) ? this : void 0;
|
|
119
|
-
wait = () => (0, import_react4.waitFor)(this.element);
|
|
120
|
-
waitForRemove = () => (0, import_react4.waitForElementToBeRemoved)(this.element);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
// src/index.ts
|
|
124
|
-
var mockTimezone = () => {
|
|
125
|
-
jest.spyOn(Intl.DateTimeFormat.prototype, "resolvedOptions").mockReturnValue(Intl.DateTimeFormat("en-US", { timeZone: "UTC" }).resolvedOptions());
|
|
1
|
+
import { waitForRender } from "./waitForRender.js";
|
|
2
|
+
import { Tester, renders, rendersWait } from "./Tester.js";
|
|
3
|
+
import { ElementTester } from "./ElementTester.js";
|
|
4
|
+
//#region src/index.ts
|
|
5
|
+
const mockTimezone = () => {
|
|
6
|
+
jest.spyOn(Intl.DateTimeFormat.prototype, "resolvedOptions").mockReturnValue(Intl.DateTimeFormat("en-US", { timeZone: "UTC" }).resolvedOptions());
|
|
126
7
|
};
|
|
127
8
|
mockTimezone();
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
Tester,
|
|
132
|
-
mockTimezone,
|
|
133
|
-
renders,
|
|
134
|
-
rendersWait,
|
|
135
|
-
waitForRender
|
|
136
|
-
});
|
|
9
|
+
//#endregion
|
|
10
|
+
export { ElementTester, Tester, mockTimezone, renders, rendersWait, waitForRender };
|
|
11
|
+
|
|
137
12
|
//# sourceMappingURL=index.js.map
|
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 submit = (): this | undefined => (this.element() && fireEvent.submit(this.element()) ? this : undefined);\n awaitSubmit = (): Promise<boolean> => waitFor(() => fireEvent.submit(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 blur = (): this | undefined => (this.element() && fireEvent.blur(this.element()) ? this : undefined);\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 byField = (field: Id, index?: number): HTMLElement => this.byQuery(['input', 'select', 'textarea'].map(t => `${t}[name=\"${asString(field)}\"]`).join(), index);\n\n atField = (field: Id, index?: number): ElementTester => new ElementTester(() => this.byField(field, index));\n\n byName = (name: Id, index?: number): HTMLElement => this.byField(name, index);\n\n atName = (name: Id, index?: number): ElementTester => this.atField(name, 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,Q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K,OAAO;AAAA,EACnD,gBAAgB,UAAqB,yCAA0B,KAAK,OAAO;AAC7E;;;AD/BO,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"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.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"],"mappings":";;;;AAIA,MAAa,qBAAqB;CAChC,KAAK,MAAM,KAAK,eAAe,WAAW,iBAAiB,CAAC,CAAC,gBAAgB,KAAK,eAAe,SAAS,EAAE,UAAU,MAAM,CAAC,CAAC,CAAC,gBAAgB,CAAC;AAClJ;AACA,aAAa"}
|
package/dist/waitForRender.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
import { RenderOptions, RenderResult } from
|
|
2
|
-
import { ReactElement } from
|
|
1
|
+
import { RenderOptions, RenderResult } from "@testing-library/react";
|
|
2
|
+
import { ReactElement } from "react";
|
|
3
|
+
//#region src/waitForRender.d.ts
|
|
3
4
|
export declare function waitForRender(ui: ReactElement, options?: Omit<RenderOptions, 'queries'>): Promise<RenderResult>;
|
|
5
|
+
//#endregion
|
|
6
|
+
//# sourceMappingURL=waitForRender.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { render, waitFor } from "@testing-library/react";
|
|
2
|
+
import { act } from "react";
|
|
3
|
+
//#region src/waitForRender.ts
|
|
4
|
+
/* istanbul ignore next */
|
|
5
|
+
async function waitForRender(ui, options) {
|
|
6
|
+
let r = {};
|
|
7
|
+
await act(async () => {
|
|
8
|
+
r = render(ui, options);
|
|
9
|
+
await waitFor(() => r.container, { container: r.container });
|
|
10
|
+
});
|
|
11
|
+
return r;
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
export { waitForRender };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=waitForRender.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"waitForRender.js","names":[],"sources":["../src/waitForRender.ts"],"sourcesContent":["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":";;;;AAIA,eAAsB,cAAc,IAAkB,SAAiE;CACrH,IAAI,IAAI,CAAC;CAET,MAAM,IAAI,YAAY;EACpB,IAAI,OAAO,IAAI,OAAO;EACtB,MAAM,cAAc,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,CAAC;CAC7D,CAAC;CACD,OAAO;AACT"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thisisagile/easy-test-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.0.0",
|
|
4
4
|
"description": "Straightforward wrapper library for testing-library/react",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"main": "dist/index.js",
|
|
8
|
-
"module": "dist/index.
|
|
9
|
+
"module": "dist/index.js",
|
|
9
10
|
"types": "dist/index.d.ts",
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
@@ -22,8 +23,7 @@
|
|
|
22
23
|
"scripts": {
|
|
23
24
|
"lint": "yarn g:eslint . --ext .js,.jsx,.ts,.tsx --fix",
|
|
24
25
|
"format": "yarn g:prettier --check --write src test *.json",
|
|
25
|
-
"build": "yarn
|
|
26
|
-
"build:tsup": "yarn g:tsup && yarn g:tsc --emitDeclarationOnly --declaration",
|
|
26
|
+
"build": "yarn g:tsdown && yarn g:exports",
|
|
27
27
|
"test": "yarn g:jest --coverage",
|
|
28
28
|
"prepack": "yarn g:copy-readme"
|
|
29
29
|
},
|
|
@@ -35,6 +35,9 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=20.19.0"
|
|
40
|
+
},
|
|
38
41
|
"devDependencies": {
|
|
39
42
|
"@thisisagile/easy-test": "*",
|
|
40
43
|
"jest-environment-jsdom": "^29.7.0",
|
|
@@ -44,7 +47,7 @@
|
|
|
44
47
|
"@testing-library/dom": "^10.4.0",
|
|
45
48
|
"@testing-library/jest-dom": "^6.6.3",
|
|
46
49
|
"@testing-library/react": "^16.3.0",
|
|
47
|
-
"@thisisagile/easy": "^
|
|
50
|
+
"@thisisagile/easy": "^20.0.0",
|
|
48
51
|
"@types/react": "^18.3.18",
|
|
49
52
|
"react": "^18.3.1",
|
|
50
53
|
"react-dom": "^18.3.1"
|
|
@@ -52,20 +55,19 @@
|
|
|
52
55
|
"exports": {
|
|
53
56
|
".": {
|
|
54
57
|
"types": "./dist/index.d.ts",
|
|
55
|
-
"
|
|
56
|
-
"require": "./dist/index.js"
|
|
58
|
+
"default": "./dist/index.js"
|
|
57
59
|
},
|
|
58
60
|
"./ElementTester": {
|
|
59
61
|
"types": "./dist/ElementTester.d.ts",
|
|
60
|
-
"
|
|
62
|
+
"default": "./dist/ElementTester.js"
|
|
61
63
|
},
|
|
62
64
|
"./Tester": {
|
|
63
65
|
"types": "./dist/Tester.d.ts",
|
|
64
|
-
"
|
|
66
|
+
"default": "./dist/Tester.js"
|
|
65
67
|
},
|
|
66
68
|
"./waitForRender": {
|
|
67
69
|
"types": "./dist/waitForRender.d.ts",
|
|
68
|
-
"
|
|
70
|
+
"default": "./dist/waitForRender.js"
|
|
69
71
|
},
|
|
70
72
|
"./src/*": "./src/*",
|
|
71
73
|
"./dist/*": "./dist/*",
|
package/dist/ElementTester.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/Tester.mjs
DELETED
package/dist/Tester.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/chunk-DAQNFE75.mjs
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
waitForRender
|
|
3
|
-
} from "./chunk-UIR5DDLV.mjs";
|
|
4
|
-
|
|
5
|
-
// src/Tester.ts
|
|
6
|
-
import { render, screen } from "@testing-library/react";
|
|
7
|
-
import { asString } from "@thisisagile/easy";
|
|
8
|
-
|
|
9
|
-
// src/ElementTester.ts
|
|
10
|
-
import { fireEvent, waitFor, waitForElementToBeRemoved } from "@testing-library/react";
|
|
11
|
-
import { isDefined, tryTo } from "@thisisagile/easy";
|
|
12
|
-
var ElementTester = class {
|
|
13
|
-
constructor(element) {
|
|
14
|
-
this.element = element;
|
|
15
|
-
}
|
|
16
|
-
get value() {
|
|
17
|
-
return this.element()?.value;
|
|
18
|
-
}
|
|
19
|
-
get isValid() {
|
|
20
|
-
return tryTo(() => this.element()).is.defined().map(() => true).or(false);
|
|
21
|
-
}
|
|
22
|
-
get then() {
|
|
23
|
-
return new Tester(this.element());
|
|
24
|
-
}
|
|
25
|
-
click = () => this.element() && fireEvent.click(this.element()) ? this : void 0;
|
|
26
|
-
awaitClick = () => waitFor(() => fireEvent.click(this.element()));
|
|
27
|
-
submit = () => this.element() && fireEvent.submit(this.element()) ? this : void 0;
|
|
28
|
-
awaitSubmit = () => waitFor(() => fireEvent.submit(this.element()));
|
|
29
|
-
keyDown = (key) => this.element() && fireEvent.keyDown(this.element(), { key }) ? this : void 0;
|
|
30
|
-
mouseDown = (index) => this.element() && fireEvent.mouseDown(isDefined(index) ? this.element().children[index] : this.element()) ? this : void 0;
|
|
31
|
-
pressEnter = () => this.keyDown("Enter");
|
|
32
|
-
clear = () => this.type("");
|
|
33
|
-
type = (value) => fireEvent.change(this.element(), { target: { value } });
|
|
34
|
-
blur = () => this.element() && fireEvent.blur(this.element()) ? this : void 0;
|
|
35
|
-
wait = () => waitFor(this.element);
|
|
36
|
-
waitForRemove = () => waitForElementToBeRemoved(this.element);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
// src/Tester.ts
|
|
40
|
-
var byIndex = (getAll, index = 0) => getAll()[index];
|
|
41
|
-
var Tester = class _Tester {
|
|
42
|
-
constructor(container) {
|
|
43
|
-
this.container = container;
|
|
44
|
-
}
|
|
45
|
-
get isEmpty() {
|
|
46
|
-
return this.container.innerHTML === "";
|
|
47
|
-
}
|
|
48
|
-
static render = (component) => waitForRender(component).then((c) => new _Tester(c.container));
|
|
49
|
-
static renderSync = (component) => new _Tester(render(component).container);
|
|
50
|
-
byAlt = (alt, index) => byIndex(() => screen.getAllByAltText(alt), index);
|
|
51
|
-
atAlt = (alt, index) => new ElementTester(() => this.byAlt(alt, index));
|
|
52
|
-
byId = (id, index) => byIndex(() => screen.getAllByTestId(id.toString()), index);
|
|
53
|
-
atId = (id, index) => new ElementTester(() => this.byId(id, index));
|
|
54
|
-
byLabel = (label, index) => byIndex(() => screen.getAllByLabelText(label), index);
|
|
55
|
-
atLabel = (label, index) => new ElementTester(() => this.byLabel(label, index));
|
|
56
|
-
byPlaceholder = (placeholder, index) => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);
|
|
57
|
-
atPlaceholder = (placeholder, index) => new ElementTester(() => this.byPlaceholder(placeholder, index));
|
|
58
|
-
byHref = (href, index) => this.byQuery(`a[href*="${asString(href)}"]`, index);
|
|
59
|
-
atHref = (href, index) => new ElementTester(() => this.byHref(href, index));
|
|
60
|
-
byQuery = (query, index) => byIndex(() => Array.from(this.container.querySelectorAll(query)), index);
|
|
61
|
-
atQuery = (query, index) => new ElementTester(() => this.byQuery(query, index));
|
|
62
|
-
byRole = (role, index) => byIndex(() => screen.getAllByRole(role), index);
|
|
63
|
-
atRole = (role, index) => new ElementTester(() => this.byRole(role, index));
|
|
64
|
-
byRow = (index) => byIndex(() => screen.getAllByRole("row"), index);
|
|
65
|
-
atRow = (index) => new ElementTester(() => this.byRow(index));
|
|
66
|
-
byText = (text, index) => byIndex(() => screen.getAllByText(text), index);
|
|
67
|
-
atText = (text, index) => new ElementTester(() => this.byText(text, index));
|
|
68
|
-
byTitle = (title, index) => byIndex(() => screen.getAllByTitle(title), index);
|
|
69
|
-
atTitle = (title, index) => new ElementTester(() => this.byTitle(title, index));
|
|
70
|
-
byValue = (value, index) => byIndex(() => screen.getAllByDisplayValue(value), index);
|
|
71
|
-
atValue = (value, index) => new ElementTester(() => this.byValue(value, index));
|
|
72
|
-
byField = (field, index) => this.byQuery(["input", "select", "textarea"].map((t) => `${t}[name="${asString(field)}"]`).join(), index);
|
|
73
|
-
atField = (field, index) => new ElementTester(() => this.byField(field, index));
|
|
74
|
-
byName = (name, index) => this.byField(name, index);
|
|
75
|
-
atName = (name, index) => this.atField(name, index);
|
|
76
|
-
submit = (id = "btn-submit") => this.atId(id);
|
|
77
|
-
debug = () => screen.debug();
|
|
78
|
-
};
|
|
79
|
-
var rendersWait = async (component) => await Tester.render(component);
|
|
80
|
-
var renders = (component) => Tester.renderSync(component);
|
|
81
|
-
|
|
82
|
-
export {
|
|
83
|
-
Tester,
|
|
84
|
-
rendersWait,
|
|
85
|
-
renders,
|
|
86
|
-
ElementTester
|
|
87
|
-
};
|
|
88
|
-
//# sourceMappingURL=chunk-DAQNFE75.mjs.map
|
|
@@ -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 { 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 byField = (field: Id, index?: number): HTMLElement => this.byQuery(['input', 'select', 'textarea'].map(t => `${t}[name=\"${asString(field)}\"]`).join(), index);\n\n atField = (field: Id, index?: number): ElementTester => new ElementTester(() => this.byField(field, index));\n\n byName = (name: Id, index?: number): HTMLElement => this.byField(name, index);\n\n atName = (name: Id, index?: number): ElementTester => this.atField(name, 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 submit = (): this | undefined => (this.element() && fireEvent.submit(this.element()) ? this : undefined);\n awaitSubmit = (): Promise<boolean> => waitFor(() => fireEvent.submit(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 blur = (): this | undefined => (this.element() && fireEvent.blur(this.element()) ? this : undefined);\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,SAAS,MAAyB,KAAK,QAAQ,KAAK,UAAU,OAAO,KAAK,QAAQ,CAAC,IAAI,OAAO;AAAA,EAC9F,cAAc,MAAwB,QAAQ,MAAM,UAAU,OAAO,KAAK,QAAQ,CAAC,CAAC;AAAA,EACpF,UAAU,CA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AI,GAAG,KAAK;AAAA,EAEtG,SAAS,CAAC,MAAc,UAAkC,IAAI,cAAc,MAAM,KAAK,OAAO,MAAM,KAAK,CAAC;AAAA,EAE1G,UAAU,CAAC,OAAe,UAAgC,QAAQ,MAAM,OAAO,cAAc,KAAK,GAAG,KAAK;AAAA,EAE1G,UAAU,CAAC,OAAe,UAAkC,IAAI,cAAc,MAAM,KAAK,QAAQ,OAAO,KAAK,CAAC;AAAA,EAE9G,UAAU,CAAC,OAAe,UAAgC,QAAQ,MAAM,OAAO,qBAAqB,KAAK,GAAG,KAAK;AAAA,EAEjH,UAAU,CAAC,OAAe,UAAkC,IAAI,cAAc,MAAM,KAAK,QAAQ,OAAO,KAAK,CAAC;AAAA,EAE9G,UAAU,CAAC,OAAW,UAAgC,KAAK,QAAQ,CAAC,SAAS,UAAU,UAAU,EAAE,IAAI,OAAK,GAAG,CAAC,UAAU,SAAS,KAAK,CAAC,IAAI,EAAE,KAAK,GAAG,KAAK;AAAA,EAE5J,UAAU,CAAC,OAAW,UAAkC,IAAI,cAAc,MAAM,KAAK,QAAQ,OAAO,KAAK,CAAC;AAAA,EAE1G,SAAS,CAAC,MAAU,UAAgC,KAAK,QAAQ,MAAM,KAAK;AAAA,EAE5E,SAAS,CAAC,MAAU,UAAkC,KAAK,QAAQ,MAAM,KAAK;AAAA,EAE9E,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/chunk-UIR5DDLV.mjs
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// src/waitForRender.ts
|
|
2
|
-
import { render, waitFor } from "@testing-library/react";
|
|
3
|
-
import { act } from "react";
|
|
4
|
-
async function waitForRender(ui, options) {
|
|
5
|
-
let r = {};
|
|
6
|
-
await act(async () => {
|
|
7
|
-
r = render(ui, options);
|
|
8
|
-
await waitFor(() => r.container, { container: r.container });
|
|
9
|
-
});
|
|
10
|
-
return r;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
waitForRender
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=chunk-UIR5DDLV.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/waitForRender.ts"],"sourcesContent":["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,SAAS,QAAqC,eAAe;AAC7D,SAAS,WAAyB;AAGlC,eAAsB,cAAc,IAAkB,SAAiE;AACrH,MAAI,IAAI,CAAC;AAET,QAAM,IAAI,YAAY;AACpB,QAAI,OAAO,IAAI,OAAO;AACtB,UAAM,QAAQ,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,CAAC;AAAA,EAC7D,CAAC;AACD,SAAO;AACT;","names":[]}
|
package/dist/index.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ElementTester,
|
|
3
|
-
Tester,
|
|
4
|
-
renders,
|
|
5
|
-
rendersWait
|
|
6
|
-
} from "./chunk-DAQNFE75.mjs";
|
|
7
|
-
import {
|
|
8
|
-
waitForRender
|
|
9
|
-
} from "./chunk-UIR5DDLV.mjs";
|
|
10
|
-
|
|
11
|
-
// src/index.ts
|
|
12
|
-
var mockTimezone = () => {
|
|
13
|
-
jest.spyOn(Intl.DateTimeFormat.prototype, "resolvedOptions").mockReturnValue(Intl.DateTimeFormat("en-US", { timeZone: "UTC" }).resolvedOptions());
|
|
14
|
-
};
|
|
15
|
-
mockTimezone();
|
|
16
|
-
export {
|
|
17
|
-
ElementTester,
|
|
18
|
-
Tester,
|
|
19
|
-
mockTimezone,
|
|
20
|
-
renders,
|
|
21
|
-
rendersWait,
|
|
22
|
-
waitForRender
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.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"],"mappings":";;;;;;;;;;;AAIO,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":[]}
|
package/dist/waitForRender.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|