Merge pull request #1408 from Safelite/feature/Digital/CSR-1417

CSR-1417
This commit is contained in:
hiteshkumar87 2023-10-16 19:03:16 +05:30 committed by GitHub
commit b247a03ed3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 74 deletions

View file

@ -0,0 +1,6 @@
const serviceType = {
REPLACEMENT: "replacement",
REPAIR: "repair",
REPLACEMENT_AND_RECALIBRATION: "replacement and recalibration",
};
export { serviceType };

View file

@ -7,22 +7,6 @@ export function getDateDifferenceInDays(startDate, endDate) {
// Convert milliseconds to days and return the result // Convert milliseconds to days and return the result
return difference / (1000 * 3600 * 24); return difference / (1000 * 3600 * 24);
} }
export function getFullDayName(date) {
// Use a ternary operator to check if the input is a valid date object
return date instanceof Date
? // Use the built-in method toLocaleDateString() to get the full day name in the current locale
date.toLocaleDateString(undefined, { weekday: "long" })
: // Return undefined if the input is not a valid date object
undefined;
}
export function getFullMonthName(date) {
// Use a ternary operator to check if the input is a valid date object
return date instanceof Date
? // Use the built-in method toLocaleDateString() to get the full month name in the current locale
date.toLocaleDateString(undefined, { month: "long" })
: // Return undefined if the input is not a valid date object
undefined;
}
export function get12HourTimeFormat(time) { export function get12HourTimeFormat(time) {
// Check correct time format and split into components // Check correct time format and split into components
time = time.toString().match(/^([01]\d|2[0-3])(:)([0-5]\d)?$/) || [time]; time = time.toString().match(/^([01]\d|2[0-3])(:)([0-5]\d)?$/) || [time];
@ -112,7 +96,7 @@ export function shortTimeString(date) {
// Use a ternary operator to check if the input is a valid date object // Use a ternary operator to check if the input is a valid date object
return date instanceof Date return date instanceof Date
? // Use the built-in method toLocaleTimeString() to get the short time string in the current locale ? // Use the built-in method toLocaleTimeString() to get the short time string in the current locale
date.toLocaleTimeString(undefined, { hour: "numeric", minute: "numeric", hour12: true }) date.toLocaleTimeString("en-us", { hour: "numeric", minute: "numeric", hour12: true })
: // Return undefined if the input is not a valid date object : // Return undefined if the input is not a valid date object
undefined; undefined;
} }

View file

@ -1,6 +1,4 @@
import { import {
getFullDayName,
getFullMonthName,
get12HourTimeFormat, get12HourTimeFormat,
get12HourTimeMobileFormat, get12HourTimeMobileFormat,
getDateFormat, getDateFormat,
@ -52,33 +50,17 @@ describe("date-helper.js", () => {
} }
}); });
// it("getFullMonthName should return full month format.", () => { it("getDateFormat should return date in the given format.", () => {
// // Arrange / Act // Arrange / Act
// const date = new Date("2023-10-01"); const dateString = "2023-10-01";
// const monthName = getFullMonthName(date); const dateParts = dateString.split("-");
const date = new Date(dateParts[0], parseInt(dateParts[1]) - 1, dateParts[2]);
const format = "yyyy-MM-dd";
const formattedDate = getDateFormat(date, format);
// // Assert // Assert
// expect(monthName).toEqual("October"); expect(formattedDate).toEqual("2023-10-01");
// }); });
// it("getFullDayName should return full Day Name format.", () => {
// // Arrange / Act
// const date = new Date("2023-10-01");
// const dayName = getFullDayName(date);
// // Assert
// expect(dayName).toEqual("Sunday");
// });
// it("getDateFormat should return date in the given format.", () => {
// // Arrange / Act
// const date = new Date("2023-10-01");
// const format = "yyyy-MM-dd";
// const formattedDate = getDateFormat(date, format);
// // Assert
// expect(formattedDate).toEqual("2023-10-01");
// });
it("should return the correct difference in days", function () { it("should return the correct difference in days", function () {
// Define some sample dates and their expected differences // Define some sample dates and their expected differences

View file

@ -77,9 +77,9 @@ describe("Add-to-calendar methods...", () => {
//Assert //Assert
expect(wrapper.vm.$refs.calendarModalQuestion.openModal).toBeCalled(); expect(wrapper.vm.$refs.calendarModalQuestion.openModal).toBeCalled();
}); });
test("serviceType should return 'replacement and recalibration' when isRepair and funnelHasRecalibrationPart true.", () => { test("serviceType should return 'replacement and recalibration' when isRepair is false and funnelHasRecalibrationPart true.", () => {
//Arrange //Arrange
store.getters.order.damage.isRepair = true; store.getters.order.damage.isRepair = false;
store.getters.funnelHasRecalibrationPart = true; store.getters.funnelHasRecalibrationPart = true;
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
@ -89,9 +89,9 @@ describe("Add-to-calendar methods...", () => {
//Assert //Assert
expect(testValue).toEqual("replacement and recalibration"); expect(testValue).toEqual("replacement and recalibration");
}); });
test("serviceType should return 'replacement' when isRepair is true and funnelHasRecalibrationPart is false.", () => { test("serviceType should return 'replacement' when isRepair is false and funnelHasRecalibrationPart is false.", () => {
//Arrange //Arrange
store.getters.order.damage.isRepair = true; store.getters.order.damage.isRepair = false;
store.getters.funnelHasRecalibrationPart = false; store.getters.funnelHasRecalibrationPart = false;
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
@ -101,9 +101,9 @@ describe("Add-to-calendar methods...", () => {
//Assert //Assert
expect(testValue).toEqual("replacement"); expect(testValue).toEqual("replacement");
}); });
test("serviceType should return 'repair' when isRepair is false.", () => { test("serviceType should return 'repair' when isRepair is true.", () => {
//Arrange //Arrange
store.getters.order.damage.isRepair = false; store.getters.order.damage.isRepair = true;
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
//Act //Act
@ -126,7 +126,7 @@ describe("Add-to-calendar methods...", () => {
test("getappointmentData should return expected model value for appointmentType mobile.", () => { test("getappointmentData should return expected model value for appointmentType mobile.", () => {
//Arrange //Arrange
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.MOBILE; store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.MOBILE;
store.getters.order.damage.isRepair = true; store.getters.order.damage.isRepair = false;
store.getters.funnelHasRecalibrationPart = true; store.getters.funnelHasRecalibrationPart = true;
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
@ -176,7 +176,7 @@ describe("Add-to-calendar methods...", () => {
test("getappointmentData should return expected model value for appointmentType DROP_OFF.", () => { test("getappointmentData should return expected model value for appointmentType DROP_OFF.", () => {
//Arrange //Arrange
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF; store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF;
store.getters.order.damage.isRepair = false; store.getters.order.damage.isRepair = true;
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
//Act //Act
@ -188,7 +188,7 @@ describe("Add-to-calendar methods...", () => {
test("getappointmentData should return expected model value for appointmentType IN_SHOP.", () => { test("getappointmentData should return expected model value for appointmentType IN_SHOP.", () => {
//Arrange //Arrange
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.IN_SHOP; store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.IN_SHOP;
store.getters.order.damage.isRepair = false; store.getters.order.damage.isRepair = true;
const { wrapper } = setupMocks({}); const { wrapper } = setupMocks({});
//Act //Act
@ -239,12 +239,6 @@ function setupMocks({ customMountOptions }) {
}); });
const wrapper = shallowMount(addToCalendar, mountOptions); const wrapper = shallowMount(addToCalendar, mountOptions);
//wrapper.vm.setCmsContent = jest.fn();
//wrapper.vm.$refs.datePicker.initializeComponent = jest.fn();
//wrapper.vm.$refs.locationAlerts.initializeComponent = jest.fn();
//wrapper.vm.$refs.funnelFooter.updateButtonText = jest.fn();
wrapper.vm.$refs.calendarModalQuestion.openModal = jest.fn(); wrapper.vm.$refs.calendarModalQuestion.openModal = jest.fn();
return { wrapper }; return { wrapper };
} }

View file

@ -32,6 +32,7 @@ import {
import { getCalendarFile, download } from "@/helpers/add-to-calendar-helper"; import { getCalendarFile, download } from "@/helpers/add-to-calendar-helper";
import { AppointmentTypeStrings, RouteCodeFlags } from "@/constants/schedule-constants"; import { AppointmentTypeStrings, RouteCodeFlags } from "@/constants/schedule-constants";
import store from "@/store"; import store from "@/store";
import { serviceType } from "@/constants/service-type";
export default { export default {
name: "add-to-calendar", name: "add-to-calendar",
@ -127,14 +128,14 @@ export default {
serviceType() { serviceType() {
const isRepair = store.getters.order.damage.isRepair; const isRepair = store.getters.order.damage.isRepair;
const funnelHasRecalibrationPart = store.getters.funnelHasRecalibrationPart; const funnelHasRecalibrationPart = store.getters.funnelHasRecalibrationPart;
if (isRepair) { if (!isRepair) {
if (funnelHasRecalibrationPart) { if (funnelHasRecalibrationPart) {
return "replacement and recalibration"; return serviceType.REPLACEMENT_AND_RECALIBRATION;
} else { } else {
return "replacement"; return serviceType.REPLACEMENT;
} }
} }
return "repair"; return serviceType.REPAIR;
}, },
routeCode() { routeCode() {
return store.getters.order.schedule.routeCode; return store.getters.order.schedule.routeCode;

View file

@ -55,15 +55,11 @@ import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
import { AppointmentTypeStrings } from "@/constants/schedule-constants"; import { AppointmentTypeStrings } from "@/constants/schedule-constants";
import { settleAllPromises } from "@/helpers/layout-helper"; import { settleAllPromises } from "@/helpers/layout-helper";
import { applicationConfig } from "@/constants/application-config.js"; import { applicationConfig } from "@/constants/application-config.js";
import { convertDateStringToDate } from "@/layouts/schedule/helpers/schedule-helper";
import { Form } from "vee-validate"; import { Form } from "vee-validate";
import store from "@/store"; import store from "@/store";
import { import { get12HourTimeFormat, get12HourTimeMobileFormat } from "@/helpers/date-helper";
getFullDayName,
getFullMonthName,
get12HourTimeFormat,
get12HourTimeMobileFormat,
} from "@/helpers/date-helper";
export default { export default {
name: "confirmation", name: "confirmation",
async beforeRouteEnter(to, from, next) { async beforeRouteEnter(to, from, next) {
@ -174,10 +170,14 @@ export default {
return `${this.ProviderAddress},<br/> ${this.ProviderCity}, ${this.ProviderState} ${this.ProviderZipCode}`; return `${this.ProviderAddress},<br/> ${this.ProviderCity}, ${this.ProviderState} ${this.ProviderZipCode}`;
}, },
ScheduleDateFormatted() { ScheduleDateFormatted() {
const scheduleDate = new Date(this.ScheduleDate); // This conversion ensures we don't get get GMT induced date changes
return `${getFullDayName(scheduleDate)}, ${getFullMonthName( const dateObject = convertDateStringToDate(this.ScheduleDate);
scheduleDate // Ex: Tuesday, April 22
)} ${scheduleDate.getDate()}`; return dateObject.toLocaleDateString("en-us", {
weekday: "long",
month: "long",
day: "numeric",
});
}, },
ScheduleTimeFormatted() { ScheduleTimeFormatted() {
if (this.AppointmentType == AppointmentTypeStrings.MOBILE) { if (this.AppointmentType == AppointmentTypeStrings.MOBILE) {