@cydran/testsupport 0.5.1 → 0.6.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/LICENSE +1 -1
- package/dist/testsupport.d.ts +118 -40
- package/dist/testsupport.js +290 -273
- package/dist/testsupport.js.map +4 -4
- package/dist/testsupport.min.js +66 -0
- package/dist/testsupport.min.js.map +7 -0
- package/dist/testsupport.min.mjs +33 -0
- package/dist/testsupport.min.mjs.map +7 -0
- package/dist/testsupport.mjs +261 -0
- package/dist/testsupport.mjs.map +7 -0
- package/package.json +44 -19
package/dist/testsupport.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/
|
|
4
|
-
"sourcesContent": ["import { JSDOM } from 'jsdom';\nimport { Nestable, requireNotNull, isDefined, Stage, Context, Type, merge, ArgumentsResolvers, PropertyKeys, Component, create, SimpleMap } from \"@cydran/cydran\";\nimport { queries, fireEvent } from '@testing-library/dom';\nimport { expect } from '@jest/globals';\nimport { Matchers } from 'expect';\n\nclass TestComponent extends Component {\n\t\n\tconstructor() {\n\t\tsuper(\"<div></div>\");\n\t}\n\n}\n\nconst DEFAULT_COMPONENT_SUPPLIER: () => Nestable = () => new TestComponent();\n\nconst HTML: string = `<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<title>Cydran Test Harness</title>\n\t</head>\n\t<body>\n\t\t<!-- Stage Content -->\n\t</body>\n</html>`;\n\ninterface ExpectionActions {\n\n\tselectedValues(): Matchers<void, string[]>;\n\n\ttrimmedTextContent(): Matchers<void, string>;\n\n\ttextContent(): Matchers<void, string>;\n\n}\n\ninterface Operations {\n\n\tget<E extends HTMLElement>(options?: unknown): E;\n\n\tquery(options?: unknown): HTMLElement;\n\n\tfind(options?: unknown): HTMLElement;\n\n\tgetAll(options?: unknown): HTMLElement[];\n\n\tqueryAll(options?: unknown): HTMLElement[];\n\n\tfindAll(options?: unknown): HTMLElement[];\n\n\texpect(options?: unknown): ExpectionActions;\n\n\tappendText(text: string, options?: unknown): void;\n\n\treplaceText(text: string, options?: unknown): void;\n\n\tselectIndex(index: number, options?: unknown): void;\n\n\tselectIndexes(indexes: number[], options?: unknown): void;\n\n\tsetCheckedState(options?: unknown): void;\n\n}\n\nclass ExpectionActionsImpl implements ExpectionActions {\n\n\tprivate element: HTMLElement;\n\n\tconstructor(element: HTMLElement) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t}\n\n\tpublic selectedValues(): Matchers<void, string[]> {\n\t\tconst selected: string[] = [];\n\n\t\tfor (let i: number = 0; i < this.element[\"selectedOptions\"].length; i++) {\n\t\t\tconst option: HTMLOptionElement = this.element[\"selectedOptions\"][i];\n\t\t\tselected.push(option.value);\n\t\t}\n\n\t\treturn expect(selected);\n\t}\n\n\tpublic trimmedTextContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent.trim());\n\t}\n\n\tpublic textContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent);\n\t}\n\n}\n\nclass OperationsImpl implements Operations {\n\n\tprivate element: HTMLElement;\n\n\tprivate value: string;\n\n\tprivate type: string;\n\n\tconstructor(element: HTMLElement, value: string, type: string) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t\tthis.value = requireNotNull(value, \"value\");\n\t\tthis.type = requireNotNull(type, \"type\");\n\t}\n\n\tpublic get<E extends HTMLElement>(options?: unknown): E {\n\t\treturn this.execute(\"get\", options);\n\t}\n\n\tpublic query(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"query\", options);\n\t}\n\n\tpublic find(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"find\", options);\n\t}\n\n\tpublic getAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"getAll\", options);\n\t}\n\n\tpublic queryAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"queryAll\", options);\n\t}\n\n\tpublic findAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"findAll\", options);\n\t}\n\n\tpublic expect(options?: unknown): ExpectionActions {\n\t\tconst element: HTMLElement = this.get(options);\n\n\t\treturn new ExpectionActionsImpl(element);\n\t}\n\n\tpublic appendText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = element.value + text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic replaceText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic selectIndex(index: number, options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\t\telement.selectedIndex = index;\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic selectIndexes(indexes: number[], options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\n\t\tfor (let i: number = 0; i < element.options.length; i++) {\n\t\t\tconst option: HTMLOptionElement = element.options[i];\n\t\t\toption.selected = false;\n\t\t}\n\n\t\tfor (let i: number = 0; i < indexes.length; i++) {\n\t\t\tconst index: number = indexes[i];\n\t\t\tconst option: HTMLOptionElement = element.options[index];\n\t\t\toption.selected = true;\n\t\t}\n\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic setCheckedState(value: boolean, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.checked = value;\n\t\tfireEvent.input(element);\n\t}\n\n\tprivate execute<T>(name: string, options: unknown): T {\n\t\tconst methodName: string = name + \"By\" + this.type;\n\n\t\treturn queries[methodName](this.element, this.value, options) as T;\n\t}\n\n}\n\nclass Harness<C extends Nestable> {\n\n\tprivate document: Document;\n\n\tprivate window: Window;\n\n\tprivate stage: Stage;\n\n\tprivate rootSupplier: () => C;\n\n\tprivate actualProperties: SimpleMap<unknown>;\n\n\tprivate initialProperties: SimpleMap<unknown>;\n\n\tprivate root: C;\n\n\tconstructor(rootSupplier: () => C = DEFAULT_COMPONENT_SUPPLIER as () => C, properties?: SimpleMap<unknown>) {\n\t\tthis.rootSupplier = requireNotNull(rootSupplier, \"rootSupplier\");\n\t\tthis.actualProperties = isDefined(properties) ? properties : {} as SimpleMap<unknown>;\n\t\tthis.reset();\n\t}\n\n\tpublic reset(): void {\n\t\tthis.stop();\n\n\t\tthis.window = new JSDOM(HTML).window as unknown as Window;\n\t\tthis.document = this.window.document;\n\n\t\tconst defaultProperties: object = {\n\t\t\t[PropertyKeys.CYDRAN_STARTUP_SYNCHRONOUS]: true,\n\t\t\t[PropertyKeys.CYDRAN_LOG_LEVEL]: \"WARN\",\n\t\t\t[PropertyKeys.CYDRAN_OVERRIDE_WINDOW]: this.window\n\t\t};\n\n\t\tthis.initialProperties = merge([defaultProperties, this.actualProperties]);\n\n\t\tthis.stage = create(\"body\", this.initialProperties);\n\t\tthis.stage.addInitializer({}, (stage: Stage) => {\n\t\t\tthis.root = this.rootSupplier();\n\t\t\tstage.setComponent(this.root);\n\t\t});\n\t}\n\n\tpublic start(): Harness<C> {\n\t\tthis.stage.start();\n\n\t\treturn this;\n\t}\n\n\tpublic stop(): Harness<C> {\n\t\tif (isDefined(this.stage) && this.stage.isStarted()) {\n\t\t\tthis.stage.$release();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tpublic getComponent(): C {\n\t\treturn this.root;\n\t}\n\n\tpublic getWindow(): Window {\n\t\treturn this.window;\n\t}\n\n\tpublic getDocument(): Document {\n\t\treturn this.document;\n\t}\n\n\tpublic getContext(): Context {\n\t\treturn this.stage.getContext();\n\t}\n\n\tpublic getStage(): Stage {\n\t\treturn this.stage;\n\t}\n\n\tpublic registerConstant<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext().registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototype<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingleton<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerSingleton(id, classInstance, resolvers);\n\t}\n\n\n\tpublic registerConstantGlobally<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototypeGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingletonGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerSingleton(id, classInstance, resolvers);\n\t}\n\n\n\tpublic forRole(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Role\");\n\t}\n\n\tpublic forLabelText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"LabelText\");\n\t}\n\n\tpublic forPlaceholderText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"PlaceholderText\");\n\t}\n\n\tpublic forText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Text\");\n\t}\n\n\tpublic forDisplayValue(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"DisplayValue\");\n\t}\n\n\tpublic forAltText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"AltText\");\n\t}\n\n\tpublic forTitle(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Title\");\n\t}\n\n\tpublic forTestId(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"TestId\");\n\t}\n\n\tpublic expectBody(): Matchers<void, string> {\n\t\treturn expect(this.document.body.innerHTML) as Matchers<void, string>;\n\t}\n\n}\n\nexport default Harness;\n", "import Harness from 'harness/Harness';\n\nfunction isDefined<T>(value: T): boolean {\n\treturn value !== null && value !== undefined;\n}\n\nfunction requireNotNull<T>(value: T, name: string): T {\n\tif (value === null || value === undefined) {\n\t\tthrow new Error(`${ name } shall not be null`);\n\t}\n\n\treturn value;\n}\n\nfunction merge<T>(sources: unknown[]): T {\n\trequireNotNull(sources, \"sources\");\n\n\treturn overlay({} as T, sources);\n}\n\nfunction overlay<T>(destination: T, sources: unknown[]): T {\n\trequireNotNull(destination, \"destination\");\n\trequireNotNull(sources, \"sources\");\n\n\tfor (const source of sources) {\n\t\tif (!isDefined(source)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const name of Object.keys(source)) {\n\t\t\tif (!isDefined(source[name])) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tdestination[name] = source[name];\n\t\t}\n\t}\n\n\treturn destination;\n}\n\nexport {\n\tHarness, overlay, merge, requireNotNull, isDefined\n};\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
3
|
+
"sources": ["../src/index.ts", "../src/harness/Harness.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>\n * SPDX-License-Identifier: MIT\n *\n * This file is part of Cydran and is licensed under the MIT License.\n * See the LICENSE file in the package root for details.\n */\n\nimport Harness from \"harness/Harness\";\n\nfunction isDefined<T>(value: T): boolean {\n\treturn value !== null && value !== undefined;\n}\n\nfunction requireNotNull<T>(value: T, name: string): T {\n\tif (value === null || value === undefined) {\n\t\tthrow new Error(`${name} shall not be null`);\n\t}\n\n\treturn value;\n}\n\nfunction merge<T>(sources: unknown[]): T {\n\trequireNotNull(sources, \"sources\");\n\n\treturn overlay({} as T, sources);\n}\n\nfunction overlay<T>(destination: T, sources: unknown[]): T {\n\trequireNotNull(destination, \"destination\");\n\trequireNotNull(sources, \"sources\");\n\n\tfor (const source of sources) {\n\t\tif (!isDefined(source)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const name of Object.keys(source)) {\n\t\t\tif (!isDefined(source[name])) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tdestination[name] = source[name];\n\t\t}\n\t}\n\n\treturn destination;\n}\n\nexport { Harness, overlay, merge, requireNotNull, isDefined };\n", "/*\n * Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>\n * SPDX-License-Identifier: MIT\n *\n * This file is part of Cydran and is licensed under the MIT License.\n * See the LICENSE file in the package root for details.\n */\n\nimport { JSDOM } from \"jsdom\";\nimport {\n\tNestable,\n\trequireNotNull,\n\tisDefined,\n\tStage,\n\tContext,\n\tType,\n\tmerge,\n\tArgumentsResolvers,\n\tPropertyKeys,\n\tComponent,\n\tcreate,\n\tSimpleMap\n} from \"@cydran/cydran\";\nimport { queries, fireEvent } from \"@testing-library/dom\";\nimport { expect } from \"@jest/globals\";\nimport { Matchers } from \"expect\";\n\nclass TestComponent extends Component {\n\n\tconstructor() {\n\t\tsuper(\"<div></div>\");\n\t}\n\n}\n\nconst DEFAULT_COMPONENT_SUPPLIER: () => Nestable = () => new TestComponent();\n\nconst HTML: string = `<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<title>Cydran Test Harness</title>\n\t</head>\n\t<body>\n\t\t<!-- Stage Content -->\n\t</body>\n</html>`;\n\ninterface ExpectionActions {\n\n\tselectedValues(): Matchers<void, string[]>;\n\n\ttrimmedTextContent(): Matchers<void, string>;\n\n\ttextContent(): Matchers<void, string>;\n\n}\n\ninterface Operations {\n\n\tget<E extends HTMLElement>(options?: unknown): E;\n\n\tquery(options?: unknown): HTMLElement;\n\n\tfind(options?: unknown): HTMLElement;\n\n\tgetAll(options?: unknown): HTMLElement[];\n\n\tqueryAll(options?: unknown): HTMLElement[];\n\n\tfindAll(options?: unknown): HTMLElement[];\n\n\texpect(options?: unknown): ExpectionActions;\n\n\tappendText(text: string, options?: unknown): void;\n\n\treplaceText(text: string, options?: unknown): void;\n\n\tselectIndex(index: number, options?: unknown): void;\n\n\tselectIndexes(indexes: number[], options?: unknown): void;\n\n\tsetCheckedState(options?: unknown): void;\n\n}\n\nclass ExpectionActionsImpl implements ExpectionActions {\n\n\tprivate element: HTMLElement;\n\n\tconstructor(element: HTMLElement) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t}\n\n\tpublic selectedValues(): Matchers<void, string[]> {\n\t\tconst selected: string[] = [];\n\n\t\tfor (let i: number = 0; i < this.element[\"selectedOptions\"].length; i++) {\n\t\t\tconst option: HTMLOptionElement = this.element[\"selectedOptions\"][i];\n\t\t\tselected.push(option.value);\n\t\t}\n\n\t\treturn expect(selected);\n\t}\n\n\tpublic trimmedTextContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent.trim());\n\t}\n\n\tpublic textContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent);\n\t}\n\n}\n\nclass OperationsImpl implements Operations {\n\n\tprivate element: HTMLElement;\n\n\tprivate value: string;\n\n\tprivate type: string;\n\n\tconstructor(element: HTMLElement, value: string, type: string) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t\tthis.value = requireNotNull(value, \"value\");\n\t\tthis.type = requireNotNull(type, \"type\");\n\t}\n\n\tpublic get<E extends HTMLElement>(options?: unknown): E {\n\t\treturn this.execute(\"get\", options);\n\t}\n\n\tpublic query(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"query\", options);\n\t}\n\n\tpublic find(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"find\", options);\n\t}\n\n\tpublic getAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"getAll\", options);\n\t}\n\n\tpublic queryAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"queryAll\", options);\n\t}\n\n\tpublic findAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"findAll\", options);\n\t}\n\n\tpublic expect(options?: unknown): ExpectionActions {\n\t\tconst element: HTMLElement = this.get(options);\n\n\t\treturn new ExpectionActionsImpl(element);\n\t}\n\n\tpublic appendText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = element.value + text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic replaceText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic selectIndex(index: number, options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\t\telement.selectedIndex = index;\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic selectIndexes(indexes: number[], options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\n\t\tfor (let i: number = 0; i < element.options.length; i++) {\n\t\t\tconst option: HTMLOptionElement = element.options[i];\n\t\t\toption.selected = false;\n\t\t}\n\n\t\tfor (let i: number = 0; i < indexes.length; i++) {\n\t\t\tconst index: number = indexes[i];\n\t\t\tconst option: HTMLOptionElement = element.options[index];\n\t\t\toption.selected = true;\n\t\t}\n\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic setCheckedState(value: boolean, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.checked = value;\n\t\tfireEvent.input(element);\n\t}\n\n\tprivate execute<T>(name: string, options: unknown): T {\n\t\tconst methodName: string = name + \"By\" + this.type;\n\n\t\treturn queries[methodName](this.element, this.value, options) as T;\n\t}\n\n}\n\nclass Harness<C extends Nestable> {\n\n\tprivate document: Document;\n\n\tprivate window: Window;\n\n\tprivate stage: Stage;\n\n\tprivate rootSupplier: () => C;\n\n\tprivate actualProperties: SimpleMap<unknown>;\n\n\tprivate initialProperties: SimpleMap<unknown>;\n\n\tprivate root: C;\n\n\tconstructor(rootSupplier: () => C = DEFAULT_COMPONENT_SUPPLIER as () => C, properties?: SimpleMap<unknown>) {\n\t\tthis.rootSupplier = requireNotNull(rootSupplier, \"rootSupplier\");\n\t\tthis.actualProperties = isDefined(properties) ? properties : ({} as SimpleMap<unknown>);\n\t\tthis.reset();\n\t}\n\n\tpublic reset(): void {\n\t\tthis.stop();\n\n\t\tthis.window = new JSDOM(HTML).window as unknown as Window;\n\t\tthis.document = this.window.document;\n\n\t\tconst defaultProperties: object = {\n\t\t\t[PropertyKeys.CYDRAN_STARTUP_SYNCHRONOUS]: true,\n\t\t\t[PropertyKeys.CYDRAN_LOG_LEVEL]: \"WARN\",\n\t\t\t[PropertyKeys.CYDRAN_OVERRIDE_WINDOW]: this.window\n\t\t};\n\n\t\tthis.initialProperties = merge([defaultProperties, this.actualProperties]);\n\n\t\tthis.stage = create(\"body\", this.initialProperties);\n\t\tthis.stage.addInitializer({}, (stage: Stage) => {\n\t\t\tthis.root = this.rootSupplier();\n\t\t\tstage.setComponent(this.root);\n\t\t});\n\t}\n\n\tpublic start(): Harness<C> {\n\t\tthis.stage.start();\n\n\t\treturn this;\n\t}\n\n\tpublic stop(): Harness<C> {\n\t\tif (isDefined(this.stage) && this.stage.isStarted()) {\n\t\t\tthis.stage.$release();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tpublic getComponent(): C {\n\t\treturn this.root;\n\t}\n\n\tpublic getWindow(): Window {\n\t\treturn this.window;\n\t}\n\n\tpublic getDocument(): Document {\n\t\treturn this.document;\n\t}\n\n\tpublic getContext(): Context {\n\t\treturn this.stage.getContext();\n\t}\n\n\tpublic getStage(): Stage {\n\t\treturn this.stage;\n\t}\n\n\tpublic registerConstant<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext().registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototype<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingleton<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerSingleton(id, classInstance, resolvers);\n\t}\n\n\tpublic registerConstantGlobally<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototypeGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingletonGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerSingleton(id, classInstance, resolvers);\n\t}\n\n\tpublic forRole(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Role\");\n\t}\n\n\tpublic forLabelText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"LabelText\");\n\t}\n\n\tpublic forPlaceholderText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"PlaceholderText\");\n\t}\n\n\tpublic forText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Text\");\n\t}\n\n\tpublic forDisplayValue(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"DisplayValue\");\n\t}\n\n\tpublic forAltText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"AltText\");\n\t}\n\n\tpublic forTitle(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Title\");\n\t}\n\n\tpublic forTestId(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"TestId\");\n\t}\n\n\tpublic expectBody(): Matchers<void, string> {\n\t\treturn expect(this.document.body.innerHTML) as Matchers<void, string>;\n\t}\n\n}\n\nexport default Harness;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;mBAAAA;EAAA,aAAAC;EAAA;wBAAAC;;AAAA;;;ACQA,mBAAsB;AACtB,oBAaO;AACP,iBAAmC;AACnC,qBAAuB;AAGvB,IAAM,gBAAN,cAA4B,wBAAS;EAEpC,cAAA;AACC,UAA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gBAAe,SAAS,SAAS;AAEjC,aAAW,UAAU,SAAS;AAC7B,QAAI,CAACD,WAAU,MAAM,GAAG;AACvB;IACD;AAEA,eAAW,QAAQ,OAAO,KAAK,MAAM,GAAG;AACvC,UAAI,CAACA,WAAU,OAAO,IAAI,CAAC,GAAG;AAC7B;MACD;AAEA,kBAAY,IAAI,IAAI,OAAO,IAAI;IAChC;EACD;AAEA,SAAO;AACR;",
|
|
6
|
+
"names": ["isDefined", "merge", "requireNotNull", "isDefined", "requireNotNull", "merge"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/*
|
|
2
|
+
0.6.0
|
|
3
|
+
---
|
|
4
|
+
Cydran <https://cydran.io/>
|
|
5
|
+
Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>
|
|
6
|
+
SPDX-License-Identifier: MIT
|
|
7
|
+
---
|
|
8
|
+
Derivative work based on Lodash 4.17.15 <https://lodash.com/license>
|
|
9
|
+
Copyright (c) 2019 OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
10
|
+
---
|
|
11
|
+
Derivative work based on Underscore.js
|
|
12
|
+
Copyright (c) 2012 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
13
|
+
---
|
|
14
|
+
Derivative work based on docReady <https://github.com/jfriend00/docReady/blob/master/license>
|
|
15
|
+
Copyright (c) 2014, John Friend <https://github.com/jfriend00/docReady/>
|
|
16
|
+
---
|
|
17
|
+
Derivative work based on Math.uuid.js <http://www.broofa.com>
|
|
18
|
+
Copyright (c) 2010 Robert Kieffer <https://www.broofa.com/2008/09/javascript-uuid-function/>
|
|
19
|
+
---
|
|
20
|
+
Derivative work based on UMD <https://github.com/umdjs/umd/blob/master/LICENSE.md>
|
|
21
|
+
Copyright (c) 2014 the UMD contributors <https://github.com/umdjs/umd/>
|
|
22
|
+
|
|
23
|
+
*/
|
|
24
|
+
(function (root, factory) {
|
|
25
|
+
var ids = ["@cydran/cydran","@jest/globals","@testing-library/dom","jsdom"];
|
|
26
|
+
var globals = {"@cydran/cydran":"cydran"};
|
|
27
|
+
if (typeof define === "function" && define.amd) {
|
|
28
|
+
define(["exports"].concat(ids), function (exports) {
|
|
29
|
+
var values = Array.prototype.slice.call(arguments, 1);
|
|
30
|
+
factory(exports, function (id) {
|
|
31
|
+
return values[ids.indexOf(id)];
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
} else if (typeof exports === "object" && typeof exports.nodeName !== "string") {
|
|
35
|
+
factory(exports, typeof require === "function" ? require : function (id) {
|
|
36
|
+
throw new Error("testsupport: dependency " + id + " cannot be loaded: require is not available");
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
var target = {};
|
|
40
|
+
factory(target, function (id) {
|
|
41
|
+
var value = Object.prototype.hasOwnProperty.call(globals, id) ? root[globals[id]] : undefined;
|
|
42
|
+
if (value === undefined) {
|
|
43
|
+
throw new Error("testsupport: dependency " + id + " is not available as a global");
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
});
|
|
47
|
+
root["testsupport"] = target;
|
|
48
|
+
}
|
|
49
|
+
})(typeof self !== "undefined" ? self : this, function (exports, require) {
|
|
50
|
+
"use strict";
|
|
51
|
+
var module = { exports: {} };
|
|
52
|
+
var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var E=(r,e)=>{for(var t in e)d(r,t,{get:e[t],enumerable:!0})},S=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of T(e))!P.call(r,s)&&s!==t&&d(r,s,{get:()=>e[s],enumerable:!(n=w(e,s))||n.enumerable});return r};var b=r=>S(d({},"__esModule",{value:!0}),r);var R={};E(R,{Harness:()=>x,isDefined:()=>p,merge:()=>D,overlay:()=>y,requireNotNull:()=>c});module.exports=b(R);var f=require("jsdom"),o=require("@cydran/cydran"),l=require("@testing-library/dom"),u=require("@jest/globals"),a=class extends o.Component{constructor(){super("<div></div>")}},N=()=>new a,A=`<!doctype html>
|
|
53
|
+
<html lang="en">
|
|
54
|
+
<head>
|
|
55
|
+
<title>Cydran Test Harness</title>
|
|
56
|
+
</head>
|
|
57
|
+
<body>
|
|
58
|
+
<!-- Stage Content -->
|
|
59
|
+
</body>
|
|
60
|
+
</html>`,m=class{constructor(e){this.element=(0,o.requireNotNull)(e,"element")}selectedValues(){let e=[];for(let t=0;t<this.element.selectedOptions.length;t++){let n=this.element.selectedOptions[t];e.push(n.value)}return(0,u.expect)(e)}trimmedTextContent(){return(0,u.expect)(this.element.textContent.trim())}textContent(){return(0,u.expect)(this.element.textContent)}},i=class{constructor(e,t,n){this.element=(0,o.requireNotNull)(e,"element"),this.value=(0,o.requireNotNull)(t,"value"),this.type=(0,o.requireNotNull)(n,"type")}get(e){return this.execute("get",e)}query(e){return this.execute("query",e)}find(e){return this.execute("find",e)}getAll(e){return this.execute("getAll",e)}queryAll(e){return this.execute("queryAll",e)}findAll(e){return this.execute("findAll",e)}expect(e){let t=this.get(e);return new m(t)}appendText(e,t){let n=this.get(t);n.value=n.value+e,l.fireEvent.input(n)}replaceText(e,t){let n=this.get(t);n.value=e,l.fireEvent.input(n)}selectIndex(e,t){let n=this.get(t);n.selectedIndex=e,l.fireEvent.change(n)}selectIndexes(e,t){let n=this.get(t);for(let s=0;s<n.options.length;s++){let h=n.options[s];h.selected=!1}for(let s=0;s<e.length;s++){let h=e[s],C=n.options[h];C.selected=!0}l.fireEvent.change(n)}setCheckedState(e,t){let n=this.get(t);n.checked=e,l.fireEvent.input(n)}execute(e,t){let n=e+"By"+this.type;return l.queries[n](this.element,this.value,t)}},g=class{constructor(e=N,t){this.rootSupplier=(0,o.requireNotNull)(e,"rootSupplier"),this.actualProperties=(0,o.isDefined)(t)?t:{},this.reset()}reset(){this.stop(),this.window=new f.JSDOM(A).window,this.document=this.window.document;let e={[o.PropertyKeys.CYDRAN_STARTUP_SYNCHRONOUS]:!0,[o.PropertyKeys.CYDRAN_LOG_LEVEL]:"WARN",[o.PropertyKeys.CYDRAN_OVERRIDE_WINDOW]:this.window};this.initialProperties=(0,o.merge)([e,this.actualProperties]),this.stage=(0,o.create)("body",this.initialProperties),this.stage.addInitializer({},t=>{this.root=this.rootSupplier(),t.setComponent(this.root)})}start(){return this.stage.start(),this}stop(){return(0,o.isDefined)(this.stage)&&this.stage.isStarted()&&this.stage.$release(),this}getComponent(){return this.root}getWindow(){return this.window}getDocument(){return this.document}getContext(){return this.stage.getContext()}getStage(){return this.stage}registerConstant(e,t){this.stage.getContext().registerConstant(e,t)}registerPrototype(e,t,n){this.stage.getContext().registerPrototype(e,t,n)}registerSingleton(e,t,n){this.stage.getContext().registerSingleton(e,t,n)}registerConstantGlobally(e,t){this.stage.getContext().obscuredParent.registerConstant(e,t)}registerPrototypeGlobally(e,t,n){this.stage.getContext().obscuredParent.registerPrototype(e,t,n)}registerSingletonGlobally(e,t,n){this.stage.getContext().obscuredParent.registerSingleton(e,t,n)}forRole(e){return new i(this.document.documentElement,e,"Role")}forLabelText(e){return new i(this.document.documentElement,e,"LabelText")}forPlaceholderText(e){return new i(this.document.documentElement,e,"PlaceholderText")}forText(e){return new i(this.document.documentElement,e,"Text")}forDisplayValue(e){return new i(this.document.documentElement,e,"DisplayValue")}forAltText(e){return new i(this.document.documentElement,e,"AltText")}forTitle(e){return new i(this.document.documentElement,e,"Title")}forTestId(e){return new i(this.document.documentElement,e,"TestId")}expectBody(){return(0,u.expect)(this.document.body.innerHTML)}},x=g;function p(r){return r!=null}function c(r,e){if(r==null)throw new Error(`${e} shall not be null`);return r}function D(r){return c(r,"sources"),y({},r)}function y(r,e){c(r,"destination"),c(e,"sources");for(let t of e)if(p(t))for(let n of Object.keys(t))p(t[n])&&(r[n]=t[n]);return r}0&&(module.exports={Harness,isDefined,merge,overlay,requireNotNull});
|
|
61
|
+
var source = module.exports;
|
|
62
|
+
Object.getOwnPropertyNames(source).forEach(function (key) {
|
|
63
|
+
Object.defineProperty(exports, key, Object.getOwnPropertyDescriptor(source, key));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=testsupport.min.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/index.ts", "../src/harness/Harness.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>\n * SPDX-License-Identifier: MIT\n *\n * This file is part of Cydran and is licensed under the MIT License.\n * See the LICENSE file in the package root for details.\n */\n\nimport Harness from \"harness/Harness\";\n\nfunction isDefined<T>(value: T): boolean {\n\treturn value !== null && value !== undefined;\n}\n\nfunction requireNotNull<T>(value: T, name: string): T {\n\tif (value === null || value === undefined) {\n\t\tthrow new Error(`${name} shall not be null`);\n\t}\n\n\treturn value;\n}\n\nfunction merge<T>(sources: unknown[]): T {\n\trequireNotNull(sources, \"sources\");\n\n\treturn overlay({} as T, sources);\n}\n\nfunction overlay<T>(destination: T, sources: unknown[]): T {\n\trequireNotNull(destination, \"destination\");\n\trequireNotNull(sources, \"sources\");\n\n\tfor (const source of sources) {\n\t\tif (!isDefined(source)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const name of Object.keys(source)) {\n\t\t\tif (!isDefined(source[name])) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tdestination[name] = source[name];\n\t\t}\n\t}\n\n\treturn destination;\n}\n\nexport { Harness, overlay, merge, requireNotNull, isDefined };\n", "/*\n * Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>\n * SPDX-License-Identifier: MIT\n *\n * This file is part of Cydran and is licensed under the MIT License.\n * See the LICENSE file in the package root for details.\n */\n\nimport { JSDOM } from \"jsdom\";\nimport {\n\tNestable,\n\trequireNotNull,\n\tisDefined,\n\tStage,\n\tContext,\n\tType,\n\tmerge,\n\tArgumentsResolvers,\n\tPropertyKeys,\n\tComponent,\n\tcreate,\n\tSimpleMap\n} from \"@cydran/cydran\";\nimport { queries, fireEvent } from \"@testing-library/dom\";\nimport { expect } from \"@jest/globals\";\nimport { Matchers } from \"expect\";\n\nclass TestComponent extends Component {\n\n\tconstructor() {\n\t\tsuper(\"<div></div>\");\n\t}\n\n}\n\nconst DEFAULT_COMPONENT_SUPPLIER: () => Nestable = () => new TestComponent();\n\nconst HTML: string = `<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<title>Cydran Test Harness</title>\n\t</head>\n\t<body>\n\t\t<!-- Stage Content -->\n\t</body>\n</html>`;\n\ninterface ExpectionActions {\n\n\tselectedValues(): Matchers<void, string[]>;\n\n\ttrimmedTextContent(): Matchers<void, string>;\n\n\ttextContent(): Matchers<void, string>;\n\n}\n\ninterface Operations {\n\n\tget<E extends HTMLElement>(options?: unknown): E;\n\n\tquery(options?: unknown): HTMLElement;\n\n\tfind(options?: unknown): HTMLElement;\n\n\tgetAll(options?: unknown): HTMLElement[];\n\n\tqueryAll(options?: unknown): HTMLElement[];\n\n\tfindAll(options?: unknown): HTMLElement[];\n\n\texpect(options?: unknown): ExpectionActions;\n\n\tappendText(text: string, options?: unknown): void;\n\n\treplaceText(text: string, options?: unknown): void;\n\n\tselectIndex(index: number, options?: unknown): void;\n\n\tselectIndexes(indexes: number[], options?: unknown): void;\n\n\tsetCheckedState(options?: unknown): void;\n\n}\n\nclass ExpectionActionsImpl implements ExpectionActions {\n\n\tprivate element: HTMLElement;\n\n\tconstructor(element: HTMLElement) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t}\n\n\tpublic selectedValues(): Matchers<void, string[]> {\n\t\tconst selected: string[] = [];\n\n\t\tfor (let i: number = 0; i < this.element[\"selectedOptions\"].length; i++) {\n\t\t\tconst option: HTMLOptionElement = this.element[\"selectedOptions\"][i];\n\t\t\tselected.push(option.value);\n\t\t}\n\n\t\treturn expect(selected);\n\t}\n\n\tpublic trimmedTextContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent.trim());\n\t}\n\n\tpublic textContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent);\n\t}\n\n}\n\nclass OperationsImpl implements Operations {\n\n\tprivate element: HTMLElement;\n\n\tprivate value: string;\n\n\tprivate type: string;\n\n\tconstructor(element: HTMLElement, value: string, type: string) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t\tthis.value = requireNotNull(value, \"value\");\n\t\tthis.type = requireNotNull(type, \"type\");\n\t}\n\n\tpublic get<E extends HTMLElement>(options?: unknown): E {\n\t\treturn this.execute(\"get\", options);\n\t}\n\n\tpublic query(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"query\", options);\n\t}\n\n\tpublic find(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"find\", options);\n\t}\n\n\tpublic getAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"getAll\", options);\n\t}\n\n\tpublic queryAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"queryAll\", options);\n\t}\n\n\tpublic findAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"findAll\", options);\n\t}\n\n\tpublic expect(options?: unknown): ExpectionActions {\n\t\tconst element: HTMLElement = this.get(options);\n\n\t\treturn new ExpectionActionsImpl(element);\n\t}\n\n\tpublic appendText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = element.value + text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic replaceText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic selectIndex(index: number, options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\t\telement.selectedIndex = index;\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic selectIndexes(indexes: number[], options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\n\t\tfor (let i: number = 0; i < element.options.length; i++) {\n\t\t\tconst option: HTMLOptionElement = element.options[i];\n\t\t\toption.selected = false;\n\t\t}\n\n\t\tfor (let i: number = 0; i < indexes.length; i++) {\n\t\t\tconst index: number = indexes[i];\n\t\t\tconst option: HTMLOptionElement = element.options[index];\n\t\t\toption.selected = true;\n\t\t}\n\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic setCheckedState(value: boolean, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.checked = value;\n\t\tfireEvent.input(element);\n\t}\n\n\tprivate execute<T>(name: string, options: unknown): T {\n\t\tconst methodName: string = name + \"By\" + this.type;\n\n\t\treturn queries[methodName](this.element, this.value, options) as T;\n\t}\n\n}\n\nclass Harness<C extends Nestable> {\n\n\tprivate document: Document;\n\n\tprivate window: Window;\n\n\tprivate stage: Stage;\n\n\tprivate rootSupplier: () => C;\n\n\tprivate actualProperties: SimpleMap<unknown>;\n\n\tprivate initialProperties: SimpleMap<unknown>;\n\n\tprivate root: C;\n\n\tconstructor(rootSupplier: () => C = DEFAULT_COMPONENT_SUPPLIER as () => C, properties?: SimpleMap<unknown>) {\n\t\tthis.rootSupplier = requireNotNull(rootSupplier, \"rootSupplier\");\n\t\tthis.actualProperties = isDefined(properties) ? properties : ({} as SimpleMap<unknown>);\n\t\tthis.reset();\n\t}\n\n\tpublic reset(): void {\n\t\tthis.stop();\n\n\t\tthis.window = new JSDOM(HTML).window as unknown as Window;\n\t\tthis.document = this.window.document;\n\n\t\tconst defaultProperties: object = {\n\t\t\t[PropertyKeys.CYDRAN_STARTUP_SYNCHRONOUS]: true,\n\t\t\t[PropertyKeys.CYDRAN_LOG_LEVEL]: \"WARN\",\n\t\t\t[PropertyKeys.CYDRAN_OVERRIDE_WINDOW]: this.window\n\t\t};\n\n\t\tthis.initialProperties = merge([defaultProperties, this.actualProperties]);\n\n\t\tthis.stage = create(\"body\", this.initialProperties);\n\t\tthis.stage.addInitializer({}, (stage: Stage) => {\n\t\t\tthis.root = this.rootSupplier();\n\t\t\tstage.setComponent(this.root);\n\t\t});\n\t}\n\n\tpublic start(): Harness<C> {\n\t\tthis.stage.start();\n\n\t\treturn this;\n\t}\n\n\tpublic stop(): Harness<C> {\n\t\tif (isDefined(this.stage) && this.stage.isStarted()) {\n\t\t\tthis.stage.$release();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tpublic getComponent(): C {\n\t\treturn this.root;\n\t}\n\n\tpublic getWindow(): Window {\n\t\treturn this.window;\n\t}\n\n\tpublic getDocument(): Document {\n\t\treturn this.document;\n\t}\n\n\tpublic getContext(): Context {\n\t\treturn this.stage.getContext();\n\t}\n\n\tpublic getStage(): Stage {\n\t\treturn this.stage;\n\t}\n\n\tpublic registerConstant<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext().registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototype<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingleton<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerSingleton(id, classInstance, resolvers);\n\t}\n\n\tpublic registerConstantGlobally<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototypeGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingletonGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerSingleton(id, classInstance, resolvers);\n\t}\n\n\tpublic forRole(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Role\");\n\t}\n\n\tpublic forLabelText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"LabelText\");\n\t}\n\n\tpublic forPlaceholderText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"PlaceholderText\");\n\t}\n\n\tpublic forText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Text\");\n\t}\n\n\tpublic forDisplayValue(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"DisplayValue\");\n\t}\n\n\tpublic forAltText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"AltText\");\n\t}\n\n\tpublic forTitle(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Title\");\n\t}\n\n\tpublic forTestId(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"TestId\");\n\t}\n\n\tpublic expectBody(): Matchers<void, string> {\n\t\treturn expect(this.document.body.innerHTML) as Matchers<void, string>;\n\t}\n\n}\n\nexport default Harness;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4ZAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,cAAAC,EAAA,UAAAC,EAAA,YAAAC,EAAA,mBAAAC,IAAA,eAAAC,EAAAP,GCQA,IAAAQ,EAAsB,iBACtBC,EAaO,0BACPC,EAAmC,gCACnCC,EAAuB,yBAGjBC,EAAN,cAA4B,WAAS,CAEpC,aAAA,CACC,MAAM,aAAa,CACpB,GAIKC,EAA6C,IAAM,IAAID,EAEvDE,EAAe;;;;;;;;SAgDfC,EAAN,KAA0B,CAIzB,YAAYC,EAAoB,CAC/B,KAAK,WAAU,kBAAeA,EAAS,SAAS,CACjD,CAEO,gBAAc,CACpB,IAAMC,EAAqB,CAAA,EAE3B,QAASC,EAAY,EAAGA,EAAI,KAAK,QAAQ,gBAAmB,OAAQA,IAAK,CACxE,IAAMC,EAA4B,KAAK,QAAQ,gBAAmBD,CAAC,EACnED,EAAS,KAAKE,EAAO,KAAK,CAC3B,CAEA,SAAO,UAA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,CAClF,CAEO,QAAQA,EAAa,CAC3B,OAAO,IAAID,EAAe,KAAK,SAAS,gBAAiBC,EAAO,MAAM,CACvE,CAEO,gBAAgBA,EAAa,CACnC,OAAO,IAAID,EAAe,KAAK,SAAS,gBAAiBC,EAAO,cAAc,CAC/E,CAEO,WAAWA,EAAa,CAC9B,OAAO,IAAID,EAAe,KAAK,SAAS,gBAAiBC,EAAO,SAAS,CAC1E,CAEO,SAASA,EAAa,CAC5B,OAAO,IAAID,EAAe,KAAK,SAAS,gBAAiBC,EAAO,OAAO,CACxE,CAEO,UAAUA,EAAa,CAC7B,OAAO,IAAID,EAAe,KAAK,SAAS,gBAAiBC,EAAO,QAAQ,CACzE,CAEO,YAAU,CAChB,SAAO,UAAO,KAAK,SAAS,KAAK,SAAS,CAC3C,GAIDiB,EAAeT,EDhVf,SAASU,EAAaC,EAAQ,CAC7B,OAAOA,GAAU,IAClB,CAEA,SAASC,EAAkBD,EAAUE,EAAY,CAChD,GAAIF,GAAU,KACb,MAAM,IAAI,MAAM,GAAGE,CAAI,oBAAoB,EAG5C,OAAOF,CACR,CAEA,SAASG,EAASC,EAAkB,CACnC,OAAAH,EAAeG,EAAS,SAAS,EAE1BC,EAAQ,CAAA,EAASD,CAAO,CAChC,CAEA,SAASC,EAAWC,EAAgBF,EAAkB,CACrDH,EAAeK,EAAa,aAAa,EACzCL,EAAeG,EAAS,SAAS,EAEjC,QAAWG,KAAUH,EACpB,GAAKL,EAAUQ,CAAM,EAIrB,QAAWL,KAAQ,OAAO,KAAKK,CAAM,EAC/BR,EAAUQ,EAAOL,CAAI,CAAC,IAI3BI,EAAYJ,CAAI,EAAIK,EAAOL,CAAI,GAIjC,OAAOI,CACR",
|
|
6
|
+
"names": ["js_exports", "__export", "Harness_default", "isDefined", "merge", "overlay", "requireNotNull", "__toCommonJS", "import_jsdom", "import_cydran", "import_dom", "import_globals", "TestComponent", "DEFAULT_COMPONENT_SUPPLIER", "HTML", "ExpectionActionsImpl", "element", "selected", "i", "option", "OperationsImpl", "value", "type", "options", "text", "index", "indexes", "name", "methodName", "Harness", "rootSupplier", "properties", "defaultProperties", "stage", "id", "instance", "classInstance", "resolvers", "Harness_default", "isDefined", "value", "requireNotNull", "name", "merge", "sources", "overlay", "destination", "source"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
0.6.0
|
|
3
|
+
---
|
|
4
|
+
Cydran <https://cydran.io/>
|
|
5
|
+
Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>
|
|
6
|
+
SPDX-License-Identifier: MIT
|
|
7
|
+
---
|
|
8
|
+
Derivative work based on Lodash 4.17.15 <https://lodash.com/license>
|
|
9
|
+
Copyright (c) 2019 OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
10
|
+
---
|
|
11
|
+
Derivative work based on Underscore.js
|
|
12
|
+
Copyright (c) 2012 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
13
|
+
---
|
|
14
|
+
Derivative work based on docReady <https://github.com/jfriend00/docReady/blob/master/license>
|
|
15
|
+
Copyright (c) 2014, John Friend <https://github.com/jfriend00/docReady/>
|
|
16
|
+
---
|
|
17
|
+
Derivative work based on Math.uuid.js <http://www.broofa.com>
|
|
18
|
+
Copyright (c) 2010 Robert Kieffer <https://www.broofa.com/2008/09/javascript-uuid-function/>
|
|
19
|
+
---
|
|
20
|
+
Derivative work based on UMD <https://github.com/umdjs/umd/blob/master/LICENSE.md>
|
|
21
|
+
Copyright (c) 2014 the UMD contributors <https://github.com/umdjs/umd/>
|
|
22
|
+
|
|
23
|
+
*/
|
|
24
|
+
import{JSDOM as y}from"jsdom";import{requireNotNull as l,isDefined as p,merge as C,PropertyKeys as h,Component as w,create as T}from"@cydran/cydran";import{queries as P,fireEvent as i}from"@testing-library/dom";import{expect as u}from"@jest/globals";var d=class extends w{constructor(){super("<div></div>")}},E=()=>new d,S=`<!doctype html>
|
|
25
|
+
<html lang="en">
|
|
26
|
+
<head>
|
|
27
|
+
<title>Cydran Test Harness</title>
|
|
28
|
+
</head>
|
|
29
|
+
<body>
|
|
30
|
+
<!-- Stage Content -->
|
|
31
|
+
</body>
|
|
32
|
+
</html>`,a=class{constructor(e){this.element=l(e,"element")}selectedValues(){let e=[];for(let t=0;t<this.element.selectedOptions.length;t++){let n=this.element.selectedOptions[t];e.push(n.value)}return u(e)}trimmedTextContent(){return u(this.element.textContent.trim())}textContent(){return u(this.element.textContent)}},o=class{constructor(e,t,n){this.element=l(e,"element"),this.value=l(t,"value"),this.type=l(n,"type")}get(e){return this.execute("get",e)}query(e){return this.execute("query",e)}find(e){return this.execute("find",e)}getAll(e){return this.execute("getAll",e)}queryAll(e){return this.execute("queryAll",e)}findAll(e){return this.execute("findAll",e)}expect(e){let t=this.get(e);return new a(t)}appendText(e,t){let n=this.get(t);n.value=n.value+e,i.input(n)}replaceText(e,t){let n=this.get(t);n.value=e,i.input(n)}selectIndex(e,t){let n=this.get(t);n.selectedIndex=e,i.change(n)}selectIndexes(e,t){let n=this.get(t);for(let s=0;s<n.options.length;s++){let c=n.options[s];c.selected=!1}for(let s=0;s<e.length;s++){let c=e[s],x=n.options[c];x.selected=!0}i.change(n)}setCheckedState(e,t){let n=this.get(t);n.checked=e,i.input(n)}execute(e,t){let n=e+"By"+this.type;return P[n](this.element,this.value,t)}},m=class{constructor(e=E,t){this.rootSupplier=l(e,"rootSupplier"),this.actualProperties=p(t)?t:{},this.reset()}reset(){this.stop(),this.window=new y(S).window,this.document=this.window.document;let e={[h.CYDRAN_STARTUP_SYNCHRONOUS]:!0,[h.CYDRAN_LOG_LEVEL]:"WARN",[h.CYDRAN_OVERRIDE_WINDOW]:this.window};this.initialProperties=C([e,this.actualProperties]),this.stage=T("body",this.initialProperties),this.stage.addInitializer({},t=>{this.root=this.rootSupplier(),t.setComponent(this.root)})}start(){return this.stage.start(),this}stop(){return p(this.stage)&&this.stage.isStarted()&&this.stage.$release(),this}getComponent(){return this.root}getWindow(){return this.window}getDocument(){return this.document}getContext(){return this.stage.getContext()}getStage(){return this.stage}registerConstant(e,t){this.stage.getContext().registerConstant(e,t)}registerPrototype(e,t,n){this.stage.getContext().registerPrototype(e,t,n)}registerSingleton(e,t,n){this.stage.getContext().registerSingleton(e,t,n)}registerConstantGlobally(e,t){this.stage.getContext().obscuredParent.registerConstant(e,t)}registerPrototypeGlobally(e,t,n){this.stage.getContext().obscuredParent.registerPrototype(e,t,n)}registerSingletonGlobally(e,t,n){this.stage.getContext().obscuredParent.registerSingleton(e,t,n)}forRole(e){return new o(this.document.documentElement,e,"Role")}forLabelText(e){return new o(this.document.documentElement,e,"LabelText")}forPlaceholderText(e){return new o(this.document.documentElement,e,"PlaceholderText")}forText(e){return new o(this.document.documentElement,e,"Text")}forDisplayValue(e){return new o(this.document.documentElement,e,"DisplayValue")}forAltText(e){return new o(this.document.documentElement,e,"AltText")}forTitle(e){return new o(this.document.documentElement,e,"Title")}forTestId(e){return new o(this.document.documentElement,e,"TestId")}expectBody(){return u(this.document.body.innerHTML)}},b=m;function f(r){return r!=null}function g(r,e){if(r==null)throw new Error(`${e} shall not be null`);return r}function _(r){return g(r,"sources"),N({},r)}function N(r,e){g(r,"destination"),g(e,"sources");for(let t of e)if(f(t))for(let n of Object.keys(t))f(t[n])&&(r[n]=t[n]);return r}export{b as Harness,f as isDefined,_ as merge,N as overlay,g as requireNotNull};
|
|
33
|
+
//# sourceMappingURL=testsupport.min.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/harness/Harness.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>\n * SPDX-License-Identifier: MIT\n *\n * This file is part of Cydran and is licensed under the MIT License.\n * See the LICENSE file in the package root for details.\n */\n\nimport { JSDOM } from \"jsdom\";\nimport {\n\tNestable,\n\trequireNotNull,\n\tisDefined,\n\tStage,\n\tContext,\n\tType,\n\tmerge,\n\tArgumentsResolvers,\n\tPropertyKeys,\n\tComponent,\n\tcreate,\n\tSimpleMap\n} from \"@cydran/cydran\";\nimport { queries, fireEvent } from \"@testing-library/dom\";\nimport { expect } from \"@jest/globals\";\nimport { Matchers } from \"expect\";\n\nclass TestComponent extends Component {\n\n\tconstructor() {\n\t\tsuper(\"<div></div>\");\n\t}\n\n}\n\nconst DEFAULT_COMPONENT_SUPPLIER: () => Nestable = () => new TestComponent();\n\nconst HTML: string = `<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<title>Cydran Test Harness</title>\n\t</head>\n\t<body>\n\t\t<!-- Stage Content -->\n\t</body>\n</html>`;\n\ninterface ExpectionActions {\n\n\tselectedValues(): Matchers<void, string[]>;\n\n\ttrimmedTextContent(): Matchers<void, string>;\n\n\ttextContent(): Matchers<void, string>;\n\n}\n\ninterface Operations {\n\n\tget<E extends HTMLElement>(options?: unknown): E;\n\n\tquery(options?: unknown): HTMLElement;\n\n\tfind(options?: unknown): HTMLElement;\n\n\tgetAll(options?: unknown): HTMLElement[];\n\n\tqueryAll(options?: unknown): HTMLElement[];\n\n\tfindAll(options?: unknown): HTMLElement[];\n\n\texpect(options?: unknown): ExpectionActions;\n\n\tappendText(text: string, options?: unknown): void;\n\n\treplaceText(text: string, options?: unknown): void;\n\n\tselectIndex(index: number, options?: unknown): void;\n\n\tselectIndexes(indexes: number[], options?: unknown): void;\n\n\tsetCheckedState(options?: unknown): void;\n\n}\n\nclass ExpectionActionsImpl implements ExpectionActions {\n\n\tprivate element: HTMLElement;\n\n\tconstructor(element: HTMLElement) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t}\n\n\tpublic selectedValues(): Matchers<void, string[]> {\n\t\tconst selected: string[] = [];\n\n\t\tfor (let i: number = 0; i < this.element[\"selectedOptions\"].length; i++) {\n\t\t\tconst option: HTMLOptionElement = this.element[\"selectedOptions\"][i];\n\t\t\tselected.push(option.value);\n\t\t}\n\n\t\treturn expect(selected);\n\t}\n\n\tpublic trimmedTextContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent.trim());\n\t}\n\n\tpublic textContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent);\n\t}\n\n}\n\nclass OperationsImpl implements Operations {\n\n\tprivate element: HTMLElement;\n\n\tprivate value: string;\n\n\tprivate type: string;\n\n\tconstructor(element: HTMLElement, value: string, type: string) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t\tthis.value = requireNotNull(value, \"value\");\n\t\tthis.type = requireNotNull(type, \"type\");\n\t}\n\n\tpublic get<E extends HTMLElement>(options?: unknown): E {\n\t\treturn this.execute(\"get\", options);\n\t}\n\n\tpublic query(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"query\", options);\n\t}\n\n\tpublic find(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"find\", options);\n\t}\n\n\tpublic getAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"getAll\", options);\n\t}\n\n\tpublic queryAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"queryAll\", options);\n\t}\n\n\tpublic findAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"findAll\", options);\n\t}\n\n\tpublic expect(options?: unknown): ExpectionActions {\n\t\tconst element: HTMLElement = this.get(options);\n\n\t\treturn new ExpectionActionsImpl(element);\n\t}\n\n\tpublic appendText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = element.value + text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic replaceText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic selectIndex(index: number, options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\t\telement.selectedIndex = index;\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic selectIndexes(indexes: number[], options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\n\t\tfor (let i: number = 0; i < element.options.length; i++) {\n\t\t\tconst option: HTMLOptionElement = element.options[i];\n\t\t\toption.selected = false;\n\t\t}\n\n\t\tfor (let i: number = 0; i < indexes.length; i++) {\n\t\t\tconst index: number = indexes[i];\n\t\t\tconst option: HTMLOptionElement = element.options[index];\n\t\t\toption.selected = true;\n\t\t}\n\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic setCheckedState(value: boolean, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.checked = value;\n\t\tfireEvent.input(element);\n\t}\n\n\tprivate execute<T>(name: string, options: unknown): T {\n\t\tconst methodName: string = name + \"By\" + this.type;\n\n\t\treturn queries[methodName](this.element, this.value, options) as T;\n\t}\n\n}\n\nclass Harness<C extends Nestable> {\n\n\tprivate document: Document;\n\n\tprivate window: Window;\n\n\tprivate stage: Stage;\n\n\tprivate rootSupplier: () => C;\n\n\tprivate actualProperties: SimpleMap<unknown>;\n\n\tprivate initialProperties: SimpleMap<unknown>;\n\n\tprivate root: C;\n\n\tconstructor(rootSupplier: () => C = DEFAULT_COMPONENT_SUPPLIER as () => C, properties?: SimpleMap<unknown>) {\n\t\tthis.rootSupplier = requireNotNull(rootSupplier, \"rootSupplier\");\n\t\tthis.actualProperties = isDefined(properties) ? properties : ({} as SimpleMap<unknown>);\n\t\tthis.reset();\n\t}\n\n\tpublic reset(): void {\n\t\tthis.stop();\n\n\t\tthis.window = new JSDOM(HTML).window as unknown as Window;\n\t\tthis.document = this.window.document;\n\n\t\tconst defaultProperties: object = {\n\t\t\t[PropertyKeys.CYDRAN_STARTUP_SYNCHRONOUS]: true,\n\t\t\t[PropertyKeys.CYDRAN_LOG_LEVEL]: \"WARN\",\n\t\t\t[PropertyKeys.CYDRAN_OVERRIDE_WINDOW]: this.window\n\t\t};\n\n\t\tthis.initialProperties = merge([defaultProperties, this.actualProperties]);\n\n\t\tthis.stage = create(\"body\", this.initialProperties);\n\t\tthis.stage.addInitializer({}, (stage: Stage) => {\n\t\t\tthis.root = this.rootSupplier();\n\t\t\tstage.setComponent(this.root);\n\t\t});\n\t}\n\n\tpublic start(): Harness<C> {\n\t\tthis.stage.start();\n\n\t\treturn this;\n\t}\n\n\tpublic stop(): Harness<C> {\n\t\tif (isDefined(this.stage) && this.stage.isStarted()) {\n\t\t\tthis.stage.$release();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tpublic getComponent(): C {\n\t\treturn this.root;\n\t}\n\n\tpublic getWindow(): Window {\n\t\treturn this.window;\n\t}\n\n\tpublic getDocument(): Document {\n\t\treturn this.document;\n\t}\n\n\tpublic getContext(): Context {\n\t\treturn this.stage.getContext();\n\t}\n\n\tpublic getStage(): Stage {\n\t\treturn this.stage;\n\t}\n\n\tpublic registerConstant<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext().registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototype<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingleton<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerSingleton(id, classInstance, resolvers);\n\t}\n\n\tpublic registerConstantGlobally<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototypeGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingletonGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerSingleton(id, classInstance, resolvers);\n\t}\n\n\tpublic forRole(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Role\");\n\t}\n\n\tpublic forLabelText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"LabelText\");\n\t}\n\n\tpublic forPlaceholderText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"PlaceholderText\");\n\t}\n\n\tpublic forText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Text\");\n\t}\n\n\tpublic forDisplayValue(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"DisplayValue\");\n\t}\n\n\tpublic forAltText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"AltText\");\n\t}\n\n\tpublic forTitle(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Title\");\n\t}\n\n\tpublic forTestId(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"TestId\");\n\t}\n\n\tpublic expectBody(): Matchers<void, string> {\n\t\treturn expect(this.document.body.innerHTML) as Matchers<void, string>;\n\t}\n\n}\n\nexport default Harness;\n", "/*\n * Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>\n * SPDX-License-Identifier: MIT\n *\n * This file is part of Cydran and is licensed under the MIT License.\n * See the LICENSE file in the package root for details.\n */\n\nimport Harness from \"harness/Harness\";\n\nfunction isDefined<T>(value: T): boolean {\n\treturn value !== null && value !== undefined;\n}\n\nfunction requireNotNull<T>(value: T, name: string): T {\n\tif (value === null || value === undefined) {\n\t\tthrow new Error(`${name} shall not be null`);\n\t}\n\n\treturn value;\n}\n\nfunction merge<T>(sources: unknown[]): T {\n\trequireNotNull(sources, \"sources\");\n\n\treturn overlay({} as T, sources);\n}\n\nfunction overlay<T>(destination: T, sources: unknown[]): T {\n\trequireNotNull(destination, \"destination\");\n\trequireNotNull(sources, \"sources\");\n\n\tfor (const source of sources) {\n\t\tif (!isDefined(source)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const name of Object.keys(source)) {\n\t\t\tif (!isDefined(source[name])) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tdestination[name] = source[name];\n\t\t}\n\t}\n\n\treturn destination;\n}\n\nexport { Harness, overlay, merge, requireNotNull, isDefined };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAQA,OAAS,SAAAA,MAAa,QACtB,OAEC,kBAAAC,EACA,aAAAC,EAIA,SAAAC,EAEA,gBAAAC,EACA,aAAAC,EACA,UAAAC,MAEM,iBACP,OAAS,WAAAC,EAAS,aAAAC,MAAiB,uBACnC,OAAS,UAAAC,MAAc,gBAGvB,IAAMC,EAAN,cAA4BL,CAAS,CAEpC,aAAA,CACC,MAAM,aAAa,CACpB,GAIKM,EAA6C,IAAM,IAAID,EAEvDE,EAAe;;;;;;;;SAgDfC,EAAN,KAA0B,CAIzB,YAAYC,EAAoB,CAC/B,KAAK,QAAUb,EAAea,EAAS,SAAS,CACjD,CAEO,gBAAc,CACpB,IAAMC,EAAqB,CAAA,EAE3B,QAASC,EAAY,EAAGA,EAAI,KAAK,QAAQ,gBAAmB,OAAQA,IAAK,CACxE,IAAMC,EAA4B,KAAK,QAAQ,gBAAmBD,CAAC,EACnED,EAAS,KAAKE,EAAO,KAAK,CAC3B,CAEA,OAAOR,EAAOM,CAAQ,CACvB,CAEO,oBAAkB,CACxB,OAAON,EAAO,KAAK,QAAQ,YAAY,KAAI,CAAE,CAC9C,CAEO,aAAW,CACjB,OAAOA,EAAO,KAAK,QAAQ,WAAW,CACvC,GAIKS,EAAN,KAAoB,CAQnB,YAAYJ,EAAsBK,EAAeC,EAAY,CAC5D,KAAK,QAAUnB,EAAea,EAAS,SAAS,EAChD,KAAK,MAAQb,EAAekB,EAAO,OAAO,EAC1C,KAAK,KAAOlB,EAAemB,EAAM,MAAM,CACxC,CAEO,IAA2BC,EAAiB,CAClD,OAAO,KAAK,QAAQ,MAAOA,CAAO,CACnC,CAEO,MAAMA,EAAiB,CAC7B,OAAO,KAAK,QAAQ,QAASA,CAAO,CAC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,CACzE,CAEO,YAAU,CAChB,OAAOV,EAAO,KAAK,SAAS,KAAK,SAAS,CAC3C,GAID2B,EAAeT,EChVf,SAASU,EAAaC,EAAQ,CAC7B,OAAOA,GAAU,IAClB,CAEA,SAASC,EAAkBD,EAAUE,EAAY,CAChD,GAAIF,GAAU,KACb,MAAM,IAAI,MAAM,GAAGE,CAAI,oBAAoB,EAG5C,OAAOF,CACR,CAEA,SAASG,EAASC,EAAkB,CACnC,OAAAH,EAAeG,EAAS,SAAS,EAE1BC,EAAQ,CAAA,EAASD,CAAO,CAChC,CAEA,SAASC,EAAWC,EAAgBF,EAAkB,CACrDH,EAAeK,EAAa,aAAa,EACzCL,EAAeG,EAAS,SAAS,EAEjC,QAAWG,KAAUH,EACpB,GAAKL,EAAUQ,CAAM,EAIrB,QAAWL,KAAQ,OAAO,KAAKK,CAAM,EAC/BR,EAAUQ,EAAOL,CAAI,CAAC,IAI3BI,EAAYJ,CAAI,EAAIK,EAAOL,CAAI,GAIjC,OAAOI,CACR",
|
|
6
|
+
"names": ["JSDOM", "requireNotNull", "isDefined", "merge", "PropertyKeys", "Component", "create", "queries", "fireEvent", "expect", "TestComponent", "DEFAULT_COMPONENT_SUPPLIER", "HTML", "ExpectionActionsImpl", "element", "selected", "i", "option", "OperationsImpl", "value", "type", "options", "text", "index", "indexes", "name", "methodName", "Harness", "rootSupplier", "properties", "defaultProperties", "stage", "id", "instance", "classInstance", "resolvers", "Harness_default", "isDefined", "value", "requireNotNull", "name", "merge", "sources", "overlay", "destination", "source"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/*
|
|
2
|
+
0.6.0
|
|
3
|
+
---
|
|
4
|
+
Cydran <https://cydran.io/>
|
|
5
|
+
Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>
|
|
6
|
+
SPDX-License-Identifier: MIT
|
|
7
|
+
---
|
|
8
|
+
Derivative work based on Lodash 4.17.15 <https://lodash.com/license>
|
|
9
|
+
Copyright (c) 2019 OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
10
|
+
---
|
|
11
|
+
Derivative work based on Underscore.js
|
|
12
|
+
Copyright (c) 2012 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
13
|
+
---
|
|
14
|
+
Derivative work based on docReady <https://github.com/jfriend00/docReady/blob/master/license>
|
|
15
|
+
Copyright (c) 2014, John Friend <https://github.com/jfriend00/docReady/>
|
|
16
|
+
---
|
|
17
|
+
Derivative work based on Math.uuid.js <http://www.broofa.com>
|
|
18
|
+
Copyright (c) 2010 Robert Kieffer <https://www.broofa.com/2008/09/javascript-uuid-function/>
|
|
19
|
+
---
|
|
20
|
+
Derivative work based on UMD <https://github.com/umdjs/umd/blob/master/LICENSE.md>
|
|
21
|
+
Copyright (c) 2014 the UMD contributors <https://github.com/umdjs/umd/>
|
|
22
|
+
|
|
23
|
+
*/
|
|
24
|
+
// target/js/harness/Harness.js
|
|
25
|
+
import { JSDOM } from "jsdom";
|
|
26
|
+
import { requireNotNull, isDefined, merge, PropertyKeys, Component, create } from "@cydran/cydran";
|
|
27
|
+
import { queries, fireEvent } from "@testing-library/dom";
|
|
28
|
+
import { expect } from "@jest/globals";
|
|
29
|
+
var TestComponent = class extends Component {
|
|
30
|
+
constructor() {
|
|
31
|
+
super("<div></div>");
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var DEFAULT_COMPONENT_SUPPLIER = () => new TestComponent();
|
|
35
|
+
var HTML = `<!doctype html>
|
|
36
|
+
<html lang="en">
|
|
37
|
+
<head>
|
|
38
|
+
<title>Cydran Test Harness</title>
|
|
39
|
+
</head>
|
|
40
|
+
<body>
|
|
41
|
+
<!-- Stage Content -->
|
|
42
|
+
</body>
|
|
43
|
+
</html>`;
|
|
44
|
+
var ExpectionActionsImpl = class {
|
|
45
|
+
constructor(element) {
|
|
46
|
+
this.element = requireNotNull(element, "element");
|
|
47
|
+
}
|
|
48
|
+
selectedValues() {
|
|
49
|
+
const selected = [];
|
|
50
|
+
for (let i = 0; i < this.element["selectedOptions"].length; i++) {
|
|
51
|
+
const option = this.element["selectedOptions"][i];
|
|
52
|
+
selected.push(option.value);
|
|
53
|
+
}
|
|
54
|
+
return expect(selected);
|
|
55
|
+
}
|
|
56
|
+
trimmedTextContent() {
|
|
57
|
+
return expect(this.element.textContent.trim());
|
|
58
|
+
}
|
|
59
|
+
textContent() {
|
|
60
|
+
return expect(this.element.textContent);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
var OperationsImpl = class {
|
|
64
|
+
constructor(element, value, type) {
|
|
65
|
+
this.element = requireNotNull(element, "element");
|
|
66
|
+
this.value = requireNotNull(value, "value");
|
|
67
|
+
this.type = requireNotNull(type, "type");
|
|
68
|
+
}
|
|
69
|
+
get(options) {
|
|
70
|
+
return this.execute("get", options);
|
|
71
|
+
}
|
|
72
|
+
query(options) {
|
|
73
|
+
return this.execute("query", options);
|
|
74
|
+
}
|
|
75
|
+
find(options) {
|
|
76
|
+
return this.execute("find", options);
|
|
77
|
+
}
|
|
78
|
+
getAll(options) {
|
|
79
|
+
return this.execute("getAll", options);
|
|
80
|
+
}
|
|
81
|
+
queryAll(options) {
|
|
82
|
+
return this.execute("queryAll", options);
|
|
83
|
+
}
|
|
84
|
+
findAll(options) {
|
|
85
|
+
return this.execute("findAll", options);
|
|
86
|
+
}
|
|
87
|
+
expect(options) {
|
|
88
|
+
const element = this.get(options);
|
|
89
|
+
return new ExpectionActionsImpl(element);
|
|
90
|
+
}
|
|
91
|
+
appendText(text, options) {
|
|
92
|
+
const element = this.get(options);
|
|
93
|
+
element.value = element.value + text;
|
|
94
|
+
fireEvent.input(element);
|
|
95
|
+
}
|
|
96
|
+
replaceText(text, options) {
|
|
97
|
+
const element = this.get(options);
|
|
98
|
+
element.value = text;
|
|
99
|
+
fireEvent.input(element);
|
|
100
|
+
}
|
|
101
|
+
selectIndex(index, options) {
|
|
102
|
+
const element = this.get(options);
|
|
103
|
+
element.selectedIndex = index;
|
|
104
|
+
fireEvent.change(element);
|
|
105
|
+
}
|
|
106
|
+
selectIndexes(indexes, options) {
|
|
107
|
+
const element = this.get(options);
|
|
108
|
+
for (let i = 0; i < element.options.length; i++) {
|
|
109
|
+
const option = element.options[i];
|
|
110
|
+
option.selected = false;
|
|
111
|
+
}
|
|
112
|
+
for (let i = 0; i < indexes.length; i++) {
|
|
113
|
+
const index = indexes[i];
|
|
114
|
+
const option = element.options[index];
|
|
115
|
+
option.selected = true;
|
|
116
|
+
}
|
|
117
|
+
fireEvent.change(element);
|
|
118
|
+
}
|
|
119
|
+
setCheckedState(value, options) {
|
|
120
|
+
const element = this.get(options);
|
|
121
|
+
element.checked = value;
|
|
122
|
+
fireEvent.input(element);
|
|
123
|
+
}
|
|
124
|
+
execute(name, options) {
|
|
125
|
+
const methodName = name + "By" + this.type;
|
|
126
|
+
return queries[methodName](this.element, this.value, options);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
var Harness = class {
|
|
130
|
+
constructor(rootSupplier = DEFAULT_COMPONENT_SUPPLIER, properties) {
|
|
131
|
+
this.rootSupplier = requireNotNull(rootSupplier, "rootSupplier");
|
|
132
|
+
this.actualProperties = isDefined(properties) ? properties : {};
|
|
133
|
+
this.reset();
|
|
134
|
+
}
|
|
135
|
+
reset() {
|
|
136
|
+
this.stop();
|
|
137
|
+
this.window = new JSDOM(HTML).window;
|
|
138
|
+
this.document = this.window.document;
|
|
139
|
+
const defaultProperties = {
|
|
140
|
+
[PropertyKeys.CYDRAN_STARTUP_SYNCHRONOUS]: true,
|
|
141
|
+
[PropertyKeys.CYDRAN_LOG_LEVEL]: "WARN",
|
|
142
|
+
[PropertyKeys.CYDRAN_OVERRIDE_WINDOW]: this.window
|
|
143
|
+
};
|
|
144
|
+
this.initialProperties = merge([defaultProperties, this.actualProperties]);
|
|
145
|
+
this.stage = create("body", this.initialProperties);
|
|
146
|
+
this.stage.addInitializer({}, (stage) => {
|
|
147
|
+
this.root = this.rootSupplier();
|
|
148
|
+
stage.setComponent(this.root);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
start() {
|
|
152
|
+
this.stage.start();
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
stop() {
|
|
156
|
+
if (isDefined(this.stage) && this.stage.isStarted()) {
|
|
157
|
+
this.stage.$release();
|
|
158
|
+
}
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
getComponent() {
|
|
162
|
+
return this.root;
|
|
163
|
+
}
|
|
164
|
+
getWindow() {
|
|
165
|
+
return this.window;
|
|
166
|
+
}
|
|
167
|
+
getDocument() {
|
|
168
|
+
return this.document;
|
|
169
|
+
}
|
|
170
|
+
getContext() {
|
|
171
|
+
return this.stage.getContext();
|
|
172
|
+
}
|
|
173
|
+
getStage() {
|
|
174
|
+
return this.stage;
|
|
175
|
+
}
|
|
176
|
+
registerConstant(id, instance) {
|
|
177
|
+
this.stage.getContext().registerConstant(id, instance);
|
|
178
|
+
}
|
|
179
|
+
registerPrototype(id, classInstance, resolvers) {
|
|
180
|
+
this.stage.getContext().registerPrototype(id, classInstance, resolvers);
|
|
181
|
+
}
|
|
182
|
+
registerSingleton(id, classInstance, resolvers) {
|
|
183
|
+
this.stage.getContext().registerSingleton(id, classInstance, resolvers);
|
|
184
|
+
}
|
|
185
|
+
registerConstantGlobally(id, instance) {
|
|
186
|
+
this.stage.getContext()["obscuredParent"].registerConstant(id, instance);
|
|
187
|
+
}
|
|
188
|
+
registerPrototypeGlobally(id, classInstance, resolvers) {
|
|
189
|
+
this.stage.getContext()["obscuredParent"].registerPrototype(id, classInstance, resolvers);
|
|
190
|
+
}
|
|
191
|
+
registerSingletonGlobally(id, classInstance, resolvers) {
|
|
192
|
+
this.stage.getContext()["obscuredParent"].registerSingleton(id, classInstance, resolvers);
|
|
193
|
+
}
|
|
194
|
+
forRole(value) {
|
|
195
|
+
return new OperationsImpl(this.document.documentElement, value, "Role");
|
|
196
|
+
}
|
|
197
|
+
forLabelText(value) {
|
|
198
|
+
return new OperationsImpl(this.document.documentElement, value, "LabelText");
|
|
199
|
+
}
|
|
200
|
+
forPlaceholderText(value) {
|
|
201
|
+
return new OperationsImpl(this.document.documentElement, value, "PlaceholderText");
|
|
202
|
+
}
|
|
203
|
+
forText(value) {
|
|
204
|
+
return new OperationsImpl(this.document.documentElement, value, "Text");
|
|
205
|
+
}
|
|
206
|
+
forDisplayValue(value) {
|
|
207
|
+
return new OperationsImpl(this.document.documentElement, value, "DisplayValue");
|
|
208
|
+
}
|
|
209
|
+
forAltText(value) {
|
|
210
|
+
return new OperationsImpl(this.document.documentElement, value, "AltText");
|
|
211
|
+
}
|
|
212
|
+
forTitle(value) {
|
|
213
|
+
return new OperationsImpl(this.document.documentElement, value, "Title");
|
|
214
|
+
}
|
|
215
|
+
forTestId(value) {
|
|
216
|
+
return new OperationsImpl(this.document.documentElement, value, "TestId");
|
|
217
|
+
}
|
|
218
|
+
expectBody() {
|
|
219
|
+
return expect(this.document.body.innerHTML);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
var Harness_default = Harness;
|
|
223
|
+
|
|
224
|
+
// target/js/index.js
|
|
225
|
+
function isDefined2(value) {
|
|
226
|
+
return value !== null && value !== void 0;
|
|
227
|
+
}
|
|
228
|
+
function requireNotNull2(value, name) {
|
|
229
|
+
if (value === null || value === void 0) {
|
|
230
|
+
throw new Error(`${name} shall not be null`);
|
|
231
|
+
}
|
|
232
|
+
return value;
|
|
233
|
+
}
|
|
234
|
+
function merge2(sources) {
|
|
235
|
+
requireNotNull2(sources, "sources");
|
|
236
|
+
return overlay({}, sources);
|
|
237
|
+
}
|
|
238
|
+
function overlay(destination, sources) {
|
|
239
|
+
requireNotNull2(destination, "destination");
|
|
240
|
+
requireNotNull2(sources, "sources");
|
|
241
|
+
for (const source of sources) {
|
|
242
|
+
if (!isDefined2(source)) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
for (const name of Object.keys(source)) {
|
|
246
|
+
if (!isDefined2(source[name])) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
destination[name] = source[name];
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return destination;
|
|
253
|
+
}
|
|
254
|
+
export {
|
|
255
|
+
Harness_default as Harness,
|
|
256
|
+
isDefined2 as isDefined,
|
|
257
|
+
merge2 as merge,
|
|
258
|
+
overlay,
|
|
259
|
+
requireNotNull2 as requireNotNull
|
|
260
|
+
};
|
|
261
|
+
//# sourceMappingURL=testsupport.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/harness/Harness.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["/*\n * Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>\n * SPDX-License-Identifier: MIT\n *\n * This file is part of Cydran and is licensed under the MIT License.\n * See the LICENSE file in the package root for details.\n */\n\nimport { JSDOM } from \"jsdom\";\nimport {\n\tNestable,\n\trequireNotNull,\n\tisDefined,\n\tStage,\n\tContext,\n\tType,\n\tmerge,\n\tArgumentsResolvers,\n\tPropertyKeys,\n\tComponent,\n\tcreate,\n\tSimpleMap\n} from \"@cydran/cydran\";\nimport { queries, fireEvent } from \"@testing-library/dom\";\nimport { expect } from \"@jest/globals\";\nimport { Matchers } from \"expect\";\n\nclass TestComponent extends Component {\n\n\tconstructor() {\n\t\tsuper(\"<div></div>\");\n\t}\n\n}\n\nconst DEFAULT_COMPONENT_SUPPLIER: () => Nestable = () => new TestComponent();\n\nconst HTML: string = `<!doctype html>\n<html lang=\"en\">\n\t<head>\n\t\t<title>Cydran Test Harness</title>\n\t</head>\n\t<body>\n\t\t<!-- Stage Content -->\n\t</body>\n</html>`;\n\ninterface ExpectionActions {\n\n\tselectedValues(): Matchers<void, string[]>;\n\n\ttrimmedTextContent(): Matchers<void, string>;\n\n\ttextContent(): Matchers<void, string>;\n\n}\n\ninterface Operations {\n\n\tget<E extends HTMLElement>(options?: unknown): E;\n\n\tquery(options?: unknown): HTMLElement;\n\n\tfind(options?: unknown): HTMLElement;\n\n\tgetAll(options?: unknown): HTMLElement[];\n\n\tqueryAll(options?: unknown): HTMLElement[];\n\n\tfindAll(options?: unknown): HTMLElement[];\n\n\texpect(options?: unknown): ExpectionActions;\n\n\tappendText(text: string, options?: unknown): void;\n\n\treplaceText(text: string, options?: unknown): void;\n\n\tselectIndex(index: number, options?: unknown): void;\n\n\tselectIndexes(indexes: number[], options?: unknown): void;\n\n\tsetCheckedState(options?: unknown): void;\n\n}\n\nclass ExpectionActionsImpl implements ExpectionActions {\n\n\tprivate element: HTMLElement;\n\n\tconstructor(element: HTMLElement) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t}\n\n\tpublic selectedValues(): Matchers<void, string[]> {\n\t\tconst selected: string[] = [];\n\n\t\tfor (let i: number = 0; i < this.element[\"selectedOptions\"].length; i++) {\n\t\t\tconst option: HTMLOptionElement = this.element[\"selectedOptions\"][i];\n\t\t\tselected.push(option.value);\n\t\t}\n\n\t\treturn expect(selected);\n\t}\n\n\tpublic trimmedTextContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent.trim());\n\t}\n\n\tpublic textContent(): Matchers<void, string> {\n\t\treturn expect(this.element.textContent);\n\t}\n\n}\n\nclass OperationsImpl implements Operations {\n\n\tprivate element: HTMLElement;\n\n\tprivate value: string;\n\n\tprivate type: string;\n\n\tconstructor(element: HTMLElement, value: string, type: string) {\n\t\tthis.element = requireNotNull(element, \"element\");\n\t\tthis.value = requireNotNull(value, \"value\");\n\t\tthis.type = requireNotNull(type, \"type\");\n\t}\n\n\tpublic get<E extends HTMLElement>(options?: unknown): E {\n\t\treturn this.execute(\"get\", options);\n\t}\n\n\tpublic query(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"query\", options);\n\t}\n\n\tpublic find(options?: unknown): HTMLElement {\n\t\treturn this.execute(\"find\", options);\n\t}\n\n\tpublic getAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"getAll\", options);\n\t}\n\n\tpublic queryAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"queryAll\", options);\n\t}\n\n\tpublic findAll(options?: unknown): HTMLElement[] {\n\t\treturn this.execute(\"findAll\", options);\n\t}\n\n\tpublic expect(options?: unknown): ExpectionActions {\n\t\tconst element: HTMLElement = this.get(options);\n\n\t\treturn new ExpectionActionsImpl(element);\n\t}\n\n\tpublic appendText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = element.value + text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic replaceText(text: string, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.value = text;\n\t\tfireEvent.input(element);\n\t}\n\n\tpublic selectIndex(index: number, options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\t\telement.selectedIndex = index;\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic selectIndexes(indexes: number[], options?: unknown): void {\n\t\tconst element: HTMLSelectElement = this.get(options) as HTMLSelectElement;\n\n\t\tfor (let i: number = 0; i < element.options.length; i++) {\n\t\t\tconst option: HTMLOptionElement = element.options[i];\n\t\t\toption.selected = false;\n\t\t}\n\n\t\tfor (let i: number = 0; i < indexes.length; i++) {\n\t\t\tconst index: number = indexes[i];\n\t\t\tconst option: HTMLOptionElement = element.options[index];\n\t\t\toption.selected = true;\n\t\t}\n\n\t\tfireEvent.change(element);\n\t}\n\n\tpublic setCheckedState(value: boolean, options?: unknown): void {\n\t\tconst element: HTMLInputElement = this.get(options) as HTMLInputElement;\n\t\telement.checked = value;\n\t\tfireEvent.input(element);\n\t}\n\n\tprivate execute<T>(name: string, options: unknown): T {\n\t\tconst methodName: string = name + \"By\" + this.type;\n\n\t\treturn queries[methodName](this.element, this.value, options) as T;\n\t}\n\n}\n\nclass Harness<C extends Nestable> {\n\n\tprivate document: Document;\n\n\tprivate window: Window;\n\n\tprivate stage: Stage;\n\n\tprivate rootSupplier: () => C;\n\n\tprivate actualProperties: SimpleMap<unknown>;\n\n\tprivate initialProperties: SimpleMap<unknown>;\n\n\tprivate root: C;\n\n\tconstructor(rootSupplier: () => C = DEFAULT_COMPONENT_SUPPLIER as () => C, properties?: SimpleMap<unknown>) {\n\t\tthis.rootSupplier = requireNotNull(rootSupplier, \"rootSupplier\");\n\t\tthis.actualProperties = isDefined(properties) ? properties : ({} as SimpleMap<unknown>);\n\t\tthis.reset();\n\t}\n\n\tpublic reset(): void {\n\t\tthis.stop();\n\n\t\tthis.window = new JSDOM(HTML).window as unknown as Window;\n\t\tthis.document = this.window.document;\n\n\t\tconst defaultProperties: object = {\n\t\t\t[PropertyKeys.CYDRAN_STARTUP_SYNCHRONOUS]: true,\n\t\t\t[PropertyKeys.CYDRAN_LOG_LEVEL]: \"WARN\",\n\t\t\t[PropertyKeys.CYDRAN_OVERRIDE_WINDOW]: this.window\n\t\t};\n\n\t\tthis.initialProperties = merge([defaultProperties, this.actualProperties]);\n\n\t\tthis.stage = create(\"body\", this.initialProperties);\n\t\tthis.stage.addInitializer({}, (stage: Stage) => {\n\t\t\tthis.root = this.rootSupplier();\n\t\t\tstage.setComponent(this.root);\n\t\t});\n\t}\n\n\tpublic start(): Harness<C> {\n\t\tthis.stage.start();\n\n\t\treturn this;\n\t}\n\n\tpublic stop(): Harness<C> {\n\t\tif (isDefined(this.stage) && this.stage.isStarted()) {\n\t\t\tthis.stage.$release();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tpublic getComponent(): C {\n\t\treturn this.root;\n\t}\n\n\tpublic getWindow(): Window {\n\t\treturn this.window;\n\t}\n\n\tpublic getDocument(): Document {\n\t\treturn this.document;\n\t}\n\n\tpublic getContext(): Context {\n\t\treturn this.stage.getContext();\n\t}\n\n\tpublic getStage(): Stage {\n\t\treturn this.stage;\n\t}\n\n\tpublic registerConstant<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext().registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototype<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingleton<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext().registerSingleton(id, classInstance, resolvers);\n\t}\n\n\tpublic registerConstantGlobally<T>(id: string, instance: T): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerConstant(id, instance);\n\t}\n\n\tpublic registerPrototypeGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerPrototype(id, classInstance, resolvers);\n\t}\n\n\tpublic registerSingletonGlobally<T>(id: string, classInstance: Type<T>, resolvers?: ArgumentsResolvers): void {\n\t\tthis.stage.getContext()[\"obscuredParent\"].registerSingleton(id, classInstance, resolvers);\n\t}\n\n\tpublic forRole(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Role\");\n\t}\n\n\tpublic forLabelText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"LabelText\");\n\t}\n\n\tpublic forPlaceholderText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"PlaceholderText\");\n\t}\n\n\tpublic forText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Text\");\n\t}\n\n\tpublic forDisplayValue(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"DisplayValue\");\n\t}\n\n\tpublic forAltText(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"AltText\");\n\t}\n\n\tpublic forTitle(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"Title\");\n\t}\n\n\tpublic forTestId(value: string): Operations {\n\t\treturn new OperationsImpl(this.document.documentElement, value, \"TestId\");\n\t}\n\n\tpublic expectBody(): Matchers<void, string> {\n\t\treturn expect(this.document.body.innerHTML) as Matchers<void, string>;\n\t}\n\n}\n\nexport default Harness;\n", "/*\n * Copyright (c) 2018-2026 The Cydran Team <https://cydran.io/>\n * SPDX-License-Identifier: MIT\n *\n * This file is part of Cydran and is licensed under the MIT License.\n * See the LICENSE file in the package root for details.\n */\n\nimport Harness from \"harness/Harness\";\n\nfunction isDefined<T>(value: T): boolean {\n\treturn value !== null && value !== undefined;\n}\n\nfunction requireNotNull<T>(value: T, name: string): T {\n\tif (value === null || value === undefined) {\n\t\tthrow new Error(`${name} shall not be null`);\n\t}\n\n\treturn value;\n}\n\nfunction merge<T>(sources: unknown[]): T {\n\trequireNotNull(sources, \"sources\");\n\n\treturn overlay({} as T, sources);\n}\n\nfunction overlay<T>(destination: T, sources: unknown[]): T {\n\trequireNotNull(destination, \"destination\");\n\trequireNotNull(sources, \"sources\");\n\n\tfor (const source of sources) {\n\t\tif (!isDefined(source)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tfor (const name of Object.keys(source)) {\n\t\t\tif (!isDefined(source[name])) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tdestination[name] = source[name];\n\t\t}\n\t}\n\n\treturn destination;\n}\n\nexport { Harness, overlay, merge, requireNotNull, isDefined };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAQA,SAAS,aAAa;AACtB,SAEC,gBACA,WAIA,OAEA,cACA,WACA,cAEM;AACP,SAAS,SAAS,iBAAiB;AACnC,SAAS,cAAc;AAGvB,IAAM,gBAAN,cAA4B,UAAS;EAEpC,cAAA;AACC,UAAM,aAAa;EACpB;;AAID,IAAM,6BAA6C,MAAM,IAAI,cAAa;AAE1E,IAAM,OAAe;;;;;;;;;AAgDrB,IAAM,uBAAN,MAA0B;EAIzB,YAAY,SAAoB;AAC/B,SAAK,UAAU,eAAe,SAAS,SAAS;EACjD;EAEO,iBAAc;AACpB,UAAM,WAAqB,CAAA;AAE3B,aAAS,IAAY,GA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