DigitalConsumer.FixMyGlass/playwright-tests/pages/CoverageStatementPage.ts
maguire-arman 458e552d6b Removes URL declaration from page classes
Removes the explicit URL declaration from the page classes.

The URL validation and navigation are now handled directly within the tests, providing greater flexibility and control over test execution and removing the need to manage URLs within each page object.
2025-07-14 16:13:56 -04:00

71 lines
No EOL
3 KiB
TypeScript

import { expect, type Locator, type Page } from '@playwright/test';
import { InsuranceBasePage } from './InsuranceBasePage';
import { IClaimDetails } from 'safelite-playwright-core';
import { step } from 'framework/localTypes/Step';
import { ITestData } from 'framework/TestData';
export class CoverageStatementPage extends InsuranceBasePage {
readonly page: Page;
readonly scheduleOnlineButton: Locator;
readonly cancelMyClaimButton: Locator;
readonly deductibleAmount: Locator;
readonly verifyingCoverageText: Locator;
readonly noCompText: Locator;
readonly continueButton: Locator; // For ITAC/NoComp
constructor(page: Page) {
super(page);
this.page = page;
this.scheduleOnlineButton = this.page.getByText('Continue to schedule online');
this.cancelMyClaimButton = this.page.getByText('Cancel my claim');
this.deductibleAmount = this.page.getByRole('heading', { name: '$' }).locator('span');
this.verifyingCoverageText = this.page.getByRole('heading', { name: 'We\'re verifying your coverage' });
this.noCompText = this.page.getByRole('heading', { name: 'Your policy doesn\'t cover this service' });
this.continueButton = page.getByRole('button', { name: 'Continue' });
}
async scheduleOnline(){
await this.scheduleOnlineButton.click();
}
async cancelMyClaim(){
await this.cancelMyClaimButton.click();
}
async validateDeductibleAmount(claimDetails: IClaimDetails) {
// Format the deductible number to have 2 decimal places
const formattedDeductible = typeof claimDetails.policyDeductible === 'number'
? claimDetails.policyDeductible.toFixed(2)
: Number(claimDetails.policyDeductible).toFixed(2);
// Add a regex to match the formatted value with commas
const expectedDeductibleRegex = formattedDeductible.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
// Narrow down the selector to target the exact element
const deductibleElement = this.page.locator(
"span.deductible-text-black[data-bind='text: deductibleFormatted']"
);
const unverifiedDeductibleElement = this.verifyingCoverageText;
// Check if the locator is visible before running the expectation
if (await deductibleElement.isVisible()) {
// Check if the page contains the properly formatted deductible amount
await expect(deductibleElement).toContainText(`$${expectedDeductibleRegex}`);
}
if (await unverifiedDeductibleElement.isVisible() || await this.noCompText.isVisible()) {
// Click on continue button if unverified header is visible
await this.continueButton.click();
}
}
@step("CoverageStatementPage >> Next page: ")
async handleCoverageStatementPage(testData: Partial<ITestData>) {
const { claimDetails } = testData;
await this.validateDeductibleAmount(claimDetails!);
await this.nextPage();
}
}