Skip to content

Commit f1da042

Browse files
authored
test: add visual tests for text-field base styles (#9004)
1 parent 96b4521 commit f1da042

22 files changed

+130
-0
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
2+
import { fixtureSync, mousedown } from '@vaadin/testing-helpers';
3+
import { visualDiff } from '@web/test-runner-visual-regression';
4+
import '../common.js';
5+
import '../../../src/vaadin-lit-text-field.js';
6+
7+
describe('text-field', () => {
8+
let div, element;
9+
10+
beforeEach(() => {
11+
div = document.createElement('div');
12+
div.style.display = 'inline-block';
13+
div.style.padding = '10px';
14+
element = fixtureSync('<vaadin-text-field></vaadin-text-field>', div);
15+
});
16+
17+
describe('states', () => {
18+
it('basic', async () => {
19+
await visualDiff(div, 'state-basic');
20+
});
21+
22+
it('value', async () => {
23+
element.value = 'value';
24+
await visualDiff(div, 'state-value');
25+
});
26+
27+
it('placeholder', async () => {
28+
element.placeholder = 'Placeholder';
29+
await visualDiff(div, 'state-placeholder');
30+
});
31+
32+
it('disabled', async () => {
33+
element.disabled = true;
34+
await visualDiff(div, 'state-disabled');
35+
});
36+
37+
it('disabled value', async () => {
38+
element.disabled = true;
39+
element.value = 'value';
40+
await visualDiff(div, 'state-disabled-value');
41+
});
42+
43+
it('readonly', async () => {
44+
element.readonly = true;
45+
await visualDiff(div, 'state-readonly');
46+
});
47+
48+
it('required', async () => {
49+
element.label = 'Label';
50+
element.required = true;
51+
await visualDiff(div, 'state-required');
52+
});
53+
54+
describe('focus', () => {
55+
afterEach(async () => {
56+
await resetMouse();
57+
// After tests which use sendKeys() the focus-utils.js -> isKeyboardActive is set to true.
58+
// Click once here on body to reset it so other tests are not affected by it.
59+
// An unwanted focus-ring would be shown in other tests otherwise.
60+
mousedown(document.body);
61+
});
62+
63+
it('keyboard focus', async () => {
64+
await sendKeys({ press: 'Tab' });
65+
await visualDiff(div, 'state-focus-keyboard');
66+
});
67+
68+
it('pointer focus', async () => {
69+
await sendMouseToElement({ type: 'click', element });
70+
await visualDiff(div, 'state-focus-pointer');
71+
});
72+
});
73+
});
74+
75+
describe('features', () => {
76+
['ltr', 'rtl'].forEach((dir) => {
77+
describe(dir, () => {
78+
before(() => {
79+
document.documentElement.setAttribute('dir', dir);
80+
});
81+
82+
after(() => {
83+
document.documentElement.removeAttribute('dir');
84+
});
85+
86+
it('clear button', async () => {
87+
element.value = 'value';
88+
element.clearButtonVisible = true;
89+
await visualDiff(div, `${dir}-clear-button`);
90+
});
91+
92+
it('error message', async () => {
93+
element.label = 'Label';
94+
element.errorMessage = 'This field is required';
95+
element.required = true;
96+
element.validate();
97+
await visualDiff(div, `${dir}-error-message`);
98+
});
99+
100+
it('helper text', async () => {
101+
element.helperText = 'Helper text';
102+
await visualDiff(div, `${dir}-helper-text`);
103+
});
104+
105+
it('helper above field', async () => {
106+
element.label = 'Label';
107+
element.helperText = 'Helper text';
108+
element.setAttribute('theme', 'helper-above-field');
109+
await visualDiff(div, `${dir}-helper-above-field`);
110+
});
111+
112+
it('prefix', async () => {
113+
const span = document.createElement('span');
114+
span.setAttribute('slot', 'prefix');
115+
span.textContent = '$';
116+
element.appendChild(span);
117+
await visualDiff(div, `${dir}-prefix`);
118+
});
119+
120+
it('suffix', async () => {
121+
const span = document.createElement('span');
122+
span.setAttribute('slot', 'suffix');
123+
span.textContent = '$';
124+
element.appendChild(span);
125+
await visualDiff(div, `${dir}-suffix`);
126+
});
127+
});
128+
});
129+
});
130+
});

0 commit comments

Comments
 (0)