Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbraak committed Nov 10, 2024
1 parent 8da7a2e commit 9dce78d
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/test/saveStateHandler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import SaveStateHandler from "../saveStateHandler";

const createSaveStateHandler = () => {
const addToSelection = jest.fn();
const getNodeById = jest.fn();
const getSelectedNodes = jest.fn();
const getTree = jest.fn();
const openNode = jest.fn();
const refreshElements = jest.fn();
const removeFromSelection = jest.fn();

return new SaveStateHandler({
addToSelection,
getNodeById,
getSelectedNodes,
getTree,
openNode,
refreshElements,
removeFromSelection,
saveState: true,
});
};

describe("getStateFromStorage", () => {
afterEach(() => {
localStorage.clear();
});

it("returns null when the state is not in local storage", () => {
localStorage.clear();

const saveStateHandler = createSaveStateHandler();
expect(saveStateHandler.getStateFromStorage()).toBeNull();
});

it("returns an array of selected nodes when 'selected_node' in the states is a number", () => {
localStorage.setItem("tree", JSON.stringify({ selected_node: 123 }));

const saveStateHandler = createSaveStateHandler();
expect(saveStateHandler.getStateFromStorage()).toEqual({
selected_node: [123],
});
});
});

0 comments on commit 9dce78d

Please sign in to comment.