Skip to content
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

test: use formatter from date picker in tests #7306

Merged
merged 1 commit into from
Apr 8, 2024
Merged
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
34 changes: 15 additions & 19 deletions packages/date-picker/test/value-commit.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,8 @@ import sinon from 'sinon';
import { getDeepActiveElement } from '@vaadin/a11y-base/src/focus-utils.js';
import { waitForOverlayRender, waitForScrollToFinish } from './helpers.js';

function formatDateISO(date) {
return date.toISOString().split('T')[0];
}

const TODAY_DATE = formatDateISO(new Date());
const YESTERDAY_DATE = formatDateISO(new Date(Date.now() - 3600 * 1000 * 24));

describe('value commit', () => {
let datePicker, valueChangedSpy, validateSpy, changeSpy, unparsableChangeSpy;
let datePicker, valueChangedSpy, validateSpy, changeSpy, unparsableChangeSpy, todayDate, yesterdayDate;

function expectNoValueCommit() {
expect(valueChangedSpy).to.be.not.called;
Expand Down Expand Up @@ -63,6 +56,9 @@ describe('value commit', () => {
datePicker.addEventListener('unparsable-change', unparsableChangeSpy);

datePicker.focus();

todayDate = datePicker._formatISO(new Date());
yesterdayDate = datePicker._formatISO(new Date(Date.now() - 3600 * 1000 * 24));
});

describe('default', () => {
Expand Down Expand Up @@ -160,7 +156,7 @@ describe('value commit', () => {

describe('value set programmatically', () => {
beforeEach(() => {
datePicker.value = TODAY_DATE;
datePicker.value = todayDate;
valueChangedSpy.resetHistory();
validateSpy.resetHistory();
});
Expand Down Expand Up @@ -265,22 +261,22 @@ describe('value commit', () => {
it('should commit on focused date selection with click', () => {
const date = getDeepActiveElement();
tap(date);
expectValueCommit(YESTERDAY_DATE);
expectValueCommit(yesterdayDate);
});

it('should commit on focused date selection with Enter', async () => {
await sendKeys({ press: 'Enter' });
expectValueCommit(YESTERDAY_DATE);
expectValueCommit(yesterdayDate);
});

it('should commit on focused date selection with Space', async () => {
await sendKeys({ press: 'Space' });
expectValueCommit(YESTERDAY_DATE);
expectValueCommit(yesterdayDate);
});

it('should commit focused date on close with outside click', () => {
outsideClick();
expectValueCommit(YESTERDAY_DATE);
expectValueCommit(yesterdayDate);
});

it('should revert on close with Escape', async () => {
Expand Down Expand Up @@ -312,7 +308,7 @@ describe('value commit', () => {
validateSpy.resetHistory();
changeSpy.resetHistory();
outsideClick();
expectValueCommit(TODAY_DATE);
expectValueCommit(todayDate);
});

describe('another date focused', () => {
Expand All @@ -325,17 +321,17 @@ describe('value commit', () => {
it('should commit on focused date selection with click', () => {
const date = getDeepActiveElement();
tap(date);
expectValueCommit(YESTERDAY_DATE);
expectValueCommit(yesterdayDate);
});

it('should commit on focused date selection with Space', async () => {
await sendKeys({ press: 'Space' });
expectValueCommit(YESTERDAY_DATE);
expectValueCommit(yesterdayDate);
});

it('should commit on focused date selection with Enter', async () => {
await sendKeys({ press: 'Enter' });
expectValueCommit(YESTERDAY_DATE);
expectValueCommit(yesterdayDate);
});
});
});
Expand All @@ -344,7 +340,7 @@ describe('value commit', () => {
let initialInputElementValue;

beforeEach(() => {
datePicker.value = TODAY_DATE;
datePicker.value = todayDate;
initialInputElementValue = datePicker.inputElement.value;
valueChangedSpy.resetHistory();
validateSpy.resetHistory();
Expand Down Expand Up @@ -434,7 +430,7 @@ describe('value commit', () => {

describe('with clear button', () => {
beforeEach(() => {
datePicker.value = TODAY_DATE;
datePicker.value = todayDate;
datePicker.clearButtonVisible = true;
validateSpy.resetHistory();
valueChangedSpy.resetHistory();
Expand Down
Loading