Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reporting-year-options #401

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions frontend/src/components/InputForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
43 changes: 40 additions & 3 deletions frontend/src/components/__tests__/InputForm.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand All @@ -73,12 +88,17 @@ describe('InputForm', () => {
plugins: [vuetify, pinia],
},
});
};

beforeEach(() => {
initWrapper();
});

afterEach(() => {
if (wrapper) {
wrapper.unmount();
}
vi.useRealTimers();
});

describe('submit', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down