Skip to content

Commit

Permalink
Finally figured out what was the problem with failing tests (not just…
Browse files Browse the repository at this point in the history
… asynch and so, but also the input was not cleaned out,

and need to use target.value=''; to clean it, and some other small fixes needed too, plus Ugur's idea on assigning values and
how to input)
  • Loading branch information
czp13 committed Jan 16, 2023
1 parent c9390e7 commit fcb48e8
Showing 1 changed file with 53 additions and 63 deletions.
116 changes: 53 additions & 63 deletions test/keyboard-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -538,69 +538,59 @@
expect(Vaadin.DatePickerHelper._getAdjustedYear(new Date(1920, 0, 2), 70)).to.equal(1970);
});

// it('should parse short year with current date as reference date', async () => {
// await checkYearOffsets();
// });
//
// it('should parse short year with a custom reference date later in century', async () => {
// datepicker.i18n = {
// ...datepicker.i18n,
// referenceDate: '1999-01-01',
// };
// await checkYearOffsets();
// });
//
// it('should parse short year with a custom reference date earlier in century', async () => {
// datepicker.i18n = {
// ...datepicker.i18n,
// referenceDate: '2001-01-01',
// };
// await checkYearOffsets();
// });

// it('should parse short year with a custom reference date and ambiguous year difference', async () => {
// datepicker.i18n = {
// ...datepicker.i18n,
// referenceDate: '2001-03-15',
// };
// await checkMonthAndDayOffset(0, 0, 0);
// await checkMonthAndDayOffset(0, -1, 0);
// await checkMonthAndDayOffset(0, 1, -100);
// await checkMonthAndDayOffset(-1, 0, 0);
// await checkMonthAndDayOffset(1, 0, -100);
// });

// async function checkMonthAndDayOffset(monthOffsetToAdd, dayOffsetToAdd, expectedYearOffset) {
// input.value = '';
// const referenceDate = new Date(datepicker.i18n.referenceDate);
// const yearToTest = referenceDate.getFullYear() + 50;
// await sendKeys({
// type: `${referenceDate.getMonth() + 1 + monthOffsetToAdd}/${referenceDate.getDate() + dayOffsetToAdd}/${
// yearToTest % 100
// }`,
// });
// const result = focusedDate();
// expect(result.getFullYear()).to.equal(yearToTest + expectedYearOffset);
// }

// async function checkYearOffsets() {
// await checkYearOffset(0, 0);
// await checkYearOffset(-49, 0);
// await checkYearOffset(49, 0);
// await checkYearOffset(-51, 100);
// await checkYearOffset(51, -100);
// }

// async function checkYearOffset(offsetToAdd, expectedOffset) {
// input.value = '';
// const referenceDateYear = datepicker.i18n.referenceDate
// ? new Date(datepicker.i18n.referenceDate).getFullYear()
// : today.getFullYear();
// const yearToTest = referenceDateYear + offsetToAdd;
// await sendKeys({ type: `6/20/${String(yearToTest).slice(2, 4)}` });
// const result = focusedDate();
// expect(result.getFullYear()).to.equal(yearToTest + expectedOffset);
// }
it('should parse short year with current date as reference date', () => {
checkYearOffsets();
});

it('should parse short year with a custom reference date later in century', () => {
Object.assign(datepicker.i18n, {referenceDate: '1999-01-01'});
checkYearOffsets();
});

it('should parse short year with a custom reference date earlier in century', () => {
Object.assign(datepicker.i18n, {referenceDate: '2001-01-01'});
checkYearOffsets();
});

it('should parse short year with a custom reference date and ambiguous year difference', () => {
Object.assign(datepicker.i18n, {referenceDate: '2001-03-15'});
checkMonthAndDayOffset(0, 0, 0);
checkMonthAndDayOffset(0, -1, 0);
checkMonthAndDayOffset(0, 1, -100);
checkMonthAndDayOffset(-1, 0, 0);
checkMonthAndDayOffset(1, 0, -100);
});

function checkMonthAndDayOffset(monthOffsetToAdd, dayOffsetToAdd, expectedYearOffset) {
const referenceDate = new Date(datepicker.i18n.referenceDate);
const yearToTest = referenceDate.getFullYear() + 50;
target.value = '';
inputText(`${referenceDate.getMonth() + 1 + monthOffsetToAdd}/${referenceDate.getDate() + dayOffsetToAdd}/${
yearToTest % 100
}`);

const result = focusedDate();
expect(result.getFullYear()).to.equal(yearToTest + expectedYearOffset);
}

function checkYearOffsets() {
checkYearOffset(0, 0);
checkYearOffset(-49, 0);
checkYearOffset(49, 0);
checkYearOffset(-51, 100);
checkYearOffset(51, -100);
}

function checkYearOffset(offsetToAdd, expectedOffset) {
const referenceDateYear = datepicker.i18n.referenceDate
? new Date(datepicker.i18n.referenceDate).getFullYear()
: today.getFullYear();
const yearToTest = referenceDateYear + offsetToAdd;
target.value = '';
inputText(`6/20/${String(yearToTest).slice(2, 4)}`);
const result = focusedDate();
expect(result.getFullYear()).to.equal(yearToTest + expectedOffset);
}
});

describe('focus modes', () => {
Expand Down

0 comments on commit fcb48e8

Please sign in to comment.