-
Notifications
You must be signed in to change notification settings - Fork 75
/
option.e2e.ts
95 lines (76 loc) · 2.92 KB
/
option.e2e.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { newE2EPage } from "@stencil/core/testing";
import { accessible, defaults, reflects, renders, hidden } from "../../tests/commonTests";
describe("calcite-option", () => {
describe("renders", () => {
renders("calcite-option", { display: "block" });
});
describe("honors hidden attribute", () => {
hidden("calcite-option");
});
describe("accessible", () => {
accessible("calcite-option");
});
describe("defaults", () => {
defaults("calcite-option", [
{
propertyName: "disabled",
defaultValue: false,
},
]);
});
describe("reflects", () => {
reflects("calcite-option", [
{
propertyName: "disabled",
value: true,
},
{
propertyName: "selected",
value: true,
},
]);
});
it("falls back to the text content when value/label is not specified", async () => {
const optionText = "one";
const page = await newE2EPage({
html: `<calcite-option>${optionText}</calcite-option>`,
});
const option = await page.find("calcite-option");
expect(await option.getProperty("label")).toBe(optionText);
expect(await option.getProperty("value")).toBe(optionText);
option.setProperty("label", "two");
option.setProperty("value", 2);
await page.waitForChanges();
expect(await option.getProperty("label")).toBe("two");
expect(await option.getProperty("value")).toBe(2);
option.setProperty("label", undefined);
option.setProperty("value", undefined);
await page.waitForChanges();
expect(await option.getProperty("label")).toBe(optionText);
expect(await option.getProperty("value")).toBe(optionText);
option.setProperty("label", "");
option.setProperty("value", "");
await page.waitForChanges();
expect(await option.getProperty("label")).toBe(optionText);
expect(await option.getProperty("value")).toBe("");
option.setProperty("label", null);
option.setProperty("value", null);
await page.waitForChanges();
expect(await option.getProperty("label")).toBe(optionText);
expect(await option.getProperty("value")).toBe(optionText);
const alternateLabel = "dos";
await option.setProperty("innerText", alternateLabel);
await page.waitForChanges();
expect(await option.getProperty("label")).toBe(alternateLabel);
expect(await option.getProperty("value")).toBe(alternateLabel);
const charDataUpdateLabel = "tres";
await page.evaluate((updatedText: string): void => {
// Ember and possibly other frameworks use Text node APIs to update contents
const option = document.querySelector<HTMLCalciteOptionElement>("calcite-option");
const textNode = option.childNodes[0] as Text;
textNode.replaceData(0, textNode.length, updatedText);
}, charDataUpdateLabel);
expect(await option.getProperty("label")).toBe(charDataUpdateLabel);
expect(await option.getProperty("value")).toBe(charDataUpdateLabel);
});
});