-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
}); | ||
}); | ||
}); |