@fluid-topics/ft-wc-test-utils 1.1.75
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/README.md +2 -0
- package/build/FtLitElementTestHelper.d.ts +16 -0
- package/build/FtLitElementTestHelper.js +40 -0
- package/build/ft-wc-test-utils.light.js +408 -0
- package/build/ft-wc-test-utils.min.js +450 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { FtLitElement, Optional } from "@fluid-topics/ft-wc-utils";
|
|
2
|
+
export declare class FtLitElementTestHelper<T extends FtLitElement> {
|
|
3
|
+
element: T;
|
|
4
|
+
constructor(element: T);
|
|
5
|
+
elementUpdated(): Promise<T>;
|
|
6
|
+
get<E extends HTMLElement>(selector: string): E;
|
|
7
|
+
find<E extends HTMLElement>(selector: string): Optional<E>;
|
|
8
|
+
findAll<E extends HTMLElement>(selector: string): Array<E>;
|
|
9
|
+
shouldBeHidden(selector?: string): Promise<void>;
|
|
10
|
+
shouldBeVisible(selector?: string): Promise<void>;
|
|
11
|
+
shouldNotBeEmpty(selector?: string): Promise<void>;
|
|
12
|
+
protected shouldHaveTextIgnoringWhiteSpaces(selector: Optional<string>, expectedText: string): Promise<void>;
|
|
13
|
+
protected matches<E extends HTMLElement>(selector: Optional<string>, matcher: (e: E) => boolean): boolean;
|
|
14
|
+
protected getTarget<E extends HTMLElement>(selector?: Optional<string>): Optional<E>;
|
|
15
|
+
protected removeWhiteSpaces(text: string): string;
|
|
16
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { elementUpdated, waitUntil } from "@open-wc/testing";
|
|
2
|
+
export class FtLitElementTestHelper {
|
|
3
|
+
constructor(element) {
|
|
4
|
+
this.element = element;
|
|
5
|
+
}
|
|
6
|
+
elementUpdated() {
|
|
7
|
+
return elementUpdated(this.element);
|
|
8
|
+
}
|
|
9
|
+
get(selector) {
|
|
10
|
+
return this.find(selector);
|
|
11
|
+
}
|
|
12
|
+
find(selector) {
|
|
13
|
+
return this.element.shadowRoot.querySelector(selector);
|
|
14
|
+
}
|
|
15
|
+
findAll(selector) {
|
|
16
|
+
return [...this.element.shadowRoot.querySelectorAll(selector)];
|
|
17
|
+
}
|
|
18
|
+
async shouldBeHidden(selector) {
|
|
19
|
+
await waitUntil(() => this.matches(selector, target => getComputedStyle(target).display === "none"), "Element should be hidden");
|
|
20
|
+
}
|
|
21
|
+
async shouldBeVisible(selector) {
|
|
22
|
+
await waitUntil(() => this.matches(selector, target => getComputedStyle(target).display != "none"), "Element should be visible");
|
|
23
|
+
}
|
|
24
|
+
async shouldNotBeEmpty(selector) {
|
|
25
|
+
await waitUntil(() => this.matches(selector, target => { var _a; return ((_a = target.textContent) !== null && _a !== void 0 ? _a : "").trim() !== ""; }), `Element <${selector !== null && selector !== void 0 ? selector : this.element.constructor.name}> should have had text`);
|
|
26
|
+
}
|
|
27
|
+
async shouldHaveTextIgnoringWhiteSpaces(selector, expectedText) {
|
|
28
|
+
await waitUntil(() => this.matches(selector, (target) => { var _a; return this.removeWhiteSpaces((_a = target.textContent) !== null && _a !== void 0 ? _a : "") === this.removeWhiteSpaces(expectedText); }), `Element <${selector !== null && selector !== void 0 ? selector : this.element.constructor.name}> should have had text "${expectedText}"`);
|
|
29
|
+
}
|
|
30
|
+
matches(selector, matcher) {
|
|
31
|
+
const target = this.getTarget(selector);
|
|
32
|
+
return !!target && matcher(target);
|
|
33
|
+
}
|
|
34
|
+
getTarget(selector) {
|
|
35
|
+
return selector ? this.find(selector) : this.element;
|
|
36
|
+
}
|
|
37
|
+
removeWhiteSpaces(text) {
|
|
38
|
+
return text.trim().replace(/\s+/g, "-");
|
|
39
|
+
}
|
|
40
|
+
}
|