Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Oct 11, 2023
1 parent ae6b549 commit 61c5081
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
5 changes: 5 additions & 0 deletions app/static/tests/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ export const mockMultiSensitivityState = (state: Partial<MultiSensitivityState>
};
};

const mockUserPreferences = () => ({ showUnlabelledSessions: true });

export const mockBasicState = (state: Partial<BasicState> = {}): BasicState => {
return {
sessionId: "123",
Expand All @@ -215,6 +217,7 @@ export const mockBasicState = (state: Partial<BasicState> = {}): BasicState => {
configured: false,
persisted: true,
language: mockLanguageState(),
userPreferences: mockUserPreferences(),
...state
};
};
Expand Down Expand Up @@ -267,6 +270,7 @@ export const mockFitState = (state: Partial<FitState> = {}): FitState => {
configured: false,
persisted: false,
language: mockLanguageState(),
userPreferences: mockUserPreferences(),
...state
};
};
Expand Down Expand Up @@ -298,6 +302,7 @@ export const mockStochasticState = (state: Partial<StochasticState> = {}): Stoch
configured: false,
persisted: false,
language: mockLanguageState(),
userPreferences: mockUserPreferences(),
...state
};
};
Expand Down
28 changes: 21 additions & 7 deletions app/static/tests/unit/localStorageManager.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { localStorageManager } from "../../src/app/localStorageManager";

describe("localStorageManager for sessions", () => {
const spyOnGetItem = jest.spyOn(Storage.prototype, "getItem").mockReturnValue("[\"session1\", \"session2\"]");
const spyOnSetItem = jest.spyOn(Storage.prototype, "setItem");
let spyOnGetItem: any;
let spyOnSetItem : any;

beforeAll(() => {
spyOnGetItem = jest.spyOn(Storage.prototype, "getItem").mockReturnValue("[\"session1\", \"session2\"]");
spyOnSetItem = jest.spyOn(Storage.prototype, "setItem");
});

beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -48,9 +53,14 @@ describe("localStorageManager for sessions", () => {
});

describe("localStorageManager gets and saves user preferences", () => {
const spyOnGetItem = jest.spyOn(Storage.prototype, "getItem")
.mockReturnValue("{\"showUnlabelledSessions\": false}");
const spyOnSetItem = jest.spyOn(Storage.prototype, "setItem");
let spyOnGetItem: any;
let spyOnSetItem: any;

beforeAll(() => {
spyOnGetItem = jest.spyOn(Storage.prototype, "getItem")
.mockReturnValue("{\"showUnlabelledSessions\": false}");
spyOnSetItem = jest.spyOn(Storage.prototype, "setItem");
});

beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -70,8 +80,12 @@ describe("localStorageManager gets and saves user preferences", () => {
});

describe("localStorageManager gets default user preferences", () => {
const spyOnGetItem = jest.spyOn(Storage.prototype, "getItem")
.mockReturnValue(null);
let spyOnGetItem: any;

beforeAll(() => {
spyOnGetItem = jest.spyOn(Storage.prototype, "getItem")
.mockReturnValue(null);
});

beforeEach(() => {
jest.clearAllMocks();
Expand Down

0 comments on commit 61c5081

Please sign in to comment.