From 312669c1afdc26f77e8c6fe8381ad8f0666944f8 Mon Sep 17 00:00:00 2001 From: Ahmed Awan Date: Wed, 2 Oct 2024 16:22:53 -0500 Subject: [PATCH] add a jest for `SwitchToHistoryLink` that tests current history case For the current history, we show a title saying "This is your current history", therefore, a mock is added here for `historyStore.currentHistoryId` to always return `current-history-id` regardless of which history you mount. This is done so that we can test the case when the history is current, and not. --- .../History/SwitchToHistoryLink.test.ts | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/client/src/components/History/SwitchToHistoryLink.test.ts b/client/src/components/History/SwitchToHistoryLink.test.ts index a63d5eee99fb..d5bf29c50b5e 100644 --- a/client/src/components/History/SwitchToHistoryLink.test.ts +++ b/client/src/components/History/SwitchToHistoryLink.test.ts @@ -17,6 +17,18 @@ const selectors = { historyLink: ".history-link", } as const; +// Mock the history store to always return the same current history id +jest.mock("@/stores/historyStore", () => { + const originalModule = jest.requireActual("@/stores/historyStore"); + return { + ...originalModule, + useHistoryStore: () => ({ + ...originalModule.useHistoryStore(), + currentHistoryId: "current-history-id", + }), + }; +}); + function mountSwitchToHistoryLinkForHistory(history: HistorySummaryExtended) { const pinia = createTestingPinia(); @@ -98,6 +110,18 @@ describe("SwitchToHistoryLink", () => { await expectOptionForHistory("Switch", history); }); + it("should display the appropriate text when the history is the Current history", async () => { + const history = { + id: "current-history-id", + name: "History Current", + deleted: false, + purged: false, + archived: false, + user_id: "user_id", + } as HistorySummaryExtended; + await expectOptionForHistory("This is your current history", history); + }); + it("should display the View option when the history is purged", async () => { const history = { id: "purged-history-id",