From 9c90addf6b849b0821b575406ca719d05f9c0ba9 Mon Sep 17 00:00:00 2001 From: Brock Anderson Date: Tue, 16 Apr 2024 20:17:51 -0700 Subject: [PATCH] prior to 2025, the only available reporting year is the current year. 2025 or after both the current year and the previous year are both options. --- frontend/src/components/InputForm.vue | 12 ++++-- .../components/__tests__/InputForm.spec.ts | 43 +++++++++++++++++-- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/InputForm.vue b/frontend/src/components/InputForm.vue index 21785a87e..13411fb5b 100644 --- a/frontend/src/components/InputForm.vue +++ b/frontend/src/components/InputForm.vue @@ -755,10 +755,14 @@ export default { .format(dateFormatter); }, reportYearList() { - const list = [ - LocalDate.now().minusYears(1).year(), - LocalDate.now().year(), - ]; + const list = [] as number[]; + const yearNow = LocalDate.now().year(); + if (yearNow >= 2025) { + //only include last year if the current year is at least 2025 + list.push(LocalDate.now().minusYears(1).year()); + } + //always include the current year + list.push(LocalDate.now().year()); return list; }, startMonthList() { diff --git a/frontend/src/components/__tests__/InputForm.spec.ts b/frontend/src/components/__tests__/InputForm.spec.ts index c2aaab157..3b6a5b9ae 100644 --- a/frontend/src/components/__tests__/InputForm.spec.ts +++ b/frontend/src/components/__tests__/InputForm.spec.ts @@ -1,8 +1,13 @@ -import { DateTimeFormatter, LocalDate, TemporalAdjusters } from '@js-joda/core'; +import { + DateTimeFormatter, + LocalDate, + TemporalAdjusters, + convert, +} from '@js-joda/core'; import { Locale } from '@js-joda/locale_en'; import { createTestingPinia } from '@pinia/testing'; import { mount } from '@vue/test-utils'; -import { afterEach, beforeEach, describe, expect, it } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { nextTick } from 'vue'; import { createVuetify } from 'vuetify'; import * as components from 'vuetify/components'; @@ -53,7 +58,17 @@ describe('InputForm', () => { let wrapper; let pinia; - beforeEach(() => { + const initWrapper = (options: any = {}) => { + const defaultOptions = { date: null }; + options = { ...defaultOptions, ...options }; + + if (options.date) { + vi.useFakeTimers(); + vi.setSystemTime(options.date); + } else { + vi.useRealTimers(); + } + //create an instances of vuetify and pinia so we can inject them //into the mounted component, allowing it to behave as it would //in a browser @@ -73,12 +88,17 @@ describe('InputForm', () => { plugins: [vuetify, pinia], }, }); + }; + + beforeEach(() => { + initWrapper(); }); afterEach(() => { if (wrapper) { wrapper.unmount(); } + vi.useRealTimers(); }); describe('submit', () => { @@ -267,6 +287,23 @@ describe('InputForm', () => { ).toBeFalsy(); } }); + + describe('reportYearList', () => { + describe('when the current year is before 2025', () => { + it('the current year is the only reporting year option', () => { + initWrapper({ date: convert(LocalDate.of(2024, 12, 31)).toDate() }); + const list = wrapper.vm.reportYearList; + expect(list).toStrictEqual([2024]); + }); + }); + describe('when the current year is after 2024', () => { + it('there are two reporting year options: [previous year, current year]', () => { + initWrapper({ date: convert(LocalDate.of(2025, 1, 1)).toDate() }); + const list = wrapper.vm.reportYearList; + expect(list).toStrictEqual([2024, 2025]); + }); + }); + }); }); describe('InputForm Edit Mode', () => {