From 081bbfd161c2d7e25fedb84fd0b6612007ec83bd Mon Sep 17 00:00:00 2001 From: Adam Caouette Date: Wed, 15 Mar 2023 09:31:35 -0400 Subject: [PATCH] CSR-886: first version of date-picker along with demo page --- jest.config.js | 2 +- .../date-picker/date-picker-spec.js1 | 1 - .../date-picker/date-picker.spec.js | 67 +- .../date-picker/date-picker.vue | 601 +++++++++++------- src/constants/scheduling.js | 16 + .../demo-date-picker/demo-date-picker.vue | 48 +- 6 files changed, 494 insertions(+), 241 deletions(-) delete mode 100644 src/common-components/date-picker/date-picker-spec.js1 create mode 100644 src/constants/scheduling.js diff --git a/jest.config.js b/jest.config.js index bfb4bf71f..ceeb6f781 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,7 +15,7 @@ module.exports = { "!src/layouts/vehicle-damage/windshield-options/windshield-options.vue", "!src/layouts/reveal/**/*.vue", "!src/ux-components/text-link/**/*.vue", - "!src/common-components/date-picker/**/*.vue", + "!src/common-components/date-picker/**/*.vue", // Temp until unit tests completed "!src/layouts/vin-lookup/**/*.vue", //Temporary for Quote page testing "!src/common-components/funnel-header/menu-modal/**/*.vue", // END diff --git a/src/common-components/date-picker/date-picker-spec.js1 b/src/common-components/date-picker/date-picker-spec.js1 deleted file mode 100644 index 3d0843e10..000000000 --- a/src/common-components/date-picker/date-picker-spec.js1 +++ /dev/null @@ -1 +0,0 @@ -test.todo("some test to be written in the future"); diff --git a/src/common-components/date-picker/date-picker.spec.js b/src/common-components/date-picker/date-picker.spec.js index de02d2f72..cf6aae609 100644 --- a/src/common-components/date-picker/date-picker.spec.js +++ b/src/common-components/date-picker/date-picker.spec.js @@ -86,12 +86,12 @@ describe("date-picker.vue", () => { wrapper.unmount(); }); - describe("for each month in calendarData, each should have keys monthLabel, yearNum, dates, startDayIndex", () => { + describe("each month should have keys monthLabel, yearNum, dates, firstDateDayIndex", () => { const testScenarios = [ ["monthLabel", true, "string"], ["yearNum", true, "number"], ["dates", true, "object"], - ["startDayIndex", true, "number"], + ["firstDateDayIndex", true, "number"], ["monthClass", true, "string"], ]; @@ -106,7 +106,7 @@ describe("date-picker.vue", () => { // Act const calendarData = await wrapper.vm.calendarData; - console.log("calendarData: ", calendarData) + // console.log("calendarData: ", calendarData); // Assert expect(calendarData.every(containsMonthLabel)).toBe(true); @@ -118,7 +118,64 @@ describe("date-picker.vue", () => { ); }); - test("for each month in calendarData, the dates array should have the 1st of the month", async () => { + describe("the current month's week which includes today", () => { + const testScenarios = [ + ["2022-02-05T03:00:00", 1, 2, true], + ["2024-02-05T03:00:00", 4, 0, true], + ["2020-01-15T03:00:00", 12, 0, true], + ]; + + test.each(testScenarios)( + "the first date of the week including the date %s should be the date number %s and be day index %s", + async (todayDateString, startDate, dayOfWeekIndex) => { + // Arrange + const { wrapper } = setupMocks({ + propsData: { + todayOverrideDateString: todayDateString, + }, + }); + + // Act + const calendarData = await wrapper.vm.calendarData; + const currentMonthIndex = calendarData.findIndex((month) => { + console.log("month: ", month); + return month.monthClass === "currentMonth"; + }); + console.log("calendarData ", calendarData); + console.log("currentMonthIndex ", currentMonthIndex); + + // Assert + expect(calendarData[currentMonthIndex].dates[0].dateNum === startDate).toBe( + true + ); + expect( + calendarData[currentMonthIndex].dates[0].firstDateDayIndex === + dayOfWeekIndex + ).toBe(true); + + wrapper.unmount(); + } + ); + }); + + test("the current month's dates array should start with the first day of the week which includes today", async () => { + // Arrange + const { wrapper } = setupMocks({}); + const hasAFirstInDates = (obj) => obj?.dates[0].dateNum === 1; + + // Act + const calendarData = await wrapper.vm.calendarData; + const currentMonthIndex = calendarData.findIndex((month) => { + return month.monthClass === "currentMonth"; + }); + + // Assert + expect(calendarData[currentMonthIndex].dates[0].dateNum === 1).toBe(true); + + wrapper.unmount(); + }); + + test("for each month (other than current month), the dates array should have the 1st of the month", async () => { // Arrange const { wrapper } = setupMocks({}); const hasAFirstInDates = (obj) => obj?.dates[0].dateNum === 1; @@ -132,7 +189,7 @@ describe("date-picker.vue", () => { wrapper.unmount(); }); - describe("for each month in calendarData, the dates array should have correct days of month", () => { + describe("for the current month in calendarData, the dates array should have correct days of month", () => { const testScenarios = [ ["2022-02-05T03:00:00", 28, true], ["2024-02-05T03:00:00", 29, true], diff --git a/src/common-components/date-picker/date-picker.vue b/src/common-components/date-picker/date-picker.vue index 95e89c005..9ff0f5cf7 100644 --- a/src/common-components/date-picker/date-picker.vue +++ b/src/common-components/date-picker/date-picker.vue @@ -1,21 +1,17 @@ diff --git a/src/constants/scheduling.js b/src/constants/scheduling.js new file mode 100644 index 000000000..5e819a7a4 --- /dev/null +++ b/src/constants/scheduling.js @@ -0,0 +1,16 @@ +const monthsOfYear = [ + "January", + "February", + "March", + "April", + "May", + "June", + "July", + "August", + "September", + "October", + "November", + "December", +]; + +export { monthsOfYear }; \ No newline at end of file diff --git a/src/layouts/demo-date-picker/demo-date-picker.vue b/src/layouts/demo-date-picker/demo-date-picker.vue index dead25731..8799d012a 100644 --- a/src/layouts/demo-date-picker/demo-date-picker.vue +++ b/src/layouts/demo-date-picker/demo-date-picker.vue @@ -3,11 +3,17 @@
- -
- - + +
@@ -33,11 +39,27 @@ import baseMixin from "@/mixins/base-mixin"; export default { name: "demo-date-picker", - // data() { - // return { - // todayDate: new Date(), - // }; - // }, + data() { + return { + selectedDate: null, + // selectedDate: { // USE THIS FORMAT FOR A PRE-SELECTED DATE ON LOAD + // year: 2023, + // month: 3, // use 1-based index for months + // date: 21, + // }, + mockSelectableDatesData: [ + { year: 2023, month: 3, date: 4 }, + { year: 2023, month: 3, date: 5 }, + { year: 2023, month: 3, date: 22 }, + { year: 2023, month: 4, date: 13 }, + { year: 2023, month: 4, date: 14 }, + { year: 2023, month: 4, date: 26 }, + { year: 2023, month: 5, date: 21 }, + { year: 2023, month: 5, date: 23 }, + { year: 2023, month: 5, date: 25 }, + ], + }; + }, computed: { todayDate() { const today = new Date(); @@ -48,12 +70,16 @@ export default { arePagePrerequisitesValid() { return true; }, + getAvailableDates(startDate, endDate) { + this.mockSelectableDatesData.push(endDate); + // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + // temporary test method that adds endDate to list of selectable dates + return this.mockSelectableDatesData; + }, }, components: { datePicker, funnelHeader, - vehicleBanner, - funnelSubHeader, }, };