unit test cases
unit test cases
This commit is contained in:
parent
042c8d2473
commit
bc4f083368
6 changed files with 651 additions and 52 deletions
|
|
@ -6,7 +6,7 @@ export function getCalendarFile(calFile) {
|
||||||
calEvent.push("BEGIN:VCALENDAR");
|
calEvent.push("BEGIN:VCALENDAR");
|
||||||
calEvent.push("VERSION:2.0");
|
calEvent.push("VERSION:2.0");
|
||||||
calEvent.push("BEGIN:VEVENT");
|
calEvent.push("BEGIN:VEVENT");
|
||||||
calEvent.push("DTSTAMP:" + getDateFormat(new Date(), dateFormat));
|
calEvent.push("DTSTAMP:" + calFile.TimeStamp);
|
||||||
calEvent.push("UID:" + calFile.UniqueId + "@safelite.com");
|
calEvent.push("UID:" + calFile.UniqueId + "@safelite.com");
|
||||||
calEvent.push("PRODID:noreply@safelite.com");
|
calEvent.push("PRODID:noreply@safelite.com");
|
||||||
switch (calFile.Status) {
|
switch (calFile.Status) {
|
||||||
|
|
|
||||||
79
src/helpers/add-to-calendar-helper.spec.js
Normal file
79
src/helpers/add-to-calendar-helper.spec.js
Normal file
|
|
@ -0,0 +1,79 @@
|
||||||
|
import { download, getCalendarFile } from "./add-to-calendar-helper";
|
||||||
|
|
||||||
|
// Create a mock function
|
||||||
|
const mockDownload = jest.fn((filename, fileBody) => {
|
||||||
|
// Simulate creating an anchor element
|
||||||
|
const mockElement = {
|
||||||
|
setAttribute: jest.fn(),
|
||||||
|
style: { display: "none" },
|
||||||
|
click: jest.fn(),
|
||||||
|
};
|
||||||
|
// Mock the document.createElement method
|
||||||
|
document.createElement = jest.fn(() => mockElement);
|
||||||
|
// Mock the document.body.appendChild method
|
||||||
|
document.body.appendChild = jest.fn();
|
||||||
|
// Mock the document.body.removeChild method
|
||||||
|
document.body.removeChild = jest.fn();
|
||||||
|
|
||||||
|
// Call the original function with the mock element
|
||||||
|
download(filename, fileBody);
|
||||||
|
|
||||||
|
// Return the mock element for further assertions
|
||||||
|
return mockElement;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use the mock function in a test
|
||||||
|
test("download function", () => {
|
||||||
|
// Call the mock function with some arguments
|
||||||
|
const mockElement = mockDownload("test.txt", "Hello world");
|
||||||
|
|
||||||
|
// Make assertions about the mock function and the mock element
|
||||||
|
expect(mockDownload).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockDownload).toHaveBeenCalledWith("test.txt", "Hello world");
|
||||||
|
expect(mockElement.setAttribute).toHaveBeenCalledTimes(2);
|
||||||
|
expect(mockElement.setAttribute).toHaveBeenCalledWith(
|
||||||
|
"href",
|
||||||
|
"data:text/plain;charset=utf-8," + encodeURIComponent("Hello world")
|
||||||
|
);
|
||||||
|
expect(mockElement.setAttribute).toHaveBeenCalledWith("download", "test.txt");
|
||||||
|
expect(mockElement.style.display).toBe("none");
|
||||||
|
expect(mockElement.click).toHaveBeenCalledTimes(1);
|
||||||
|
expect(document.body.appendChild).toHaveBeenCalledTimes(1);
|
||||||
|
expect(document.body.appendChild).toHaveBeenCalledWith(mockElement);
|
||||||
|
expect(document.body.removeChild).toHaveBeenCalledTimes(1);
|
||||||
|
expect(document.body.removeChild).toHaveBeenCalledWith(mockElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Use the mock function in a test
|
||||||
|
test("getCalendarFile function", () => {
|
||||||
|
// Create a mock calFile object
|
||||||
|
const mockCalFile = {
|
||||||
|
UniqueId: "123456",
|
||||||
|
Status: "Busy",
|
||||||
|
StartDate: new Date(2023, 9, 11, 12, 0, 0),
|
||||||
|
EndDate: new Date(2023, 9, 11, 13, 0, 0),
|
||||||
|
Subject: "Meeting with John",
|
||||||
|
Location: "Conference Room",
|
||||||
|
Body: "Discuss the project progress",
|
||||||
|
TimeStamp: "20231011T113118",
|
||||||
|
};
|
||||||
|
|
||||||
|
// Call the mock function with the mock calFile object
|
||||||
|
const mockCalendarFile = getCalendarFile(mockCalFile);
|
||||||
|
|
||||||
|
// Make assertions about the mock function and the mock calendar file
|
||||||
|
expect(mockCalendarFile).toContain("BEGIN:VCALENDAR");
|
||||||
|
expect(mockCalendarFile).toContain("VERSION:2.0");
|
||||||
|
expect(mockCalendarFile).toContain("BEGIN:VEVENT");
|
||||||
|
expect(mockCalendarFile).toContain("DTSTAMP:20231011T113118");
|
||||||
|
expect(mockCalendarFile).toContain("UID:123456@safelite.com");
|
||||||
|
expect(mockCalendarFile).toContain("PRODID:noreply@safelite.com");
|
||||||
|
expect(mockCalendarFile).toContain("DTSTART:20231011T120000");
|
||||||
|
expect(mockCalendarFile).toContain("DTEND:20231011T130000");
|
||||||
|
expect(mockCalendarFile).toContain("X-MICROSOFT-CDO-BUSYSTATUS:BUSY");
|
||||||
|
expect(mockCalendarFile).toContain("SUMMARY:Meeting with John");
|
||||||
|
expect(mockCalendarFile).toContain("LOCATION:Conference Room");
|
||||||
|
expect(mockCalendarFile).toContain("DESCRIPTION:Discuss the project progress");
|
||||||
|
expect(mockCalendarFile).toContain("END:VEVENT");
|
||||||
|
expect(mockCalendarFile).toContain("END:VCALENDAR");
|
||||||
|
});
|
||||||
|
|
@ -1,35 +1,27 @@
|
||||||
export function getDateDifferenceInDays(startDate, endDate) {
|
export function getDateDifferenceInDays(startDate, endDate) {
|
||||||
|
// Create date objects from the input strings
|
||||||
var date1 = new Date(endDate);
|
var date1 = new Date(endDate);
|
||||||
date1.setHours(0, 0, 0, 0);
|
|
||||||
var date2 = new Date(startDate);
|
var date2 = new Date(startDate);
|
||||||
date2.setHours(0, 0, 0, 0);
|
// Use the built-in method to get the difference in milliseconds
|
||||||
// To calculate the time difference of two dates
|
var difference = date1 - date2;
|
||||||
var Difference_In_Time = date1.getTime() - date2.getTime();
|
// Convert milliseconds to days and return the result
|
||||||
// To calculate the no. of days between two dates
|
return difference / (1000 * 3600 * 24);
|
||||||
return Difference_In_Time / (1000 * 3600 * 24);
|
|
||||||
}
|
}
|
||||||
export function getFullDayName(date) {
|
export function getFullDayName(date) {
|
||||||
if (date instanceof Date !== true) return;
|
// Use a ternary operator to check if the input is a valid date object
|
||||||
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
|
return date instanceof Date
|
||||||
return days[date.getDay()];
|
? // 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) {
|
export function getFullMonthName(date) {
|
||||||
if (date instanceof Date !== true) return;
|
// Use a ternary operator to check if the input is a valid date object
|
||||||
const monthNames = [
|
return date instanceof Date
|
||||||
"January",
|
? // Use the built-in method toLocaleDateString() to get the full month name in the current locale
|
||||||
"February",
|
date.toLocaleDateString(undefined, { month: "long" })
|
||||||
"March",
|
: // Return undefined if the input is not a valid date object
|
||||||
"April",
|
undefined;
|
||||||
"May",
|
|
||||||
"June",
|
|
||||||
"July",
|
|
||||||
"August",
|
|
||||||
"September",
|
|
||||||
"October",
|
|
||||||
"November",
|
|
||||||
"December",
|
|
||||||
];
|
|
||||||
return monthNames[date.getMonth()];
|
|
||||||
}
|
}
|
||||||
export function get12HourTimeFormat(time) {
|
export function get12HourTimeFormat(time) {
|
||||||
// Check correct time format and split into components
|
// Check correct time format and split into components
|
||||||
|
|
@ -96,32 +88,31 @@ export function convertMsToTime(milliseconds) {
|
||||||
return `${padTo2Digits(hours)}${padTo2Digits(minutes)}`;
|
return `${padTo2Digits(hours)}${padTo2Digits(minutes)}`;
|
||||||
}
|
}
|
||||||
export function padTo2Digits(time) {
|
export function padTo2Digits(time) {
|
||||||
return ("0" + time).slice(-2);
|
// Use the built-in method toString() with a radix of 10 to convert the time value to a decimal string
|
||||||
|
time = time.toString(10);
|
||||||
|
// Use the conditional operator to check if the length of the string is less than 2
|
||||||
|
return time.length < 2
|
||||||
|
? // If yes, prepend a '0' to the string and return it
|
||||||
|
"0" + time
|
||||||
|
: // If no, return the original string
|
||||||
|
time;
|
||||||
}
|
}
|
||||||
export function combineDateAndTime(date, time) {
|
export function combineDateAndTime(date, time) {
|
||||||
var newDate = new Date(date);
|
// Use the Date.parse() method to convert the date and time strings to a numeric value
|
||||||
var timeParts = time.split(":");
|
var timestamp = Date.parse(date + "T" + time);
|
||||||
newDate.setHours(timeParts[0]);
|
// Use the new Date() constructor to create a new date object from the numeric value
|
||||||
newDate.setMinutes(timeParts[1]);
|
var newDate = new Date(timestamp);
|
||||||
|
// Return the new date object
|
||||||
return newDate;
|
return newDate;
|
||||||
}
|
}
|
||||||
export function addMinutes(date, minutes) {
|
export function addMinutes(date, minutes) {
|
||||||
return new Date(date.getTime() + minutes * 60000);
|
return new Date(date.getTime() + minutes * 60000);
|
||||||
}
|
}
|
||||||
export function shortTimeString(date) {
|
export function shortTimeString(date) {
|
||||||
if (date instanceof Date !== true) return;
|
// Use a ternary operator to check if the input is a valid date object
|
||||||
const hour = ("0" + date.getHours()).slice(-2);
|
return date instanceof Date
|
||||||
const minute = ("0" + date.getMinutes()).slice(-2);
|
? // Use the built-in method toLocaleTimeString() to get the short time string in the current locale
|
||||||
//const second = ("0" + date.getSeconds()).slice(-2);
|
date.toLocaleTimeString(undefined, { hour: "numeric", minute: "numeric", hour12: true })
|
||||||
let time = hour + ":" + minute;
|
: // Return undefined if the input is not a valid date object
|
||||||
// Check correct time format and split into components
|
undefined;
|
||||||
time = time.toString().match(/^([01]\d|2[0-3])(:)([0-5]\d)?$/) || [time];
|
|
||||||
|
|
||||||
if (time.length > 1) {
|
|
||||||
// If time format correct
|
|
||||||
time = time.slice(1); // Remove full string match value
|
|
||||||
time[5] = +time[0] < 12 ? " AM" : " PM"; // Set AM/PM
|
|
||||||
time[0] = +time[0] % 12 || 12; // Adjust hours
|
|
||||||
}
|
|
||||||
return time.join(""); // return adjusted time or original string
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
191
src/helpers/date-helper.spec.js
Normal file
191
src/helpers/date-helper.spec.js
Normal file
|
|
@ -0,0 +1,191 @@
|
||||||
|
import {
|
||||||
|
getFullDayName,
|
||||||
|
getFullMonthName,
|
||||||
|
get12HourTimeFormat,
|
||||||
|
get12HourTimeMobileFormat,
|
||||||
|
getDateFormat,
|
||||||
|
getDateDifferenceInDays,
|
||||||
|
calculateDuration,
|
||||||
|
padTo2Digits,
|
||||||
|
combineDateAndTime,
|
||||||
|
addMinutes,
|
||||||
|
shortTimeString,
|
||||||
|
} from "./date-helper";
|
||||||
|
describe("date-helper.js", () => {
|
||||||
|
it("get12HourTimeMobileFormat should return time in expected 12 hour mobile format.", () => {
|
||||||
|
// Define some sample times and their expected 12-hour formats
|
||||||
|
const testCases = [
|
||||||
|
{ time: "00:00", expected: "12 AM" },
|
||||||
|
{ time: "01:23", expected: "1:23 AM" },
|
||||||
|
{ time: "11:59", expected: "11:59 AM" },
|
||||||
|
{ time: "12:00", expected: "12 PM" },
|
||||||
|
{ time: "13:45", expected: "1:45 PM" },
|
||||||
|
{ time: "23:59", expected: "11:59 PM" },
|
||||||
|
];
|
||||||
|
// Loop through the test cases and call the function with each time
|
||||||
|
for (let testCase of testCases) {
|
||||||
|
// Call the function and store the result
|
||||||
|
const result = get12HourTimeMobileFormat(testCase.time);
|
||||||
|
// Assert that the result is equal to the expected 12-hour format
|
||||||
|
expect(result).toEqual(testCase.expected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Test if the function returns the correct 12-hour format for some sample times
|
||||||
|
it("should return the correct 12-hour format", function () {
|
||||||
|
// Define some sample times and their expected 12-hour formats
|
||||||
|
const testCases = [
|
||||||
|
{ time: "00:00", expected: "12:00 AM" },
|
||||||
|
{ time: "01:23", expected: "1:23 AM" },
|
||||||
|
{ time: "11:59", expected: "11:59 AM" },
|
||||||
|
{ time: "12:00", expected: "12:00 PM" },
|
||||||
|
{ time: "13:45", expected: "1:45 PM" },
|
||||||
|
{ time: "23:59", expected: "11:59 PM" },
|
||||||
|
];
|
||||||
|
// Loop through the test cases and call the function with each time
|
||||||
|
for (let testCase of testCases) {
|
||||||
|
// Call the function and store the result
|
||||||
|
const result = get12HourTimeFormat(testCase.time);
|
||||||
|
// Assert that the result is equal to the expected 12-hour format
|
||||||
|
expect(result).toEqual(testCase.expected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("getFullMonthName should return full month format.", () => {
|
||||||
|
// Arrange / Act
|
||||||
|
const date = new Date("2023-10-01");
|
||||||
|
const monthName = getFullMonthName(date);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(monthName).toEqual("October");
|
||||||
|
});
|
||||||
|
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 () {
|
||||||
|
// Define some sample dates and their expected differences
|
||||||
|
const testCases = [
|
||||||
|
{ startDate: "2023-10-12", endDate: "2023-10-15", expected: 3 },
|
||||||
|
{ startDate: "2023-01-01", endDate: "2023-01-31", expected: 30 },
|
||||||
|
{ startDate: "2022-12-31", endDate: "2023-01-01", expected: 1 },
|
||||||
|
{ startDate: "2023-02-28", endDate: "2023-03-01", expected: 1 },
|
||||||
|
{ startDate: "2023-03-01", endDate: "2023-02-28", expected: -1 },
|
||||||
|
];
|
||||||
|
// Loop through the test cases and call the function with each pair of dates
|
||||||
|
for (let testCase of testCases) {
|
||||||
|
// Call the function and store the result
|
||||||
|
const result = getDateDifferenceInDays(testCase.startDate, testCase.endDate);
|
||||||
|
// Assert that the result is equal to the expected difference
|
||||||
|
expect(result).toEqual(testCase.expected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("calculateDuration should return duration in hhmm format.", () => {
|
||||||
|
// Arrange / Act
|
||||||
|
const startDate = new Date("2023-10-01 10:00:00");
|
||||||
|
const endDate = new Date("2023-10-01 23:00:00");
|
||||||
|
const duration = calculateDuration(startDate, endDate);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(duration).toEqual("1300");
|
||||||
|
});
|
||||||
|
it("padTo2Digits should return time in 2 digit format.", () => {
|
||||||
|
// Define some sample time values and their expected strings
|
||||||
|
const testCases = [
|
||||||
|
{ time: 0, expected: "00" },
|
||||||
|
{ time: 1, expected: "01" },
|
||||||
|
{ time: 9, expected: "09" },
|
||||||
|
{ time: 10, expected: "10" },
|
||||||
|
{ time: 59, expected: "59" },
|
||||||
|
];
|
||||||
|
// Loop through the test cases and call the function with each time value
|
||||||
|
for (let testCase of testCases) {
|
||||||
|
// Call the function and store the result
|
||||||
|
const result = padTo2Digits(testCase.time);
|
||||||
|
// Assert that the result is equal to the expected string
|
||||||
|
expect(result).toEqual(testCase.expected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("combineDateAndTime should return combined dateTime format.", () => {
|
||||||
|
// Define some sample inputs and their expected outputs
|
||||||
|
const testCases = [
|
||||||
|
{ date: "2023-10-12", time: "12:00", expected: new Date(2023, 9, 12, 12, 0) },
|
||||||
|
{ date: "2023-01-01", time: "00:00", expected: new Date(2023, 0, 1, 0, 0) },
|
||||||
|
{ date: "2022-12-31", time: "23:59", expected: new Date(2022, 11, 31, 23, 59) },
|
||||||
|
{ date: "2023-02-28", time: "13:45", expected: new Date(2023, 1, 28, 13, 45) },
|
||||||
|
{ date: "2023-03-01", time: "01:23", expected: new Date(2023, 2, 1, 1, 23) },
|
||||||
|
];
|
||||||
|
// Loop through the test cases and call the function with each pair of date and time
|
||||||
|
for (let testCase of testCases) {
|
||||||
|
// Call the function and store the result
|
||||||
|
const result = combineDateAndTime(testCase.date, testCase.time);
|
||||||
|
// Assert that the result is equal to the expected new date object
|
||||||
|
expect(result.getTime()).toEqual(testCase.expected.getTime());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("addMinutes should add given time to date.", () => {
|
||||||
|
// Define some sample inputs and their expected outputs
|
||||||
|
const testCases = [
|
||||||
|
{
|
||||||
|
date: new Date(2023, 9, 12, 12, 0),
|
||||||
|
minutes: 15,
|
||||||
|
expected: new Date(2023, 9, 12, 12, 15),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date(2023, 0, 1, 0, 0),
|
||||||
|
minutes: -30,
|
||||||
|
expected: new Date(2022, 11, 31, 23, 30),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date(2022, 11, 31, 23, 59),
|
||||||
|
minutes: 1,
|
||||||
|
expected: new Date(2023, 0, 1, 0, 0),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date(2023, 1, 28, 13, 45),
|
||||||
|
minutes: 60,
|
||||||
|
expected: new Date(2023, 1, 28, 14, 45),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
date: new Date(2023, 2, 1, 1, 23),
|
||||||
|
minutes: -1440,
|
||||||
|
expected: new Date(2023, 1, 28, 1, 23),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
// Loop through the test cases and call the function with each pair of date and minutes
|
||||||
|
for (let testCase of testCases) {
|
||||||
|
// Call the function and store the result
|
||||||
|
const result = addMinutes(testCase.date, testCase.minutes);
|
||||||
|
// Assert that the result is equal to the expected modified date object
|
||||||
|
expect(result.getTime()).toEqual(testCase.expected.getTime());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
it("shortTimeString should return time in short format.", () => {
|
||||||
|
// Define some sample dates and their expected short time strings
|
||||||
|
const testCases = [
|
||||||
|
{ date: new Date(2023, 9, 12, 12, 0), expected: "12:00 PM" },
|
||||||
|
{ date: new Date(2023, 0, 1, 0, 0), expected: "12:00 AM" },
|
||||||
|
{ date: new Date(2022, 11, 31, 23, 59), expected: "11:59 PM" },
|
||||||
|
{ date: new Date(2023, 1, 28, 13, 45), expected: "1:45 PM" },
|
||||||
|
{ date: new Date(2023, 2, 1, 1, 23), expected: "1:23 AM" },
|
||||||
|
];
|
||||||
|
// Loop through the test cases and call the function with each date
|
||||||
|
for (let testCase of testCases) {
|
||||||
|
// Call the function and store the result
|
||||||
|
const result = shortTimeString(testCase.date);
|
||||||
|
// Assert that the result is equal to the expected short time string
|
||||||
|
expect(result).toEqual(testCase.expected);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
// Components
|
// Components
|
||||||
import addToCalendar from "@/layouts/add-to-calendar/add-to-calendar.vue";
|
import addToCalendar from "@/layouts/add-to-calendar/add-to-calendar.vue";
|
||||||
|
import { calendarOptions } from "@/constants/calendar-options";
|
||||||
|
import { AppointmentTypeStrings, RouteCodeFlags } from "@/constants/schedule-constants";
|
||||||
|
|
||||||
// Supporting Files
|
// Supporting Files
|
||||||
import { shallowMount } from "@vue/test-utils";
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
|
@ -75,6 +77,160 @@ 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.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.damage.isRepair = true;
|
||||||
|
store.getters.funnelHasRecalibrationPart = true;
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.serviceType();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue).toEqual("replacement and recalibration");
|
||||||
|
});
|
||||||
|
test("serviceType should return 'replacement' when isRepair is true and funnelHasRecalibrationPart is false.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.damage.isRepair = true;
|
||||||
|
store.getters.funnelHasRecalibrationPart = false;
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.serviceType();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue).toEqual("replacement");
|
||||||
|
});
|
||||||
|
test("serviceType should return 'repair' when isRepair is false.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.damage.isRepair = false;
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.serviceType();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue).toEqual("repair");
|
||||||
|
});
|
||||||
|
test("getCalendarData should return expected model value.", () => {
|
||||||
|
//Arrange
|
||||||
|
const type = calendarOptions.OUTLOOKCOM;
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.getCalendarData(type);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue.name).toEqual(calendarOptions.OUTLOOKCOM);
|
||||||
|
});
|
||||||
|
test("getappointmentData should return expected model value for appointmentType mobile.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.MOBILE;
|
||||||
|
store.getters.order.damage.isRepair = true;
|
||||||
|
store.getters.funnelHasRecalibrationPart = true;
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.getappointmentData();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue.Subject).toEqual("Safelite replacement and recalibration appointment");
|
||||||
|
});
|
||||||
|
test("getappointmentData should return expected model value for appointmentType DROP_OFF and OVERNIGHT_DROP_OFF.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF;
|
||||||
|
store.getters.order.schedule.routeCode = RouteCodeFlags.OVERNIGHT_DROP_OFF;
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.getappointmentData();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue.Subject).toEqual("Drop off your vehicle by 5:30 PM");
|
||||||
|
});
|
||||||
|
test("getappointmentData should return expected model value for appointmentType DROP_OFF and ALL_DAY_DROP_OFF and isSameDayDropOff.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF;
|
||||||
|
store.getters.order.schedule.routeCode = RouteCodeFlags.ALL_DAY_DROP_OFF;
|
||||||
|
store.getters.order.schedule.date = new Date().toISOString().split("T")[0];
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.getappointmentData();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue.Subject).toEqual("Drop off your vehicle in the next 30 - 60 minutes");
|
||||||
|
});
|
||||||
|
test("getappointmentData should return expected model value for appointmentType DROP_OFF and ALL_DAY_DROP_OFF.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF;
|
||||||
|
store.getters.order.schedule.routeCode = RouteCodeFlags.ALL_DAY_DROP_OFF;
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.getappointmentData();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue.Subject).toEqual("Drop off your vehicle between 9:00 AM - 11:00 AM");
|
||||||
|
});
|
||||||
|
test("getappointmentData should return expected model value for appointmentType DROP_OFF.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF;
|
||||||
|
store.getters.order.damage.isRepair = false;
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.getappointmentData();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue.Subject).toEqual("Safelite repair appointment");
|
||||||
|
});
|
||||||
|
test("getappointmentData should return expected model value for appointmentType IN_SHOP.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.IN_SHOP;
|
||||||
|
store.getters.order.damage.isRepair = false;
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.getappointmentData();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue.Subject).toEqual("Safelite repair appointment");
|
||||||
|
});
|
||||||
|
test("isSameDayDropOff should return true for current schedule date.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.schedule.date = new Date().toISOString().split("T")[0];
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
//Act
|
||||||
|
const testValue = wrapper.vm.isSameDayDropOff();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(testValue).toEqual(true);
|
||||||
|
});
|
||||||
|
test("setCalendarAppointment should call getAppointment method for iCAL and Outlook.", () => {
|
||||||
|
//Arrange
|
||||||
|
const newValue = { name: calendarOptions.OUTLOOK };
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
wrapper.vm.getAppointment = jest.fn();
|
||||||
|
//Act
|
||||||
|
wrapper.vm.setCalendarAppointment(newValue);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(wrapper.vm.getAppointment).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
test("setCalendarAppointment should call window.open for Google, yahoo and Outlook.com.", () => {
|
||||||
|
//Arrange
|
||||||
|
const newValue = { name: calendarOptions.GOOGLE };
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
window.open = jest.fn();
|
||||||
|
|
||||||
|
//Act
|
||||||
|
wrapper.vm.setCalendarAppointment(newValue);
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
expect(window.open).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function setupMocks({ customMountOptions }) {
|
function setupMocks({ customMountOptions }) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
// Components
|
// Components
|
||||||
import confirmation from "@/layouts/confirmation/confirmation.vue";
|
import confirmation from "@/layouts/confirmation/confirmation.vue";
|
||||||
|
import { AppointmentTypeStrings } from "@/constants/schedule-constants";
|
||||||
|
import { applicationConfig } from "@/constants/application-config.js";
|
||||||
|
|
||||||
// Supporting Files
|
// Supporting Files
|
||||||
import { shallowMount } from "@vue/test-utils";
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
|
@ -12,14 +14,14 @@ import router from "@/router";
|
||||||
jest.mock("@/helpers/layout-helper.js", () => ({
|
jest.mock("@/helpers/layout-helper.js", () => ({
|
||||||
settleAllPromises: jest.fn(),
|
settleAllPromises: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
var wordingText = "wording Text {custom:ADDRESS}";
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.restoreAllMocks();
|
jest.restoreAllMocks();
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
store.getters = {
|
store.getters = {
|
||||||
order: {
|
order: {
|
||||||
schedule: {
|
schedule: {
|
||||||
date: "2019-01-01",
|
date: "2023-01-01",
|
||||||
startTime: "09:00",
|
startTime: "09:00",
|
||||||
endTime: "10:00",
|
endTime: "10:00",
|
||||||
routeCode: "000",
|
routeCode: "000",
|
||||||
|
|
@ -33,9 +35,9 @@ beforeEach(() => {
|
||||||
supportingItems: [],
|
supportingItems: [],
|
||||||
},
|
},
|
||||||
serviceLocation: {
|
serviceLocation: {
|
||||||
address: "",
|
address: "test",
|
||||||
address2: null,
|
address2: "123",
|
||||||
city: "",
|
city: "test",
|
||||||
state: "AZ",
|
state: "AZ",
|
||||||
appointmentType: "Inshop",
|
appointmentType: "Inshop",
|
||||||
zipCode: "12345",
|
zipCode: "12345",
|
||||||
|
|
@ -112,8 +114,188 @@ describe("confirmation.vue", () => {
|
||||||
expect(window.location.assign).toHaveBeenCalled();
|
expect(window.location.assign).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
describe("computed properties...", () => {
|
||||||
|
test("ScheduleDateFormatted should return date in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ScheduleDateFormatted;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("Sunday, January 1");
|
||||||
|
});
|
||||||
|
test("ScheduleTimeFormatted should return mobile time in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.MOBILE;
|
||||||
|
store.getters.order.schedule.startTime = "09:00";
|
||||||
|
store.getters.order.schedule.endTime = "11:00";
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ScheduleTimeFormatted;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("Between 9 AM - 11 AM");
|
||||||
|
});
|
||||||
|
test("ScheduleTimeFormatted should return DROP_OFF time in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF;
|
||||||
|
store.getters.order.schedule.startTime = "09:00";
|
||||||
|
store.getters.order.schedule.endTime = "11:00";
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ScheduleTimeFormatted;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("Drop off before 9:30 AM");
|
||||||
|
});
|
||||||
|
test("ScheduleTimeFormatted should return Inshop time in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.IN_SHOP;
|
||||||
|
store.getters.order.schedule.startTime = "09:00";
|
||||||
|
store.getters.order.schedule.endTime = "11:00";
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ScheduleTimeFormatted;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("at 9:00 AM");
|
||||||
|
});
|
||||||
|
test("AppointmentWordingText should return mobile text in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.MOBILE;
|
||||||
|
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.AppointmentWordingText;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("wording Text 123, test,<br/> test, AZ 12345");
|
||||||
|
});
|
||||||
|
test("AppointmentWordingText should return DROP_OFF text in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF;
|
||||||
|
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.AppointmentWordingText;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("wording Text test1,<br/> test, AZ 12345");
|
||||||
|
});
|
||||||
|
test("AppointmentWordingText should return IN_SHOP text in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
store.getters.order.serviceLocation.appointmentType = AppointmentTypeStrings.IN_SHOP;
|
||||||
|
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.AppointmentWordingText;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("wording Text test1,<br/> test, AZ 12345");
|
||||||
|
});
|
||||||
|
test("ConfirmationEmailText should return text in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
wordingText = "{custom:MY_ACCOUNT_URL}";
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ConfirmationEmailText;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual(applicationConfig.MY_ACCOUNT);
|
||||||
|
});
|
||||||
|
test("ScheduleDate should return date in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ScheduleDate;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("2023-01-01");
|
||||||
|
});
|
||||||
|
test("ScheduleStartTime should return time in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ScheduleStartTime;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("09:00");
|
||||||
|
});
|
||||||
|
test("ScheduleEndTime should return time in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ScheduleEndTime;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("10:00");
|
||||||
|
});
|
||||||
|
test("InShopWordingText should return text in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
wordingText = "InShopWordingText format";
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.InShopWordingText;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual(wordingText);
|
||||||
|
});
|
||||||
|
test("MobileWordingText should return text in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
wordingText = "MobileWordingText format";
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.MobileWordingText;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual(wordingText);
|
||||||
|
});
|
||||||
|
test("DropOffWordingText should return text in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
wordingText = "DropOffWordingText format";
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.DropOffWordingText;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual(wordingText);
|
||||||
|
});
|
||||||
|
test("ServiceLocationFullAddress should return text in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ServiceLocationFullAddress;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("123, test,<br/> test, AZ 12345");
|
||||||
|
});
|
||||||
|
test("ProviderFullAddress should return text in expected format.", () => {
|
||||||
|
//Arrange
|
||||||
|
|
||||||
|
const { wrapper } = setupMocks({});
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const testValue = wrapper.vm.ProviderFullAddress;
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(testValue).toEqual("test1,<br/> test, AZ 12345");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
const wordingText = "wording Text";
|
|
||||||
function setupMocks({ customMountOptions }) {
|
function setupMocks({ customMountOptions }) {
|
||||||
const mountOptions = getMountOptions({
|
const mountOptions = getMountOptions({
|
||||||
...customMountOptions,
|
...customMountOptions,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue