-
Notifications
You must be signed in to change notification settings - Fork 77
/
Copy pathlabel.e2e.ts
177 lines (155 loc) · 6.07 KB
/
label.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
import { newE2EPage } from "@stencil/core/testing";
import { renders } from "../../tests/commonTests";
describe("calcite-label", () => {
it("renders", () => renders("calcite-label", { display: "inline" }));
it("renders default props when none are provided", async () => {
const page = await newE2EPage();
await page.setContent(`
<calcite-label>
Label text
<calcite-input></calcite-input>
</calcite-label>
`);
const element = await page.find("calcite-label");
expect(element).toEqualAttribute("status", "idle");
expect(element).toEqualAttribute("layout", "default");
});
it("renders requested props when valid props are provided", async () => {
const page = await newE2EPage();
await page.setContent(`
<calcite-label layout="inline-space-between">
Label text
<calcite-input></calcite-input>
</calcite-label>
`);
const element = await page.find("calcite-label");
expect(element).toEqualAttribute("layout", "inline-space-between");
});
describe("alignment prop", () => {
let page;
let element;
let style;
describe("default behavior", () => {
it("should render with 'start' alignment", async () => {
page = await newE2EPage({
html: `<calcite-label>Label text
<calcite-input></calcite-input>
</calcite-label>`
});
element = await page.find("calcite-label");
expect(await element.getProperty("alignment")).toEqual("start");
});
describe("when in a center-aligned container", () => {
describe("when direction is left-to-right", () => {
it("should render text left-aligned", async () => {
page = await newE2EPage({
html: `<div style="text-align: center;">
<calcite-label dir="ltr">Label text
<calcite-input></calcite-input>
</calcite-label>
</div>`
});
element = await page.find("calcite-label >>> .container");
style = await element.getComputedStyle();
expect(style["textAlign"]).toEqual("start");
});
});
describe("when direction is right-to-left", () => {
it("should render text right-aligned", async () => {
page = await newE2EPage({
html: `<div style="text-align: center;">
<calcite-label dir="rtl">Label text
<calcite-input></calcite-input>
</calcite-label>
</div>`
});
element = await page.find("calcite-label >>> .container");
style = await element.getComputedStyle();
expect(style["textAlign"]).toEqual("start");
});
});
});
});
describe("when alignment prop is provided", () => {
describe("'center' alignment", () => {
it("should render text center-aligned", async () => {
page = await newE2EPage({
html: `<calcite-label alignment="center">Label text
<calcite-input></calcite-input>
</calcite-label>`
});
element = await page.find("calcite-label >>> .container");
style = await element.getComputedStyle();
expect(style["textAlign"]).toEqual("center");
});
});
describe("'end' alignment", () => {
describe("when direction is left-to-right", () => {
it("should render text right-aligned", async () => {
page = await newE2EPage({
html: `<calcite-label alignment="end" dir="ltr">Label text
<calcite-input></calcite-input>
</calcite-label>`
});
element = await page.find("calcite-label >>> .container");
style = await element.getComputedStyle();
expect(style["textAlign"]).toEqual("end");
});
});
describe("when direction is right-to-left", () => {
it("should render text left-aligned", async () => {
page = await newE2EPage({
html: `<calcite-label alignment="end" dir="rtl">Label text
<calcite-input></calcite-input>
</calcite-label>`
});
element = await page.find("calcite-label >>> .container");
style = await element.getComputedStyle();
expect(style["textAlign"]).toEqual("end");
});
});
});
});
});
it("does not pass id to child label element", async () => {
const page = await newE2EPage();
await page.setContent(`
<calcite-label id="dont-duplicate-me" layout="inline-space-between">
Label text
<calcite-input></calcite-input>
</calcite-label>
`);
const element = await page.find("calcite-label");
const childElement = await page.find("calcite-label >>> .container");
expect(element).toEqualAttribute("id", "dont-duplicate-me");
expect(childElement).not.toHaveAttribute("id");
expect(element).toEqualAttribute("layout", "inline-space-between");
});
// TODO: need shadow DOM equivalent update on helper
it("clicking sibling label focuses input when both are inside a shadowRoot", async () => {
const page = await newE2EPage();
await page.evaluate(() => {
document.addEventListener("calciteInputFocus", (event: CustomEvent): void => {
(window as any).eventDetail = event.detail;
});
});
await page.evaluate(() => {
class ShadowComponent extends HTMLElement {
constructor() {
super();
const shadow = this.attachShadow({ mode: "open" });
shadow.innerHTML = `
<calcite-label for="input">Label</calcite-label>
<calcite-input id="input"></calcite-input>
`;
}
}
customElements.define("shadow-component", ShadowComponent);
const shadowComponent = document.createElement("shadow-component");
document.body.appendChild(shadowComponent);
shadowComponent.shadowRoot.querySelector("calcite-label").click();
});
const eventDetail: any = await page.evaluateHandle(() => (window as any).eventDetail);
expect(eventDetail).toBeTruthy();
});
});