DigitalConsumer.ISS/playwright-tests/pages/VehicleDamagePage.ts
Alex Humphries 49c951fe25 Update validateURL to account for variations in query string
In scenarios that reach the order confirmation page, the query string
includes more than the issPageValue, whiche was breaking validateURL
2025-03-07 11:47:06 -05:00

150 lines
No EOL
7.3 KiB
TypeScript

import { expect, type Locator, type Page } from '@playwright/test';
import { BasePage } from './BasePage';
import { SideDoorDamage, VehicleDamage, WindshieldDamage } from '@business-logic/types/Enums';
export class VehicleDamagePage extends BasePage {
readonly page: Page;
readonly windshieldChkBox: Locator;
readonly crackButton: Locator;
readonly chipButton: Locator;
readonly sideDoorButton: Locator;
readonly driverSideButton: Locator;
readonly passengerSideButton: Locator;
readonly driverQuarterPanelChkBox: Locator;
readonly driverFrontDoorChkBox: Locator;
readonly driverBackDoorChkBox: Locator;
readonly driverSlidingDoorChkBox: Locator;
readonly driverVentGlassChkBox: Locator;
readonly passengerQuarterPanelChkBox: Locator;
readonly passengerFrontDoorChkBox: Locator;
readonly passengerBackDoorChkBox: Locator;
readonly passengerVentGlassChkBox: Locator;
readonly rearWindowChkBox: Locator;
readonly separateApptsWarning: Locator;
readonly editVehicleButton: Locator;
issPageValue = 'vehicle-damage';
constructor(page: Page) {
super(page);
this.page = page;
this.windshieldChkBox = this.page.locator('[buttonlabel="Windshield"]');
this.crackButton = this.page.locator('[buttonlabel="Crack"]');
this.chipButton = this.page.locator('[buttonlabel="Chip(s)"]');
this.sideDoorButton = this.page.locator('[buttonlabel="Side door"]');
this.driverSideButton = this.page.locator('[buttonlabel="Driver side"]');
this.passengerSideButton = this.page.locator('[buttonlabel="Passenger side"]');
this.driverQuarterPanelChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Quarter panel"]');
this.driverFrontDoorChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Front door"]');
this.driverBackDoorChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Back door"]');
this.driverVentGlassChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Vent glass"]');
this.driverSlidingDoorChkBox = this.page.locator('[aria-labelledby="driverSideOptions"]').locator('[buttonlabel="Sliding door"]');
this.passengerQuarterPanelChkBox = this.page.locator('[aria-labelledby="passengerSideOptions"]').locator('[buttonlabel="Quarter panel"]');
this.passengerFrontDoorChkBox = this.page.locator('[aria-labelledby="passengerSideOptions"]').locator('[buttonlabel="Front door"]');
this.passengerVentGlassChkBox = this.page.locator('[aria-labelledby="passengerSideOptions"]').locator('[buttonlabel="Vent glass"]');
this.passengerBackDoorChkBox = this.page.locator('[aria-labelledby="passengerSideOptions"]').locator('[buttonlabel="Back door"]');
this.rearWindowChkBox = this.page.locator('[buttonlabel="Rear window"]');
this.separateApptsWarning = this.page.locator('[class*="widget-name-HasReplacementConflict"]');
this.editVehicleButton = this.page.getByRole('link', { name: 'Edit vehicle' });
}
async checkSeparateApptsWarning() {
// Select conflict
await this.windshieldChkBox.check();
await this.chipButton.check();
await this.rearWindowChkBox.check();
// Expect warning
await expect.soft(this.separateApptsWarning).toBeAttached();
// Undo changes
await this.crackButton.check();
await this.windshieldChkBox.uncheck();
await expect.soft(this.crackButton).not.toBeVisible();
await this.rearWindowChkBox.uncheck();
}
async selectDamage(vehicleDamage: VehicleDamage[]) {
for (const damage of vehicleDamage) {
switch(damage) {
case VehicleDamage.WindshieldOneChip:
await this.windshieldChkBox.check();
await this.selectChips('1');
break;
case VehicleDamage.WindshieldTwoChips:
await this.windshieldChkBox.check();
await this.selectChips('2');
break;
case VehicleDamage.WindshieldThreeChips:
await this.windshieldChkBox.check();
await this.selectChips('3');
break;
case VehicleDamage.WindshieldCrack:
await this.windshieldChkBox.check();
await this.selectCrack();
break;
case VehicleDamage.DriverFrontDoor:
await this.sideDoorButton.check();
await this.driverSideButton.check();
await this.driverFrontDoorChkBox.check();
break;
case VehicleDamage.DriverRearDoor:
await this.sideDoorButton.check();
await this.driverSideButton.check();
await this.driverBackDoorChkBox.check();
break;
case VehicleDamage.DriverQuarterPanel:
await this.sideDoorButton.check();
await this.driverSideButton.check();
await this.driverQuarterPanelChkBox.check();
break;
case VehicleDamage.DriverVentGlass:
await this.sideDoorButton.check();
await this.driverSideButton.check();
await this.driverVentGlassChkBox.check();
break;
case VehicleDamage.DriverSlidingDoor:
await this.sideDoorButton.check();
await this.driverSideButton.check();
await this.driverSlidingDoorChkBox.check();
break;
case VehicleDamage.PassengerFrontDoor:
await this.sideDoorButton.check();
await this.passengerSideButton.check();
await this.passengerFrontDoorChkBox.check();
break;
case VehicleDamage.PassengerRearDoor:
await this.sideDoorButton.check();
await this.passengerSideButton.check();
await this.passengerBackDoorChkBox.check();
break;
case VehicleDamage.PassengerQuarterPanel:
await this.sideDoorButton.check();
await this.passengerSideButton.check();
await this.passengerQuarterPanelChkBox.click();
break;
case VehicleDamage.PassengerVentGlass:
await this.sideDoorButton.check();
await this.passengerSideButton.check();
await this.passengerVentGlassChkBox.check();
break;
case VehicleDamage.RearWindow:
await this.selectRearWindowDamage();
break;
}
}
}
async selectCrack(){
await this.crackButton.check();
}
async selectChips(numChips: string){
const numChipsButton = this.page.getByText(numChips, {exact: true});
await this.chipButton.check();
await numChipsButton.check();
}
async selectRearWindowDamage(){
await this.rearWindowChkBox.check();
}
}