Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
mbraak committed Nov 20, 2024
1 parent cac1d1a commit 906e65d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/test/saveStateHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { Node } from "../node";
import SaveStateHandler from "../saveStateHandler";

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

Expand Down Expand Up @@ -71,4 +71,27 @@ describe("setInitialStateOnDemand", () => {

expect(openNode).not.toHaveBeenCalled();
});

it("opens a node when it's in open_nodes in the state", () => {
const node = new Node({ id: 123 });
const openNode = jest.fn();
const getNodeById = jest.fn((nodeId) => {
if (nodeId === 123) {
return node;
} else {
return null;
}
});

const saveStateHandler = createSaveStateHandler({
getNodeById,
openNode,
});
saveStateHandler.setInitialStateOnDemand(
{ open_nodes: [123] },
jest.fn(),
);

expect(openNode).toHaveBeenCalledWith(node, false);
});
});

0 comments on commit 906e65d

Please sign in to comment.