import { expect, type Locator, type Page } from '@playwright/test'; import { IClaimDetails, ICustomerDetails } from 'safelite-playwright-core'; import { InsuranceBasePage } from './InsuranceBasePage'; import { STATE_ABBREVIATIONS } from 'safelite-playwright-core'; import { ITestData } from 'framework/TestData'; import { step } from 'framework/localTypes/Step'; export class CCPolicyInfoPage extends InsuranceBasePage { readonly policyNumber: Locator; readonly policyZip: Locator; readonly damageDate: Locator; readonly damageCause: Locator; readonly phoneNumber: Locator; readonly city: Locator; readonly state: Locator; readonly hasAdditionalDamage: Locator; readonly isRentalVehicle: Locator; readonly isOtherPartyResponsibleForCoverage: Locator; readonly lossLocation: Locator; constructor(page: Page) { super(page); this.policyNumber = page.locator('#PolicyNumber'); this.policyZip = page.locator('#PolicyZip'); this.damageDate = page.locator('#LossDate'); this.damageCause = page.locator('#LossCause'); this.phoneNumber = page.locator('#PrimaryPhone'); this.city = page.locator('#LossLocCity'); this.state = page.locator('#LossLocState'); this.hasAdditionalDamage = page.locator('#HasAdditionalDamage'); this.isRentalVehicle = page.locator('#IsRentalVehicle'); this.isOtherPartyResponsibleForCoverage = page.locator('#IsOtherPartyResponsibleForCoverage'); this.lossLocation = page.locator('#LossLocationType'); } async hasCityInfo(): Promise { await expect.soft(this.damageCause).toBeVisible(); return this.city.isVisible(); } private getStateAbbreviation(stateName: string): string { const abbreviation = STATE_ABBREVIATIONS[stateName]; if (!abbreviation) { throw new Error(`State "${stateName}" not found in mapping`); } return abbreviation; } async populatePage(customerDetails: ICustomerDetails, claimDetails: IClaimDetails, isFillCityInfo: boolean): Promise { try { await this.policyNumber.fill(claimDetails.policyNumber); await this.policyZip.fill(claimDetails.policyZip || customerDetails.address.postalCode); await this.damageDate.click(); await this.damageDate.fill(claimDetails.damageDate); await this.damageCause.selectOption(claimDetails.damageCause); await this.damageCause.press('Tab'); await this.phoneNumber.fill(customerDetails.phoneNumber); if (isFillCityInfo) { await this.city.fill(customerDetails.address.city); } if (await this.state.isVisible()) { const stateAbbreviation = this.getStateAbbreviation(customerDetails.address.state); await this.state.selectOption({ value: stateAbbreviation }); } if (claimDetails.lossLocation) { await this.lossLocation.selectOption(claimDetails.lossLocation); } } catch (error) { console.error('Error populating policy info page:', error); throw error; } } @step("CCPolicyInfoPage >> Fill out claim information") async handleCCPolicyInfoPage(testData: Partial) { const { customerDetails, claimDetails} = testData; await this.populatePage(customerDetails!, claimDetails!, await this.hasCityInfo()); await this.nextPage(); } }