import { expect, type Locator, type Page } from '@playwright/test'; import { BasePage } from './BasePage'; import { IVehicleDetails } from '@business-logic/types/CustomerDetails'; export class PolicyVehiclesPage extends BasePage { readonly page: Page; issPageValue = 'policy-vehicles'; readonly addAnotherVehicleButton: Locator; readonly selectVehicleOnPolicyButton: Locator; constructor(page: Page) { super(page); this.page = page; this.addAnotherVehicleButton = this.page.getByText('Add another vehicle'); this.selectVehicleOnPolicyButton = this.page.locator(`input[type="radio"][name="policyVehiclesQuestionOption"]`).first(); } async validateVehicleIsOnPolicy(vehicleDetails: IVehicleDetails) { const vehicleRegExp = new RegExp(`${vehicleDetails.year} .+ ${vehicleDetails.model}`, 'i'); await expect.soft(this.page.getByRole('radio', {name: vehicleRegExp})).toBeAttached(); } async selectVehicle(vehicleDetails: IVehicleDetails){ const vehicleRegExp = new RegExp(`${vehicleDetails.year} .+ ${vehicleDetails.model}`, 'i'); await this.page.locator('label').filter({hasText: vehicleRegExp}).locator('div').click(); } async addAnotherVehicle(){ await this.page.getByRole('button', {name: 'Add another vehicle'}).click(); } async assertNonServiceableAlertBehavior(){ const nonServiceableWarning = this.page.getByText('Service not available for your vehicle'); await expect(nonServiceableWarning).toBeVisible(); await expect(this.continueButton).toBeDisabled(); } }