import { expect, type Locator, type Page } from '@playwright/test'; import { BasePage } from './BasePage'; import { IAddress } from '@business-logic/types/IAddress'; export class AddressLookupPage extends BasePage { readonly page: Page; readonly streetAddressTextBox: Locator; readonly cityTextBox: Locator; readonly stateDropdown: Locator; readonly zipTextBox: Locator; readonly lastNameTextBox: Locator; readonly addressNoMatchTextBox: Locator; readonly stateRestrictionsTextBox: Locator; issPageValue = 'address-lookup'; constructor(page: Page) { super(page); this.page = page; this.streetAddressTextBox = page.getByRole('textbox', { name: 'Street address' }) this.cityTextBox = page.getByRole('textbox', { name: 'City' }) this.stateDropdown = page.getByRole('combobox') this.zipTextBox = page.getByRole('textbox', { name: 'ZIP code' }) this.lastNameTextBox = page.getByRole('textbox', { name: 'Last name' }) this.addressNoMatchTextBox = page.getByText('Your address didn’t return a VIN matchPlease re-enter the information below or'); this.stateRestrictionsTextBox = page.getByText('State restrictionsLooks like'); } async enterAddress(street, city, state, zip, lastName) { this.streetAddressTextBox.clear(); this.page.waitForTimeout(250); this.streetAddressTextBox.fill(street); this.cityTextBox.clear(); this.page.waitForTimeout(250); this.cityTextBox.fill(city); this.stateDropdown.selectOption(state); this.zipTextBox.clear(); this.page.waitForTimeout(250); this.zipTextBox.fill(zip); this.lastNameTextBox.clear(); this.page.waitForTimeout(250); this.lastNameTextBox.fill(lastName); this.page.waitForTimeout(250); } async forceAddressFormToAppear() { await expect(async () => { await this.streetAddressTextBox.click(); await this.streetAddressTextBox.pressSequentially('7400 Safelite Way'); await this.streetAddressTextBox.press('Tab'); await expect(this.zipTextBox).toBeVisible({ timeout: 100 }); }).toPass(); } async populateAddress(fullAdddress: IAddress) { if (fullAdddress.street) { // Force address form to appear await this.forceAddressFormToAppear(); // Fill address await this.fillAndValidate(this.streetAddressTextBox, fullAdddress.street); await this.fillAndValidate(this.zipTextBox, fullAdddress.postalCode) await this.fillAndValidate(this.cityTextBox, fullAdddress.city); await this.stateDropdown.selectOption(fullAdddress.state); } if (fullAdddress.lastName) { await this.fillAndValidate(this.lastNameTextBox, fullAdddress.lastName!); } // if (fullAdddress.firstName!) { // await this.fillAndValidate(this.firstNameTextBox, fullAdddress.firstName); // } } async validateAddressLookupAlerts(addressSet: IAddress[]) { await this.populateAddress(addressSet[0]); await this.continueButton.click(); await expect(this.addressNoMatchTextBox).toBeVisible(); await this.populateAddress(addressSet[1]); await this.continueButton.click(); await expect(this.stateRestrictionsTextBox).toBeVisible(); await this.populateAddress(addressSet[2]); } }