-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
input.e2e.ts
220 lines (194 loc) · 7.06 KB
/
input.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import { expect } from '@playwright/test';
import { configs, test } from '@utils/test/playwright';
configs().forEach(({ title, screenshot, config }) => {
test.describe(title('input: basic'), () => {
test.describe('input with overflow', () => {
test('should not have visual regressions', async ({ page }) => {
await page.setContent(
`
<ion-input aria-label="Long Input" value="reallylonglonglonginputtoseetheedgesreallylonglonglonginputtoseetheedges"></ion-input>
`,
config
);
const input = page.locator('ion-input');
// Validates the display of an input where text extends off the edge of the component.
await expect(input).toHaveScreenshot(screenshot(`input-with-text-overflow`));
});
});
test.describe('input with placeholder', () => {
test('should not have visual regressions', async ({ page }) => {
await page.setContent(
`
<ion-input aria-label="Input with Placeholder" placeholder="Placeholder"></ion-input>
`,
config
);
const input = page.locator('ion-input');
// Validates the display of an input with a placeholder.
await expect(input).toHaveScreenshot(screenshot(`input-with-placeholder`));
});
});
test.describe('input with clear button', () => {
test('should not have visual regressions with default label', async ({ page }) => {
await page.setContent(
`
<ion-input
label="Label"
clear-input="true"
value="Text"
></ion-input>
`,
config
);
const input = page.locator('ion-input');
// Validates the display of an input with a clear button.
await expect(input).toHaveScreenshot(screenshot(`input-with-clear-button`));
});
test('should not have visual regressions with stacked label', async ({ page }) => {
await page.setContent(
`
<ion-input
label="Label"
label-placement="stacked"
clear-input="true"
value="Text"
></ion-input>
`,
config
);
const input = page.locator('ion-input');
// Validates the display of an input with a clear button.
await expect(input).toHaveScreenshot(screenshot(`input-with-clear-button-stacked`));
});
});
});
});
/**
* This behavior does not vary across modes/directions.
*/
configs({ modes: ['ios'], directions: ['ltr'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('input: clear button'), () => {
test('should clear the input when pressed', async ({ page }) => {
await page.setContent(
`
<ion-input label="my label" value="abc" clear-input="true"></ion-input>
`,
config
);
const input = page.locator('ion-input');
const clearButton = input.locator('.input-clear-icon');
await expect(input).toHaveJSProperty('value', 'abc');
await clearButton.click();
await page.waitForChanges();
await expect(input).toHaveJSProperty('value', '');
});
/**
* Note: This only tests the desktop focus behavior.
* Mobile browsers have different restrictions around
* focusing inputs, so these platforms should always
* be tested when making changes to the focus behavior.
*/
test('should keep the input focused when the clear button is pressed', async ({ page }) => {
await page.setContent(
`
<ion-input label="my label" value="abc" clear-input="true"></ion-input>
`,
config
);
const input = page.locator('ion-input');
const nativeInput = input.locator('input');
const clearButton = input.locator('.input-clear-icon');
await input.click();
await expect(nativeInput).toBeFocused();
await clearButton.click();
await page.waitForChanges();
await expect(nativeInput).toBeFocused();
});
test('should inherit color when used in item with color property', async ({ page }) => {
await page.setContent(
`
<ion-item color="primary">
<ion-input aria-label="my label" value="Text" clear-input="true"></ion-input>
</ion-item>
`,
config
);
const item = page.locator('ion-item');
await expect(item).toHaveScreenshot(screenshot(`input-with-clear-button-item-color`));
});
});
});
configs({ modes: ['ionic-md'] }).forEach(({ title, screenshot, config }) => {
test.describe(title('input: clear button in ionic theme, visual checks'), () => {
test('should not have visual regressions', async ({ page }) => {
await page.setContent(
`
<ion-input
label="Label"
label-placement="stacked"
clear-input="true"
value="Text"
></ion-input>
`,
config
);
const input = page.locator('ion-input');
await input.evaluate((el: HTMLIonInputElement) => el.setFocus());
await page.waitForChanges();
await expect(input).toHaveScreenshot(screenshot(`input-with-clear-button`));
});
test('should not have visual regressions when clear button is focused', async ({ page, pageUtils }) => {
// extra padding around input ensures focus ring doesn't get cut off at screenshot edges
await page.setContent(
`
<style>
#container {
padding: 10px;
}
</style>
<div id="container">
<ion-input
label="Label"
label-placement="stacked"
clear-input="true"
value="Text"
></ion-input>
</div>
`,
config
);
const input = page.locator('ion-input');
await input.evaluate((el: HTMLIonInputElement) => el.setFocus());
await page.waitForChanges();
await pageUtils.pressKeys('Tab');
const container = page.locator('#container');
await expect(container).toHaveScreenshot(screenshot(`input-clear-button-focused`));
});
});
});
configs({ modes: ['ionic-md'], directions: ['ltr'] }).forEach(({ title, config }) => {
test.describe(title('input: clear button in ionic theme, functionality checks'), () => {
test('should show clear button when any part of input is focused', async ({ page, pageUtils }) => {
await page.setContent(
`
<ion-input
label="Label"
label-placement="stacked"
clear-input="true"
value="Text"
></ion-input>
`,
config
);
const input = page.locator('ion-input');
const clearButton = input.locator('.input-clear-icon');
await expect(clearButton).not.toBeVisible();
await input.evaluate((el: HTMLIonInputElement) => el.setFocus());
await expect(clearButton).toBeVisible();
// ensure blurring native input doesn't immediately hide clear button
await pageUtils.pressKeys('Tab');
await expect(clearButton).toBeFocused();
await expect(clearButton).toBeVisible();
});
});
});