@thisisagile/easy-test-react 17.30.9 → 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.
- package/dist/ElementTester.mjs +1 -1
- package/dist/Tester.d.ts +4 -2
- package/dist/Tester.mjs +1 -1
- package/dist/{chunk-W2RE3ASH.mjs → chunk-ENAZCQPP.mjs} +7 -4
- package/dist/chunk-ENAZCQPP.mjs.map +1 -0
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/Tester.ts +30 -2
- package/dist/chunk-W2RE3ASH.mjs.map +0 -1
package/dist/ElementTester.mjs
CHANGED
package/dist/Tester.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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
10
|
byAlt: (alt: string, index?: number) => HTMLElement;
|
|
@@ -14,6 +15,8 @@ export declare class Tester {
|
|
|
14
15
|
atLabel: (label: string, index?: number) => ElementTester;
|
|
15
16
|
byPlaceholder: (placeholder: string, index?: number) => HTMLElement;
|
|
16
17
|
atPlaceholder: (placeholder: string, index?: number) => ElementTester;
|
|
18
|
+
byHref: (href: string | Uri, index?: number) => HTMLElement;
|
|
19
|
+
atHref: (href: string | Uri, index?: number) => ElementTester;
|
|
17
20
|
byQuery: (query: string, index?: number) => HTMLElement;
|
|
18
21
|
atQuery: (query: string, index?: number) => ElementTester;
|
|
19
22
|
byRole: (role: string, index?: number) => HTMLElement;
|
|
@@ -26,7 +29,6 @@ export declare class Tester {
|
|
|
26
29
|
atTitle: (title: string, index?: number) => ElementTester;
|
|
27
30
|
byValue: (value: string, index?: number) => HTMLElement;
|
|
28
31
|
atValue: (value: string, index?: number) => ElementTester;
|
|
29
|
-
get isEmpty(): boolean;
|
|
30
32
|
submit: (id?: Id) => ElementTester;
|
|
31
33
|
debug: () => void;
|
|
32
34
|
}
|
package/dist/Tester.mjs
CHANGED
|
@@ -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";
|
|
@@ -38,6 +39,9 @@ var Tester = class _Tester {
|
|
|
38
39
|
constructor(container) {
|
|
39
40
|
this.container = container;
|
|
40
41
|
}
|
|
42
|
+
get isEmpty() {
|
|
43
|
+
return this.container.innerHTML === "";
|
|
44
|
+
}
|
|
41
45
|
static render = (component) => waitForRender(component).then((c) => new _Tester(c.container));
|
|
42
46
|
static renderSync = (component) => new _Tester(render(component).container);
|
|
43
47
|
byAlt = (alt, index) => byIndex(() => screen.getAllByAltText(alt), index);
|
|
@@ -48,6 +52,8 @@ var Tester = class _Tester {
|
|
|
48
52
|
atLabel = (label, index) => new ElementTester(() => this.byLabel(label, index));
|
|
49
53
|
byPlaceholder = (placeholder, index) => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);
|
|
50
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));
|
|
51
57
|
byQuery = (query, index) => byIndex(() => Array.from(this.container.querySelectorAll(query)), index);
|
|
52
58
|
atQuery = (query, index) => new ElementTester(() => this.byQuery(query, index));
|
|
53
59
|
byRole = (role, index) => byIndex(() => screen.getAllByRole(role), index);
|
|
@@ -60,9 +66,6 @@ var Tester = class _Tester {
|
|
|
60
66
|
atTitle = (title, index) => new ElementTester(() => this.byTitle(title, index));
|
|
61
67
|
byValue = (value, index) => byIndex(() => screen.getAllByDisplayValue(value), index);
|
|
62
68
|
atValue = (value, index) => new ElementTester(() => this.byValue(value, index));
|
|
63
|
-
get isEmpty() {
|
|
64
|
-
return this.container.innerHTML === "";
|
|
65
|
-
}
|
|
66
69
|
submit = (id = "btn-submit") => this.atId(id);
|
|
67
70
|
debug = () => screen.debug();
|
|
68
71
|
};
|
|
@@ -75,4 +78,4 @@ export {
|
|
|
75
78
|
renders,
|
|
76
79
|
ElementTester
|
|
77
80
|
};
|
|
78
|
-
//# sourceMappingURL=chunk-
|
|
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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AAA,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,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
|
|
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");
|
|
@@ -54,6 +55,9 @@ var Tester = class _Tester {
|
|
|
54
55
|
constructor(container) {
|
|
55
56
|
this.container = container;
|
|
56
57
|
}
|
|
58
|
+
get isEmpty() {
|
|
59
|
+
return this.container.innerHTML === "";
|
|
60
|
+
}
|
|
57
61
|
static render = (component) => waitForRender(component).then((c) => new _Tester(c.container));
|
|
58
62
|
static renderSync = (component) => new _Tester((0, import_react3.render)(component).container);
|
|
59
63
|
byAlt = (alt, index) => byIndex(() => import_react3.screen.getAllByAltText(alt), index);
|
|
@@ -64,6 +68,8 @@ var Tester = class _Tester {
|
|
|
64
68
|
atLabel = (label, index) => new ElementTester(() => this.byLabel(label, index));
|
|
65
69
|
byPlaceholder = (placeholder, index) => byIndex(() => import_react3.screen.getAllByPlaceholderText(placeholder), index);
|
|
66
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));
|
|
67
73
|
byQuery = (query, index) => byIndex(() => Array.from(this.container.querySelectorAll(query)), index);
|
|
68
74
|
atQuery = (query, index) => new ElementTester(() => this.byQuery(query, index));
|
|
69
75
|
byRole = (role, index) => byIndex(() => import_react3.screen.getAllByRole(role), index);
|
|
@@ -76,9 +82,6 @@ var Tester = class _Tester {
|
|
|
76
82
|
atTitle = (title, index) => new ElementTester(() => this.byTitle(title, index));
|
|
77
83
|
byValue = (value, index) => byIndex(() => import_react3.screen.getAllByDisplayValue(value), index);
|
|
78
84
|
atValue = (value, index) => new ElementTester(() => this.byValue(value, index));
|
|
79
|
-
get isEmpty() {
|
|
80
|
-
return this.container.innerHTML === "";
|
|
81
|
-
}
|
|
82
85
|
submit = (id = "btn-submit") => this.atId(id);
|
|
83
86
|
debug = () => import_react3.screen.debug();
|
|
84
87
|
};
|
|
@@ -94,7 +97,7 @@ var ElementTester = class {
|
|
|
94
97
|
return this.element()?.value;
|
|
95
98
|
}
|
|
96
99
|
get isValid() {
|
|
97
|
-
return (0,
|
|
100
|
+
return (0, import_easy2.tryTo)(() => this.element()).is.defined().map(() => true).or(false);
|
|
98
101
|
}
|
|
99
102
|
get then() {
|
|
100
103
|
return new Tester(this.element());
|
|
@@ -102,7 +105,7 @@ var ElementTester = class {
|
|
|
102
105
|
click = () => this.element() && import_react4.fireEvent.click(this.element()) ? this : void 0;
|
|
103
106
|
awaitClick = () => (0, import_react4.waitFor)(() => import_react4.fireEvent.click(this.element()));
|
|
104
107
|
keyDown = (key) => this.element() && import_react4.fireEvent.keyDown(this.element(), { key }) ? this : void 0;
|
|
105
|
-
mouseDown = (index) => this.element() && import_react4.fireEvent.mouseDown((0,
|
|
108
|
+
mouseDown = (index) => this.element() && import_react4.fireEvent.mouseDown((0, import_easy2.isDefined)(index) ? this.element().children[index] : this.element()) ? this : void 0;
|
|
106
109
|
pressEnter = () => this.keyDown("Enter");
|
|
107
110
|
clear = () => this.type("");
|
|
108
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\nconst byIndex = (getAll: () => HTMLElement[], index: number = 0): HTMLElement => getAll()[index];\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 byAlt = (alt: string, index?: number): HTMLElement => byIndex(() => screen.getAllByAltText(alt), index);\n atAlt = (alt: string, index?: number): ElementTester => new ElementTester(() => this.byAlt(alt, index));\n byId = (id: Id, index?: number): HTMLElement => byIndex(() => screen.getAllByTestId(id.toString()), index);\n atId = (id: Id, index?: number): ElementTester => new ElementTester(() => this.byId(id, index));\n byLabel = (label: string, index?: number): HTMLElement => byIndex(() => screen.getAllByLabelText(label), index);\n atLabel = (label: string, index?: number): ElementTester => new ElementTester(() => this.byLabel(label, index));\n byPlaceholder = (placeholder: string, index?: number): HTMLElement => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);\n atPlaceholder = (placeholder: string, index?: number): ElementTester => new ElementTester(() => this.byPlaceholder(placeholder, index));\n byQuery = (query: string, index?: number): HTMLElement => byIndex(() => Array.from(this.container.querySelectorAll<HTMLElement>(query)), index);\n atQuery = (query: string, index?: number): ElementTester => new ElementTester(() => this.byQuery(query, index));\n byRole = (role: string, index?: number): HTMLElement => byIndex(() => screen.getAllByRole(role), index);\n atRole = (role: string, index?: number): ElementTester => new ElementTester(() => this.byRole(role, index));\n byRow = (index?: number): HTMLElement => byIndex(() => screen.getAllByRole('row'), index);\n atRow = (index?: number): ElementTester => new ElementTester(() => this.byRow(index));\n byText = (text: string, index?: number): HTMLElement => byIndex(() => screen.getAllByText(text), index);\n atText = (text: string, index?: number): ElementTester => new ElementTester(() => this.byText(text, index));\n byTitle = (title: string, index?: number): HTMLElement => byIndex(() => screen.getAllByTitle(title), index);\n atTitle = (title: string, index?: number): ElementTester => new ElementTester(() => this.byTitle(title, index));\n byValue = (value: string, index?: number): HTMLElement => byIndex(() => screen.getAllByDisplayValue(value), index);\n atValue = (value: string, index?: number): ElementTester => new ElementTester(() => this.byValue(value, index));\n
|
|
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,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AAgB,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.
|
|
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.
|
|
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,6 +1,6 @@
|
|
|
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
|
|
|
@@ -9,30 +9,58 @@ const byIndex = (getAll: () => HTMLElement[], index: number = 0): HTMLElement =>
|
|
|
9
9
|
export class Tester {
|
|
10
10
|
constructor(public readonly container: HTMLElement) {}
|
|
11
11
|
|
|
12
|
+
get isEmpty(): boolean {
|
|
13
|
+
return this.container.innerHTML === '';
|
|
14
|
+
}
|
|
15
|
+
|
|
12
16
|
static render = (component: ReactElement): Promise<Tester> => waitForRender(component).then(c => new Tester(c.container));
|
|
17
|
+
|
|
13
18
|
static renderSync = (component: ReactElement): Tester => new Tester(render(component).container);
|
|
14
19
|
|
|
15
20
|
byAlt = (alt: string, index?: number): HTMLElement => byIndex(() => screen.getAllByAltText(alt), index);
|
|
21
|
+
|
|
16
22
|
atAlt = (alt: string, index?: number): ElementTester => new ElementTester(() => this.byAlt(alt, index));
|
|
23
|
+
|
|
17
24
|
byId = (id: Id, index?: number): HTMLElement => byIndex(() => screen.getAllByTestId(id.toString()), index);
|
|
25
|
+
|
|
18
26
|
atId = (id: Id, index?: number): ElementTester => new ElementTester(() => this.byId(id, index));
|
|
27
|
+
|
|
19
28
|
byLabel = (label: string, index?: number): HTMLElement => byIndex(() => screen.getAllByLabelText(label), index);
|
|
29
|
+
|
|
20
30
|
atLabel = (label: string, index?: number): ElementTester => new ElementTester(() => this.byLabel(label, index));
|
|
31
|
+
|
|
21
32
|
byPlaceholder = (placeholder: string, index?: number): HTMLElement => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);
|
|
33
|
+
|
|
22
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
|
+
|
|
23
40
|
byQuery = (query: string, index?: number): HTMLElement => byIndex(() => Array.from(this.container.querySelectorAll<HTMLElement>(query)), index);
|
|
41
|
+
|
|
24
42
|
atQuery = (query: string, index?: number): ElementTester => new ElementTester(() => this.byQuery(query, index));
|
|
43
|
+
|
|
25
44
|
byRole = (role: string, index?: number): HTMLElement => byIndex(() => screen.getAllByRole(role), index);
|
|
45
|
+
|
|
26
46
|
atRole = (role: string, index?: number): ElementTester => new ElementTester(() => this.byRole(role, index));
|
|
47
|
+
|
|
27
48
|
byRow = (index?: number): HTMLElement => byIndex(() => screen.getAllByRole('row'), index);
|
|
49
|
+
|
|
28
50
|
atRow = (index?: number): ElementTester => new ElementTester(() => this.byRow(index));
|
|
51
|
+
|
|
29
52
|
byText = (text: string, index?: number): HTMLElement => byIndex(() => screen.getAllByText(text), index);
|
|
53
|
+
|
|
30
54
|
atText = (text: string, index?: number): ElementTester => new ElementTester(() => this.byText(text, index));
|
|
55
|
+
|
|
31
56
|
byTitle = (title: string, index?: number): HTMLElement => byIndex(() => screen.getAllByTitle(title), index);
|
|
57
|
+
|
|
32
58
|
atTitle = (title: string, index?: number): ElementTester => new ElementTester(() => this.byTitle(title, index));
|
|
59
|
+
|
|
33
60
|
byValue = (value: string, index?: number): HTMLElement => byIndex(() => screen.getAllByDisplayValue(value), index);
|
|
61
|
+
|
|
34
62
|
atValue = (value: string, index?: number): ElementTester => new ElementTester(() => this.byValue(value, index));
|
|
35
|
-
|
|
63
|
+
|
|
36
64
|
submit = (id: Id = 'btn-submit'): ElementTester => this.atId(id);
|
|
37
65
|
debug = () => screen.debug();
|
|
38
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\nconst byIndex = (getAll: () => HTMLElement[], index: number = 0): HTMLElement => getAll()[index];\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 byAlt = (alt: string, index?: number): HTMLElement => byIndex(() => screen.getAllByAltText(alt), index);\n atAlt = (alt: string, index?: number): ElementTester => new ElementTester(() => this.byAlt(alt, index));\n byId = (id: Id, index?: number): HTMLElement => byIndex(() => screen.getAllByTestId(id.toString()), index);\n atId = (id: Id, index?: number): ElementTester => new ElementTester(() => this.byId(id, index));\n byLabel = (label: string, index?: number): HTMLElement => byIndex(() => screen.getAllByLabelText(label), index);\n atLabel = (label: string, index?: number): ElementTester => new ElementTester(() => this.byLabel(label, index));\n byPlaceholder = (placeholder: string, index?: number): HTMLElement => byIndex(() => screen.getAllByPlaceholderText(placeholder), index);\n atPlaceholder = (placeholder: string, index?: number): ElementTester => new ElementTester(() => this.byPlaceholder(placeholder, index));\n byQuery = (query: string, index?: number): HTMLElement => byIndex(() => Array.from(this.container.querySelectorAll<HTMLElement>(query)), index);\n atQuery = (query: string, index?: number): ElementTester => new ElementTester(() => this.byQuery(query, index));\n byRole = (role: string, index?: number): HTMLElement => byIndex(() => screen.getAllByRole(role), index);\n atRole = (role: string, index?: number): ElementTester => new ElementTester(() => this.byRole(role, index));\n byRow = (index?: number): HTMLElement => byIndex(() => screen.getAllByRole('row'), index);\n atRow = (index?: number): ElementTester => new ElementTester(() => this.byRow(index));\n byText = (text: string, index?: number): HTMLElement => byIndex(() => screen.getAllByText(text), index);\n atText = (text: string, index?: number): ElementTester => new ElementTester(() => this.byText(text, index));\n byTitle = (title: string, index?: number): HTMLElement => byIndex(() => screen.getAllByTitle(title), index);\n atTitle = (title: string, index?: number): ElementTester => new ElementTester(() => this.byTitle(title, index));\n byValue = (value: string, index?: number): HTMLElement => byIndex(() => screen.getAllByDisplayValue(value), index);\n atValue = (value: string, index?: number): ElementTester => new ElementTester(() => this.byValue(value, index));\n get isEmpty(): boolean { return this.container.innerHTML === ''; }\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,CAAgB;AAAA,EACjD;AAAA,EAEA,QAAQ,MAAyB,KAAK,QAAQ,KAAK,UAAU,MAAM,KAAK,QAAQ,CAAC,IAAI,OAAO;AAAA,EAC5F,aAAa,MAAwB,QAAQ,MAAM,UAAU,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