Skip to content

Commit acc535e

Browse files
authored
test: add visual tests for number-field base styles (#9005)
1 parent f1da042 commit acc535e

24 files changed

+136
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
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-number-field.js';
6+
7+
describe('number-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-number-field></vaadin-number-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 = 10;
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 = 10;
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 = 10;
88+
element.clearButtonVisible = true;
89+
await visualDiff(div, `${dir}-clear-button`);
90+
});
91+
92+
it('step buttons', async () => {
93+
element.value = 10;
94+
element.stepButtonsVisible = true;
95+
await visualDiff(div, `${dir}-step-buttons`);
96+
});
97+
98+
it('error message', async () => {
99+
element.label = 'Label';
100+
element.errorMessage = 'This field is required';
101+
element.required = true;
102+
element.validate();
103+
await visualDiff(div, `${dir}-error-message`);
104+
});
105+
106+
it('helper text', async () => {
107+
element.helperText = 'Helper text';
108+
await visualDiff(div, `${dir}-helper-text`);
109+
});
110+
111+
it('helper above field', async () => {
112+
element.label = 'Label';
113+
element.helperText = 'Helper text';
114+
element.setAttribute('theme', 'helper-above-field');
115+
await visualDiff(div, `${dir}-helper-above-field`);
116+
});
117+
118+
it('prefix', async () => {
119+
const span = document.createElement('span');
120+
span.setAttribute('slot', 'prefix');
121+
span.textContent = '$';
122+
element.appendChild(span);
123+
await visualDiff(div, `${dir}-prefix`);
124+
});
125+
126+
it('suffix', async () => {
127+
const span = document.createElement('span');
128+
span.setAttribute('slot', 'suffix');
129+
span.textContent = '$';
130+
element.appendChild(span);
131+
await visualDiff(div, `${dir}-suffix`);
132+
});
133+
});
134+
});
135+
});
136+
});
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)