Skip to content

Commit

Permalink
fix(components/datetime): fix date range picker harness to assert sta…
Browse files Browse the repository at this point in the history
…rt date visible when setting values (#2938)
  • Loading branch information
Blackbaud-SteveBrush authored Dec 9, 2024
1 parent 97c7b5b commit 6868ca9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ describe('Date range picker harness', () => {
);

await dateRangePickerHarness.selectCalculator(
SkyDateRangeCalculatorId.SpecificRange,
SkyDateRangeCalculatorId.Before,
);

await expectAsync(dateRangePickerHarness.isEndDateVisible()).toBeResolvedTo(
true,
);
Expand All @@ -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', {
Expand All @@ -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,
});
Expand All @@ -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', {
Expand All @@ -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,
});
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness {
* Gets the end date value.
*/
public async getEndDateValue(): Promise<string> {
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();

Expand Down Expand Up @@ -114,11 +112,7 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness {
* Gets the start date value.
*/
public async getStartDateValue(): Promise<string> {
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();

Expand Down Expand Up @@ -169,9 +163,11 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness {
* Whether end date datepicker is visible.
*/
public async isEndDateVisible(): Promise<boolean> {
return !(await (
const hidden = await (
await this.locatorFor('.sky-date-range-picker-end-date')()
).getProperty('hidden'));
).getProperty<boolean>('hidden');

return !hidden;
}

/**
Expand All @@ -185,9 +181,11 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness {
* Whether start date datepicker is visible.
*/
public async isStartDateVisible(): Promise<boolean> {
return !(await (
const hidden = await (
await this.locatorFor('.sky-date-range-picker-start-date')()
).getProperty('hidden'));
).getProperty<boolean>('hidden');

return !hidden;
}

/**
Expand Down Expand Up @@ -226,10 +224,10 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness {
* @param newDate date input as a formatted string.
*/
public async setEndDateValue(newDate: string): Promise<void> {
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);
}

Expand All @@ -238,15 +236,25 @@ export class SkyDateRangePickerHarness extends SkyComponentHarness {
* @param newDate date input as a formatted string.
*/
public async setStartDateValue(newDate: string): Promise<void> {
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<void> {
if (!(await this.isEndDateVisible())) {
throw new Error(`${message} End datepicker is not visible.`);
}
}

async #assertStartDateVisible(message: string): Promise<void> {
if (!(await this.isStartDateVisible())) {
throw new Error(`${message} Start datepicker is not visible.`);
}
}

async #getEndDatepicker(): Promise<SkyDatepickerHarness> {
return await (
await this.#getEndDateInputBoxHarness()
Expand Down

0 comments on commit 6868ca9

Please sign in to comment.