-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathfab.e2e.ts
executable file
·188 lines (158 loc) · 6.05 KB
/
fab.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import { newE2EPage } from "@arcgis/lumina-compiler/puppeteerTesting";
import { describe, expect, it } from "vitest";
import { accessible, defaults, disabled, hidden, renders, themed } from "../../tests/commonTests";
import { findAll } from "../../tests/utils";
import { html } from "../../../support/formatting";
import { CSS } from "./resources";
describe("calcite-fab", () => {
describe("renders", () => {
renders("calcite-fab", { display: "flex" });
});
describe("honors hidden attribute", () => {
hidden("calcite-fab");
});
describe("defaults", () => {
defaults("calcite-fab", [
{
propertyName: "scale",
defaultValue: "m",
},
{
propertyName: "appearance",
defaultValue: "solid",
},
]);
});
describe("disabled", () => {
disabled("calcite-fab");
});
it(`should set all internal calcite-button types to 'button'`, async () => {
const page = await newE2EPage({
html: "<calcite-fab></calcite-fab>",
});
const buttons = await findAll(page, "calcite-fab >>> calcite-button");
expect(buttons).toHaveLength(1);
for (const button of buttons) {
expect(await button.getProperty("type")).toBe("button");
}
});
it("should have visible text when text is enabled", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-fab text="hello world" text-enabled></calcite-fab>`);
const button = await page.find(`calcite-fab >>> .${CSS.button}`);
const text = button.textContent;
expect(text).toBe("hello world");
});
it("should not have a tooltip when text-enabled", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-fab text="hello world" text-enabled></calcite-fab>`);
const button = await page.find(`calcite-fab >>> .${CSS.button}`);
expect(button.getAttribute("title")).toBe(null);
});
it("should have a tooltip when not text-enabled", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-fab text="hello world"></calcite-fab>`);
const button = await page.find(`calcite-fab >>> .${CSS.button}`);
expect(button.getAttribute("title")).toBe("hello world");
const fab = await page.find("calcite-fab");
fab.setProperty("label", "label");
await page.waitForChanges();
expect(button.getAttribute("title")).toBe("label");
});
it("should not have visible text when text is not enabled", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-fab text="hello world"></calcite-fab>`);
const button = await page.find(`calcite-fab >>> .${CSS.button}`);
const text = button.textContent;
expect(text).toBe("");
});
it("should have label", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-fab text="hello world" label="hi"></calcite-fab>`);
const calciteButton = await page.find(`calcite-fab >>> .${CSS.button}`);
expect(calciteButton.getAttribute("title")).toBe("hi");
expect(await calciteButton.getProperty("label")).toBe("hi");
});
it("should have appearance=solid", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-fab text="hello world"></calcite-fab>`);
const fab = await page.find(`calcite-fab >>> .${CSS.button}`);
expect(fab.getAttribute("appearance")).toBe("solid");
});
it("should have appearance=outline-fill", async () => {
const page = await newE2EPage();
await page.setContent(`<calcite-fab appearance="outline-fill" text="hello world"></calcite-fab>`);
const fab = await page.find(`calcite-fab >>> .${CSS.button}`);
expect(fab.getAttribute("appearance")).toBe("outline-fill");
});
describe("accessible", () => {
accessible(`<calcite-fab label="hello world" text="hello world"></calcite-fab>`);
accessible(`<calcite-fab label="hello world" text="hello world" disabled text-enabled></calcite-fab>`);
});
describe("when invalid appearance values are passed", () => {
describe("when value is 'transparent'", () => {
it("should render with default 'outline-fill' appearance", async () => {
const page = await newE2EPage({
html: `
<calcite-fab
text="FAB"
text-enabled
appearance="transparent"
></calcite-fab>
`,
});
const fab = await page.find(`calcite-fab >>> .${CSS.button}`);
expect(fab.getAttribute("appearance")).toBe("outline-fill");
});
});
describe("when value is 'clear'", () => {
it("should render with default 'outline-fill' appearance", async () => {
const page = await newE2EPage({
html: `
<calcite-fab
text="FAB"
text-enabled
appearance="outline"
></calcite-fab>
`,
});
const fab = await page.find(`calcite-fab >>> .${CSS.button}`);
expect(fab.getAttribute("appearance")).toBe("outline-fill");
});
});
});
describe("theme", () => {
describe("default", () => {
themed(html`<calcite-fab></calcite-fab>`, {
"--calcite-fab-background-color": {
targetProp: "--calcite-button-background-color",
shadowSelector: `.${CSS.button}`,
},
"--calcite-fab-border-color": {
targetProp: "--calcite-button-border-color",
shadowSelector: `.${CSS.button}`,
},
"--calcite-fab-corner-radius": {
targetProp: "--calcite-button-corner-radius",
shadowSelector: `.${CSS.button}`,
},
"--calcite-fab-text-color": {
targetProp: "--calcite-button-text-color",
shadowSelector: `.${CSS.button}`,
},
"--calcite-fab-shadow": {
targetProp: "boxShadow",
shadowSelector: `.${CSS.button}`,
},
});
});
describe("loader", () => {
themed(html`<calcite-fab loading></calcite-fab>`, {
"--calcite-fab-loader-color": {
targetProp: "--calcite-button-loader-color",
shadowSelector: `.${CSS.button}`,
},
});
});
});
});