Fix logic for scheduling appointments

This commit is contained in:
JennyNou 2026-03-18 10:42:38 -04:00
parent 02e0afe4f6
commit 303fc24735

View file

@ -56,13 +56,20 @@ export class SchedulePage extends BasePage {
// Select in shop and schedule // Select in shop and schedule
async scheduleInShop(appointmentDetails?: IAppointmentDetails){ async scheduleInShop(appointmentDetails?: IAppointmentDetails){
if (await this.inShopButton.isVisible() && appointmentDetails?.serviceLocation !== ServiceLocation.DropOff) { if (await this.inShopButton.isVisible()) {
await this.inShopButton.waitFor({ state: 'visible', timeout: 5000 });
await this.inShopButton.click(); await this.inShopButton.click();
await (await this.getTimeSlot(1)).click(); await (await this.getFirstNonDropOffTimeSlot()).click();
} else if (await this.inShopButton.isHidden() && appointmentDetails?.serviceLocation === ServiceLocation.InShop) {
await (await this.getFirstNonDropOffTimeSlot()).click();
} else if (appointmentDetails?.serviceLocation === ServiceLocation.DropOff) { } else if (appointmentDetails?.serviceLocation === ServiceLocation.DropOff) {
await this.inShopButton.isVisible(); if (await this.inShopButton.isVisible()){
await this.inShopButton.waitFor({ state: 'visible', timeout: 5000 });
await this.inShopButton.click(); await this.inShopButton.click();
await this.dropOffButton.isVisible() ? await this.dropOffButton.click() : null; } else {
await this.dropOffButton.waitFor({ state: 'visible', timeout: 5000 });
await this.dropOffButton.isVisible() ? await this.dropOffButton.click() : await (await this.getFirstNonDropOffTimeSlot()).click(); // drop off is available in the morning for same day so this is here to avoid flaky tests
}
} else { } else {
await this.selectFirstAvailableTime(); await this.selectFirstAvailableTime();
} }
@ -89,7 +96,9 @@ export class SchedulePage extends BasePage {
} }
} }
async getTimeSlot(index: number): Promise<Locator> { async getFirstNonDropOffTimeSlot(): Promise<Locator> {
return this.page.locator('.time-slot-button').nth(index); const timeSlots = this.page.locator('.time-slot-button');
const nonDropOff = timeSlots.filter({ hasNotText: /Drop & Go/i });
return nonDropOff.first();
} }
} }