Skip to content

Commit

Permalink
test: use formatter from date picker in value commit tests (#7306) (#…
Browse files Browse the repository at this point in the history
…7307)

Co-authored-by: Ugur Saglam <[email protected]>
  • Loading branch information
vaadin-bot and ugur-vaadin committed Apr 8, 2024
1 parent 045e12a commit 8e344bb
Showing 1 changed file with 15 additions and 19 deletions.
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

0 comments on commit 8e344bb

Please sign in to comment.