Skip to content

Commit

Permalink
add a jest for SwitchToHistoryLink that tests current history case
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ahmedhamidawan committed Oct 18, 2024
1 parent 4c4720b commit 312669c
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions client/src/components/History/SwitchToHistoryLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 312669c

Please sign in to comment.