Skip to content

test: add visual tests for date-picker base styles #9018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 144 additions & 0 deletions packages/date-picker/test/visual/base/date-picker.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { resetMouse, sendKeys, sendMouseToElement } from '@vaadin/test-runner-commands';
import { fixtureSync, mousedown } from '@vaadin/testing-helpers';
import { visualDiff } from '@web/test-runner-visual-regression';
import '../common.js';
import '../../../src/vaadin-lit-date-picker.js';

describe('date-picker', () => {
let div, element;

beforeEach(() => {
div = document.createElement('div');
div.style.display = 'inline-block';
div.style.padding = '10px';
element = fixtureSync('<vaadin-date-picker></vaadin-date-picker>', div);
});

describe('states', () => {
it('basic', async () => {
await visualDiff(div, 'state-basic');
});

it('disabled', async () => {
element.disabled = true;
await visualDiff(div, 'state-disabled');
});

it('readonly', async () => {
element.readonly = true;
await visualDiff(div, 'state-readonly');
});

describe('focus', () => {
afterEach(async () => {
await resetMouse();
// After tests which use sendKeys() the focus-utils.js -> isKeyboardActive is set to true.
// Click once here on body to reset it so other tests are not affected by it.
// An unwanted focus-ring would be shown in other tests otherwise.
mousedown(document.body);
});

it('keyboard focus', async () => {
await sendKeys({ press: 'Tab' });
await visualDiff(div, 'state-focus-keyboard');
});

it('pointer focus', async () => {
element.autoOpenDisabled = true;
await sendMouseToElement({ type: 'click', element });
await visualDiff(div, 'state-focus-pointer');
});
});
});

describe('features', () => {
['ltr', 'rtl'].forEach((dir) => {
describe(dir, () => {
before(() => {
document.documentElement.setAttribute('dir', dir);
});

after(() => {
document.documentElement.removeAttribute('dir');
});

it('label', async () => {
element.label = 'Label';
await visualDiff(div, `${dir}-label`);
});

it('placeholder', async () => {
element.placeholder = 'Placeholder';
await visualDiff(div, `${dir}-placeholder`);
});

it('value', async () => {
element.value = '1991-12-20';
await visualDiff(div, `${dir}-value`);
});

it('clear button', async () => {
element.value = '1991-12-20';
element.clearButtonVisible = true;
await visualDiff(div, `${dir}-clear-button`);
});

it('required', async () => {
element.label = 'Label';
element.required = true;
await visualDiff(div, `${dir}-required`);
});

it('error message', async () => {
element.label = 'Label';
element.errorMessage = 'This field is required';
element.required = true;
element.validate();
await visualDiff(div, `${dir}-error-message`);
});

it('helper text', async () => {
element.helperText = 'Helper text';
await visualDiff(div, `${dir}-helper-text`);
});

it('helper above field', async () => {
element.label = 'Label';
element.helperText = 'Helper text';
element.setAttribute('theme', 'helper-above-field');
await visualDiff(div, `${dir}-helper-above-field`);
});

it('prefix slot', async () => {
const span = document.createElement('span');
span.setAttribute('slot', 'prefix');
span.textContent = '$';
element.appendChild(span);
await visualDiff(div, `${dir}-prefix`);
});

describe('dropdown', () => {
function openOverlay() {
element.opened = true;
div.style.height = `${element.offsetHeight + element.$.overlay.$.overlay.offsetHeight}px`;
div.style.width = `${element.$.overlay.$.overlay.offsetWidth}px`;
}

it('default', async () => {
element.value = '2000-01-01';
openOverlay();
await visualDiff(div, `${dir}-dropdown`);
});

it('week numbers', async () => {
element.value = '2000-01-01';
element.showWeekNumbers = true;
element.i18n = { firstDayOfWeek: 1 };
openOverlay();
await visualDiff(div, `${dir}-week-numbers`);
});
});
});
});
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.