This repository was archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
/
Copy pathExplorerSplit.test.tsx
executable file
·81 lines (62 loc) · 2.61 KB
/
ExplorerSplit.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
jest.mock("../browser/src/Services/WindowManager")
jest.mock("../browser/src/Services/WindowManager/WindowManager")
jest.mock("../browser/src/Services/Explorer/ExplorerView")
jest.mock("../browser/src/Services/Explorer/ExplorerStore")
import * as React from "react"
import { shallow } from "enzyme"
import MockOni from "./mocks/Oni"
import { createStore } from "../browser/src/Services/Explorer/ExplorerStore"
import { ExplorerSplit } from "../browser/src/Services/Explorer/ExplorerSplit"
describe("ExplorerSplit", () => {
let explorerSplit: ExplorerSplit
let store: Store<any>
beforeEach(() => {
store = {
dispatch: jest.fn(),
getState: jest.fn(),
subscribe: jest.fn(),
replaceReducer: jest.fn(),
} as Store<any>
;(createStore as jest.Mock).mockReturnValue(store)
explorerSplit = new ExplorerSplit(new MockOni())
})
describe("locateFile", () => {
it("dispatches SELECT_FILE when called", () => {
explorerSplit.locateFile("/path/to/file.cpp")
expect(store.dispatch).toHaveBeenCalledTimes(1)
expect(store.dispatch).toHaveBeenCalledWith({
type: "SELECT_FILE",
filePath: "/path/to/file.cpp",
})
})
})
describe("_onSelectionChanged", () => {
let _getSelectedItem: jest.Mock
beforeEach(() => {
_getSelectedItem = explorerSplit["_getSelectedItem"] = jest.fn()
})
it("dispatches SELECT_FILE_SUCCESS if fileToSelect matches selected item", () => {
store.getState.mockReturnValue({ fileToSelect: "/path/to/file.cpp" })
_getSelectedItem.mockReturnValue({
type: "file",
filePath: "/path/to/file.cpp",
})
explorerSplit["_onSelectionChanged"]("a")
expect(store.dispatch).not.toHaveBeenCalled()
})
it("does not dispatch SELECT_FILE_SUCCESS if fileToSelect isn't selected", () => {
store.getState.mockReturnValue({ fileToSelect: "/path/to/file.cpp" })
_getSelectedItem.mockReturnValue({
type: "file",
filePath: "/something/else.cpp",
})
explorerSplit["_onSelectionChanged"]("a")
expect(store.dispatch).not.toHaveBeenCalled()
})
it("does not dispatch SELECT_FILE_SUCCESS if there is no fileToSelect", () => {
store.getState.mockReturnValue({ fileToSelect: null })
explorerSplit["_onSelectionChanged"]("a")
expect(store.dispatch).not.toHaveBeenCalled()
})
})
})