CASH-2572 | Update logic and unit tests

No dates should display if any of the props are missing
This commit is contained in:
scottkiener-at-safelite 2026-05-28 11:14:28 -04:00
parent 83f4c1dd4b
commit 85b8789bca
2 changed files with 8 additions and 11 deletions

View file

@ -10,7 +10,7 @@ function mountDesktop(props = {}) {
value: 1024,
});
return shallowMount(datePicker, {
props: { availableDates: AVAILABLE_DATES, modelValue: null, ...props },
props: { availableDates: AVAILABLE_DATES, startDate: "2026-01-21", endDate: "2026-01-25", modelValue: null, ...props },
});
}
@ -21,7 +21,7 @@ function mountMobile(props = {}) {
value: 375,
});
return shallowMount(datePicker, {
props: { availableDates: AVAILABLE_DATES, modelValue: null, ...props },
props: { availableDates: AVAILABLE_DATES, startDate: "2026-01-21", endDate: "2026-01-25", modelValue: null, ...props },
});
}
@ -145,7 +145,7 @@ describe("date-picker.vue", () => {
test("goForward advances windowStart by the window size", async () => {
// Use a longer range so forward is possible on desktop (window 5)
const manyDates = ["2026-01-01", "2026-01-02", "2026-01-03", "2026-01-10"];
const wrapper = mountDesktop({ availableDates: manyDates });
const wrapper = mountDesktop({ availableDates: manyDates, startDate: "2026-01-01", endDate: "2026-01-10" });
expect(wrapper.vm.canGoForward).toBe(true);
await wrapper.vm.goForward();
expect(wrapper.vm.windowStart).toBe(5);
@ -154,7 +154,7 @@ describe("date-picker.vue", () => {
test("goBack decrements windowStart by the window size", async () => {
const manyDates = ["2026-01-01", "2026-01-02", "2026-01-03", "2026-01-10"];
const wrapper = mountDesktop({ availableDates: manyDates });
const wrapper = mountDesktop({ availableDates: manyDates, startDate: "2026-01-01", endDate: "2026-01-10" });
await wrapper.vm.goForward();
await wrapper.vm.goBack();
expect(wrapper.vm.windowStart).toBe(0);
@ -181,7 +181,7 @@ describe("date-picker.vue", () => {
test("back button becomes enabled after navigating forward", async () => {
const manyDates = ["2026-01-01", "2026-01-02", "2026-01-03", "2026-01-10"];
const wrapper = mountDesktop({ availableDates: manyDates });
const wrapper = mountDesktop({ availableDates: manyDates, startDate: "2026-01-01", endDate: "2026-01-10" });
await wrapper.vm.goForward();
await wrapper.vm.$nextTick();
const backBtn = wrapper.findAll(".date-picker__nav-btn")[0];

View file

@ -124,13 +124,10 @@ export default {
allDates() {
const availableSet = new Set(this.availableDates);
if (!this.availableDates.length) return [];
if (!this.availableDates.length || !this.startDate || !this.endDate) return [];
const startStr = this.startDate ?? this.availableDates[0];
const endStr = this.endDate ?? this.availableDates[this.availableDates.length - 1];
const first = parseLocalDate(startStr);
const last = parseLocalDate(endStr);
const first = parseLocalDate(this.startDate);
const last = parseLocalDate(this.endDate);
const dates = [];
const cursor = new Date(first);