@thisisagile/easy-test-react 18.14.0 → 18.15.1
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 +1 -0
- package/dist/ElementTester.mjs +1 -1
- package/dist/Tester.d.ts +4 -0
- package/dist/Tester.mjs +1 -1
- package/dist/{chunk-ENAZCQPP.mjs → chunk-XEJGJQF4.mjs} +6 -1
- package/dist/chunk-XEJGJQF4.mjs.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/ElementTester.ts +1 -0
- package/src/Tester.ts +9 -0
- package/dist/chunk-ENAZCQPP.mjs.map +0 -1
package/dist/ElementTester.d.ts
CHANGED
package/dist/ElementTester.mjs
CHANGED
package/dist/Tester.d.ts
CHANGED
|
@@ -29,6 +29,10 @@ export declare class Tester {
|
|
|
29
29
|
atTitle: (title: string, index?: number) => ElementTester;
|
|
30
30
|
byValue: (value: string, index?: number) => HTMLElement;
|
|
31
31
|
atValue: (value: string, index?: number) => ElementTester;
|
|
32
|
+
byField: (field: Id, index?: number) => HTMLElement;
|
|
33
|
+
atField: (field: Id, index?: number) => ElementTester;
|
|
34
|
+
byName: (name: Id, index?: number) => HTMLElement;
|
|
35
|
+
atName: (name: Id, index?: number) => ElementTester;
|
|
32
36
|
submit: (id?: Id) => ElementTester;
|
|
33
37
|
debug: () => void;
|
|
34
38
|
}
|
package/dist/Tester.mjs
CHANGED
|
@@ -29,6 +29,7 @@ var ElementTester = class {
|
|
|
29
29
|
pressEnter = () => this.keyDown("Enter");
|
|
30
30
|
clear = () => this.type("");
|
|
31
31
|
type = (value) => fireEvent.change(this.element(), { target: { value } });
|
|
32
|
+
blur = () => this.element() && fireEvent.blur(this.element()) ? this : void 0;
|
|
32
33
|
wait = () => waitFor(this.element);
|
|
33
34
|
waitForRemove = () => waitForElementToBeRemoved(this.element);
|
|
34
35
|
};
|
|
@@ -66,6 +67,10 @@ var Tester = class _Tester {
|
|
|
66
67
|
atTitle = (title, index) => new ElementTester(() => this.byTitle(title, index));
|
|
67
68
|
byValue = (value, index) => byIndex(() => screen.getAllByDisplayValue(value), index);
|
|
68
69
|
atValue = (value, index) => new ElementTester(() => this.byValue(value, index));
|
|
70
|
+
byField = (field, index) => this.byQuery(["input", "select", "textarea"].map((t) => `${t}[name="${asString(field)}"]`).join(), index);
|
|
71
|
+
atField = (field, index) => new ElementTester(() => this.byField(field, index));
|
|
72
|
+
byName = (name, index) => this.byField(name, index);
|
|
73
|
+
atName = (name, index) => this.atField(name, index);
|
|
69
74
|
submit = (id = "btn-submit") => this.atId(id);
|
|
70
75
|
debug = () => screen.debug();
|
|
71
76
|
};
|
|
@@ -78,4 +83,4 @@ export {
|
|
|
78
83
|
renders,
|
|
79
84
|
ElementTester
|
|
80
85
|
};
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
86
|
+
//# sourceMappingURL=chunk-XEJGJQF4.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 byField = (field: Id, index?: number): HTMLElement =>\n 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 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;AA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E,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
|
@@ -82,6 +82,10 @@ var Tester = class _Tester {
|
|
|
82
82
|
atTitle = (title, index) => new ElementTester(() => this.byTitle(title, index));
|
|
83
83
|
byValue = (value, index) => byIndex(() => import_react3.screen.getAllByDisplayValue(value), index);
|
|
84
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);
|
|
85
89
|
submit = (id = "btn-submit") => this.atId(id);
|
|
86
90
|
debug = () => import_react3.screen.debug();
|
|
87
91
|
};
|
|
@@ -109,6 +113,7 @@ var ElementTester = class {
|
|
|
109
113
|
pressEnter = () => this.keyDown("Enter");
|
|
110
114
|
clear = () => this.type("");
|
|
111
115
|
type = (value) => import_react4.fireEvent.change(this.element(), { target: { value } });
|
|
116
|
+
blur = () => this.element() && import_react4.fireEvent.blur(this.element()) ? this : void 0;
|
|
112
117
|
wait = () => (0, import_react4.waitFor)(this.element);
|
|
113
118
|
waitForRemove = () => (0, import_react4.waitForElementToBeRemoved)(this.element);
|
|
114
119
|
};
|
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 { 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,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AAA,EAEA,QAAQ,MAAyB,KAAK,QAAQ,KAAK,wBAAU,MAAM,KAAK,QAAQ,CAAC,IAAI,OAAO;AAAA,EAC5F,aAAa,UAAwB,uBAAQ,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,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"]}
|
|
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 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 =>\n 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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,KAAK,OAAO;AAAA,EACnD,gBAAgB,UAAqB,yCAA0B,KAAK,OAAO;AAC7E;;;AD7BO,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": "18.
|
|
3
|
+
"version": "18.15.1",
|
|
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": "^18.
|
|
47
|
+
"@thisisagile/easy": "^18.15.1",
|
|
48
48
|
"@types/react": "^18.3.18",
|
|
49
49
|
"react": "^18.3.1",
|
|
50
50
|
"react-dom": "^18.3.1"
|
package/src/ElementTester.ts
CHANGED
|
@@ -28,6 +28,7 @@ export class ElementTester {
|
|
|
28
28
|
pressEnter = (): this | undefined => this.keyDown('Enter');
|
|
29
29
|
clear = (): boolean => this.type('');
|
|
30
30
|
type = (value: string): boolean => fireEvent.change(this.element(), { target: { value } });
|
|
31
|
+
blur = (): this | undefined => (this.element() && fireEvent.blur(this.element()) ? this : undefined);
|
|
31
32
|
wait = (): Promise<Element> => waitFor(this.element);
|
|
32
33
|
waitForRemove = (): Promise<void> => waitForElementToBeRemoved(this.element);
|
|
33
34
|
}
|
package/src/Tester.ts
CHANGED
|
@@ -61,6 +61,15 @@ export class Tester {
|
|
|
61
61
|
|
|
62
62
|
atValue = (value: string, index?: number): ElementTester => new ElementTester(() => this.byValue(value, index));
|
|
63
63
|
|
|
64
|
+
byField = (field: Id, index?: number): HTMLElement =>
|
|
65
|
+
this.byQuery(['input', 'select', 'textarea'].map(t => `${t}[name="${asString(field)}"]`).join(), index);
|
|
66
|
+
|
|
67
|
+
atField = (field: Id, index?: number): ElementTester => new ElementTester(() => this.byField(field, index));
|
|
68
|
+
|
|
69
|
+
byName = (name: Id, index?: number): HTMLElement => this.byField(name, index);
|
|
70
|
+
|
|
71
|
+
atName = (name: Id, index?: number): ElementTester => this.atField(name, index);
|
|
72
|
+
|
|
64
73
|
submit = (id: Id = 'btn-submit'): ElementTester => this.atId(id);
|
|
65
74
|
debug = () => screen.debug();
|
|
66
75
|
}
|
|
@@ -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 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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