diff --git a/libs/components/datetime/testing/src/modules/date-range-picker/date-range-picker-harness.spec.ts b/libs/components/datetime/testing/src/modules/date-range-picker/date-range-picker-harness.spec.ts index 9a3008c2f3..c846db2e7f 100644 --- a/libs/components/datetime/testing/src/modules/date-range-picker/date-range-picker-harness.spec.ts +++ b/libs/components/datetime/testing/src/modules/date-range-picker/date-range-picker-harness.spec.ts @@ -297,8 +297,9 @@ describe('Date range picker harness', () => { ); await dateRangePickerHarness.selectCalculator( - SkyDateRangeCalculatorId.SpecificRange, + SkyDateRangeCalculatorId.Before, ); + await expectAsync(dateRangePickerHarness.isEndDateVisible()).toBeResolvedTo( true, ); @@ -308,7 +309,7 @@ describe('Date range picker harness', () => { const { dateRangePickerHarness, fixture } = await setupTest(); await dateRangePickerHarness.selectCalculator( - SkyDateRangeCalculatorId.SpecificRange, + SkyDateRangeCalculatorId.After, ); const newDate = new Date('01/12/1997').toLocaleDateString('en-us', { @@ -320,7 +321,7 @@ describe('Date range picker harness', () => { await dateRangePickerHarness.setStartDateValue(newDate); expect(fixture.componentInstance.pickerControl.value).toEqual({ - calculatorId: 3, + calculatorId: 2, startDate: new Date('01/12/1997'), endDate: null, }); @@ -334,7 +335,7 @@ describe('Date range picker harness', () => { const { dateRangePickerHarness, fixture } = await setupTest(); await dateRangePickerHarness.selectCalculator( - SkyDateRangeCalculatorId.SpecificRange, + SkyDateRangeCalculatorId.Before, ); const newDate = new Date('01/12/1997').toLocaleDateString('en-us', { @@ -346,7 +347,7 @@ describe('Date range picker harness', () => { await dateRangePickerHarness.setEndDateValue(newDate); expect(fixture.componentInstance.pickerControl.value).toEqual({ - calculatorId: 3, + calculatorId: 1, endDate: new Date('01/12/1997'), startDate: null, }); @@ -359,6 +360,10 @@ describe('Date range picker harness', () => { it('should throw an error if trying to get/set a date for a hidden datepicker', async () => { const { dateRangePickerHarness } = await setupTest(); + await dateRangePickerHarness.selectCalculator( + SkyDateRangeCalculatorId.AnyTime, + ); + await expectAsync( dateRangePickerHarness.getStartDateValue(), ).toBeRejectedWithError( diff --git a/libs/components/datetime/testing/src/modules/date-range-picker/date-range-picker-harness.ts b/libs/components/datetime/testing/src/modules/date-range-picker/date-range-picker-harness.ts index da2cacd74c..bf2828b14c 100644 --- a/libs/components/datetime/testing/src/modules/date-range-picker/date-range-picker-harness.ts +++ b/libs/components/datetime/testing/src/modules/date-range-picker/date-range-picker-harness.ts @@ -53,9 +53,7 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness { * Gets the end date value. */ public async getEndDateValue(): Promise { - if (!(await this.isEndDateVisible())) { - throw new Error('Unable to get end date. End datepicker is not visible.'); - } + await this.#assertEndDateVisible('Unable to get end date.'); const input = await (await this.#getEndDatepicker()).getControl(); @@ -114,11 +112,7 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness { * Gets the start date value. */ public async getStartDateValue(): Promise { - if (!(await this.isStartDateVisible())) { - throw new Error( - 'Unable to get start date. Start datepicker is not visible.', - ); - } + await this.#assertStartDateVisible('Unable to get start date.'); const input = await (await this.#getStartDatepicker()).getControl(); @@ -169,9 +163,11 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness { * Whether end date datepicker is visible. */ public async isEndDateVisible(): Promise { - return !(await ( + const hidden = await ( await this.locatorFor('.sky-date-range-picker-end-date')() - ).getProperty('hidden')); + ).getProperty('hidden'); + + return !hidden; } /** @@ -185,9 +181,11 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness { * Whether start date datepicker is visible. */ public async isStartDateVisible(): Promise { - return !(await ( + const hidden = await ( await this.locatorFor('.sky-date-range-picker-start-date')() - ).getProperty('hidden')); + ).getProperty('hidden'); + + return !hidden; } /** @@ -226,10 +224,10 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness { * @param newDate date input as a formatted string. */ public async setEndDateValue(newDate: string): Promise { - if (!(await this.isEndDateVisible())) { - throw new Error('Unable to set end date. End datepicker is not visible.'); - } + await this.#assertEndDateVisible('Unable to set end date.'); + const input = await (await this.#getEndDatepicker()).getControl(); + await input.setValue(newDate); } @@ -238,15 +236,25 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness { * @param newDate date input as a formatted string. */ public async setStartDateValue(newDate: string): Promise { - if (!(await this.isEndDateVisible())) { - throw new Error( - 'Unable to set start date. Start datepicker is not visible.', - ); - } + await this.#assertStartDateVisible('Unable to set start date.'); + const input = await (await this.#getStartDatepicker()).getControl(); + await input.setValue(newDate); } + async #assertEndDateVisible(message: string): Promise { + if (!(await this.isEndDateVisible())) { + throw new Error(`${message} End datepicker is not visible.`); + } + } + + async #assertStartDateVisible(message: string): Promise { + if (!(await this.isStartDateVisible())) { + throw new Error(`${message} Start datepicker is not visible.`); + } + } + async #getEndDatepicker(): Promise { return await ( await this.#getEndDateInputBoxHarness()