diff --git a/playwright-tests/pages/PaymentMethodPage.ts b/playwright-tests/pages/PaymentMethodPage.ts index 7bb4a6fcc..f150bd76c 100644 --- a/playwright-tests/pages/PaymentMethodPage.ts +++ b/playwright-tests/pages/PaymentMethodPage.ts @@ -1,7 +1,7 @@ import { expect, type Locator, type Page } from '@playwright/test'; import { BasePage } from './BasePage'; import { IPaymentDetails, Soft, waitUntil } from 'safelite-playwright-core'; -import { AppointmentTimeslot, ServiceLocation, PaymentType, ServicePackage, VehicleDamage } from 'safelite-playwright-core'; +import { AppointmentTimeslot, ServiceLocation, PaymentType, ServicePackage, VehicleDamage, } from 'safelite-playwright-core'; import { PaymentMethod, ProgressBarPercentages } from 'framework/localTypes/Enums'; import { PaymentPage } from './PaymentPage'; import { AfterpayPage } from './AfterpayPage'; @@ -29,11 +29,9 @@ export class PaymentMethodPage extends BasePage { // Payment detail page validation locators readonly reviewTable: Locator; - readonly vehicleSection: Locator; - readonly damageSection: Locator; readonly serviceDetailsSection: Locator; - readonly serviceLocationSection: Locator; - readonly appointmentDateSection: Locator; + readonly serviceLocationDateandTimeSection: Locator; + readonly vehicleDamageLocationsSection: Locator; readonly contactDetailsSection: Locator; readonly cartPanelDetails: Locator; readonly subtotalText: Locator; @@ -65,11 +63,8 @@ export class PaymentMethodPage extends BasePage { this.reviewTable = this.page.locator('div.review-table'); // Section locators - find by heading text - this.vehicleSection = this.page.locator('.review-table').locator('div', { hasText: 'Vehicle' }).first(); - this.damageSection = this.page.locator('.review-table').locator('div', { hasText: 'Damage' }).first(); - this.serviceDetailsSection = this.page.locator('.review-table').locator('div', { hasText: 'Glass service only' }).first(); - this.serviceLocationSection = this.page.locator('.review-table').locator('div', { hasText: "We're coming to you" }).first(); - this.appointmentDateSection = this.page.locator('.review-table').locator('div', { hasText: 'Appointment date + time' }).first(); + this.serviceLocationDateandTimeSection = this.page.locator('.review-table').locator('div .service-location'); + this.vehicleDamageLocationsSection= this.page.locator('.review-table').locator('div.py-3[damagelocationswidgetname="DamageLocationsWidget"]'); this.contactDetailsSection = this.page.locator('.review-table').locator('div', { hasText: 'Contact details' }).first(); // Cart panel elements @@ -99,15 +94,12 @@ export class PaymentMethodPage extends BasePage { ); let expectedAppointmentDetails = new Map(); - expectedAppointmentDetails = await this.getExpectedVehicleDetails(testData, expectedAppointmentDetails); - expectedAppointmentDetails = await this.getExpectedVehicleDamage(testData, expectedAppointmentDetails); - // expectedAppointmentDetails = await this.expectedServicePackageDetails(testData, expectedAppointmentDetails); - expectedAppointmentDetails = await this.getExpectedServiceLocation(testData, expectedAppointmentDetails); - expectedAppointmentDetails = await this.getExpectedAppointmentDate(testData, expectedAppointmentDetails); - expectedAppointmentDetails = await this.getExpectedCustomerDetails(testData, expectedAppointmentDetails); + expectedAppointmentDetails = await this.getExpectedServiceLocationDateAndTimeSection(testData, expectedAppointmentDetails); + expectedAppointmentDetails = await this.getExpectedVehicleDamageLocations(testData, expectedAppointmentDetails); + expectedAppointmentDetails = await this.getExpectedContactDetails(testData, expectedAppointmentDetails); + expectedAppointmentDetails = await this.getExpectedTextServiceUpdatesOptInOrOut(testData, expectedAppointmentDetails); let actualAppointmentDetails = await this.getActualAppointmentDetails(); - for (const key in expectedAppointmentDetails) { Soft.expect(actualAppointmentDetails[key]?.map(item => item.toLowerCase())) .toEqual(expectedAppointmentDetails[key].map(item => item.toLowerCase())); @@ -399,55 +391,43 @@ l return expectedServicePackageDetails; } - async getExpectedServiceLocation(testData: Partial, expectedServicePackageDetails: Map): Promise { - const { appointmentDetails } = testData; + async getExpectedServiceLocationDateAndTimeSection(testData: Partial, expectedServicePackageDetails: Map): Promise { + const { customerDetails, appointmentDetails } = testData; let serviceLocationTitle = appointmentDetails?.serviceLocation == ServiceLocation.Mobile ? "We're coming to you" : "You're coming to us"; let serviceLocation: string[] = []; - - serviceLocation.push( - appointmentDetails?.serviceLocation == ServiceLocation.Mobile + let serviceLocationText = appointmentDetails?.serviceLocation == ServiceLocation.Mobile ? appointmentDetails?.serviceAddress ? appointmentDetails.serviceAddress.street + ", " + appointmentDetails.serviceAddress.city + ", " + appointmentDetails.serviceAddress.state + " " + appointmentDetails.serviceAddress.postalCode : "" : appointmentDetails?.shopAddress ? appointmentDetails.shopAddress - : "" + : ""; + serviceLocationText += " on " + serviceLocationText += customerDetails?.apptDate ? await this.getFormattedAppointmentDate(customerDetails.apptDate) + " " + customerDetails?.apptTime?.replace("-", "—") : ""; + serviceLocation.push( + serviceLocationText ); expectedServicePackageDetails[serviceLocationTitle] = serviceLocation; return expectedServicePackageDetails; } - async getExpectedAppointmentDate(testData: Partial, expectedServicePackageDetails: Map): Promise { - const { customerDetails, appointmentDetails } = testData; - let appointmentDateText: string[] = []; - const isMobileAppointment = appointmentDetails?.serviceLocation == ServiceLocation.Mobile - if (isMobileAppointment) { - let localStorage= JSON.parse(await this.page.evaluate('localStorage.getItem(\'vuex\')')); - let jobMinMinutes = localStorage.order.schedule.jobMinMinutes as number; - let jobMaxMinutes = localStorage.order.schedule.jobMaxMinutes as number; + async getExpectedVehicleDamageLocations(testData: Partial, expectedServicePackageDetails: Map): Promise { + const { customerDetails } = testData; + let VehicleDamageLocationsText: string[] = []; + if (VehicleDamage.WindshieldCrack) { + let VehicleDamageLocationsText: string[] = []; + VehicleDamageLocationsText.push("Replace the windshield"); + }; - if (jobMinMinutes < 60) { - customerDetails!.apptDuration = `${jobMinMinutes} - ${jobMaxMinutes} minutes`; - } else { - const minHours = Math.floor(jobMinMinutes / 60); - const maxHours = Math.floor(jobMaxMinutes / 60); - customerDetails!.apptDuration = `${minHours} - ${maxHours} hours`; - } - } - - appointmentDateText.push( - customerDetails?.apptDate ? await this.getFormattedAppointmentDate(customerDetails.apptDate) + " " + customerDetails?.apptTime?.replace("-", "—") : "", - customerDetails?.apptDuration ? "Estimated appointment length: " + customerDetails.apptDuration : "" - ); - - expectedServicePackageDetails["Appointment Date + Time"] = appointmentDateText; + expectedServicePackageDetails["VehicleDamageLocationsText"] = VehicleDamageLocationsText; return expectedServicePackageDetails; + } - async getExpectedCustomerDetails(testData: Partial, expectedServicePackageDetails: Map): Promise { + async getExpectedContactDetails(testData: Partial, expectedServicePackageDetails: Map): Promise { const { customerDetails } = testData; let customerDetailsText: string[] = []; @@ -455,13 +435,24 @@ l // customerDetails?.firstName.toUpperCase() + " " + customerDetails?.lastName.toUpperCase(), customerDetails?.email ? customerDetails?.email.toUpperCase() : "", customerDetails?.phoneNumber ? customerDetails?.phoneNumber : "", - "Opted out of text message updates" ); expectedServicePackageDetails["Contact details"] = customerDetailsText; return expectedServicePackageDetails; } + async getExpectedTextServiceUpdatesOptInOrOut(testData: Partial, expectedServicePackageDetails: Map): Promise { + const { customerDetails } = testData; + + let isOptedInForTextMessages = testData.isOptedInForTextMessages ?? false; + + let expectedText = isOptedInForTextMessages ? customerDetails?.phoneNumber : "Not opted in"; + + + expectedServicePackageDetails["We’ll text service updates to"] = expectedText + return expectedServicePackageDetails; + } + async getFormattedAppointmentDate(appointmentDate: string) { // Parse the original date