Skip to content

Commit

Permalink
Ensure metadata refetched when language changes
Browse files Browse the repository at this point in the history
  • Loading branch information
r-ash committed Nov 29, 2024
1 parent 2679a5f commit 1e4fe1f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/app/static/src/app/store/language/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const ChangeLanguageAction = async (context: ActionContext<RootState, Roo

const actions: Promise<unknown>[] = [];

if (rootState.reviewInput.population.data !== null && rootGetters["baseline/complete"]) {
actions.push(dispatch("reviewInput/getPopulationDataset"));
}

// Re-fetch input comparison data to get translated metadata if the data has previously been fetched
if (rootState.reviewInput.inputComparison.data !== null && rootGetters["baseline/complete"] && rootGetters["surveyAndProgram/complete"]) {
actions.push(dispatch("reviewInput/getInputComparisonDataset"));
Expand Down
3 changes: 1 addition & 2 deletions src/app/static/src/tests/reviewInput/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ describe("reviewInput actions", () => {
.mockImplementation(async (_metadata, _commit, _rootState, _rootGetters) => {});
const mockFiltersAfterUseShapeRegions = vi
.spyOn(utils, "filtersAfterUseShapeRegions")
.mockImplementation((...args) => [])
const deepFreeze = vi.spyOn(freezer, "deepFreeze");
.mockImplementation((...args) => []);
await actions.getPopulationDataset({commit, rootState, rootGetters} as any);

expect(commit).toHaveBeenCalledTimes(4);
Expand Down
12 changes: 9 additions & 3 deletions src/app/static/src/tests/root/actions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ describe("root actions", () => {
loading: false,
error: null,
data: {} as any
},
population: {
loading: false,
error: null,
data: {} as any
}
})
});
Expand All @@ -491,9 +496,10 @@ describe("root actions", () => {

expectChangeLanguageMutations(commit);

expect(dispatch.mock.calls.length).toBe(2);
expect(dispatch.mock.calls[0][0]).toStrictEqual("reviewInput/getInputComparisonDataset");
expect(dispatch.mock.calls[1][0]).toStrictEqual("modelCalibrate/getResult");
expect(dispatch.mock.calls.length).toBe(3);
expect(dispatch.mock.calls[0][0]).toStrictEqual("reviewInput/getPopulationDataset");
expect(dispatch.mock.calls[1][0]).toStrictEqual("reviewInput/getInputComparisonDataset");
expect(dispatch.mock.calls[2][0]).toStrictEqual("modelCalibrate/getResult");
});

it("changeLanguage does not fetch review input metadata if country code is empty", async () => {
Expand Down

0 comments on commit 1e4fe1f

Please sign in to comment.