forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnavigation.spec.js
More file actions
121 lines (98 loc) · 3.59 KB
/
Copy pathnavigation.spec.js
File metadata and controls
121 lines (98 loc) · 3.59 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
import {
createStore,
selectors,
actions,
makeSource
} from "../../utils/test-head";
jest.mock("../../utils/editor");
const {
getActiveSearch,
getTextSearchQuery,
getTextSearchResults,
getTextSearchStatus,
getFileSearchQuery,
getFileSearchResults
} = selectors;
const threadClient = {
sourceContents: async () => ({
source: "function foo1() {\n const foo = 5; return foo;\n}",
contentType: "text/javascript"
}),
getBreakpointPositions: async () => ({}),
getBreakableLines: async () => [],
detachWorkers: () => {}
};
describe("navigation", () => {
it("connect sets the debuggeeUrl", async () => {
const { dispatch, getState } = createStore({
fetchWorkers: () => Promise.resolve([]),
getMainThread: () => "FakeThread"
});
await dispatch(
actions.connect(
"http://test.com/foo",
"actor",
false
)
);
expect(selectors.getDebuggeeUrl(getState())).toEqual("http://test.com/foo");
});
it("navigation closes project-search", async () => {
const { dispatch, getState, cx } = createStore(threadClient);
const mockQuery = "foo";
await dispatch(actions.newGeneratedSource(makeSource("foo1")));
await dispatch(actions.searchSources(cx, mockQuery));
let results = getTextSearchResults(getState());
expect(results).toHaveLength(1);
expect(selectors.getTextSearchQuery(getState())).toEqual("foo");
expect(getTextSearchStatus(getState())).toEqual("DONE");
await dispatch(actions.willNavigate("will-navigate"));
results = getTextSearchResults(getState());
expect(results).toHaveLength(0);
expect(getTextSearchQuery(getState())).toEqual("");
expect(getTextSearchStatus(getState())).toEqual("INITIAL");
});
it("navigation removes activeSearch 'project' value", async () => {
const { dispatch, getState } = createStore(threadClient);
dispatch(actions.setActiveSearch("project"));
expect(getActiveSearch(getState())).toBe("project");
await dispatch(actions.willNavigate("will-navigate"));
expect(getActiveSearch(getState())).toBe(null);
});
it("navigation clears the file-search query", async () => {
const { dispatch, getState, cx } = createStore(threadClient);
dispatch(actions.setFileSearchQuery(cx, "foobar"));
expect(getFileSearchQuery(getState())).toBe("foobar");
await dispatch(actions.willNavigate("will-navigate"));
expect(getFileSearchQuery(getState())).toBe("");
});
it("navigation clears the file-search results", async () => {
const { dispatch, getState, cx } = createStore(threadClient);
const searchResults = [{ line: 1, ch: 3 }, { line: 3, ch: 2 }];
dispatch(actions.updateSearchResults(cx, 2, 3, searchResults));
expect(getFileSearchResults(getState())).toEqual({
count: 2,
index: 2,
matchIndex: 1,
matches: searchResults
});
await dispatch(actions.willNavigate("will-navigate"));
expect(getFileSearchResults(getState())).toEqual({
count: 0,
index: -1,
matchIndex: -1,
matches: []
});
});
it("navigation removes activeSearch 'file' value", async () => {
const { dispatch, getState } = createStore(threadClient);
dispatch(actions.setActiveSearch("file"));
expect(getActiveSearch(getState())).toBe("file");
await dispatch(actions.willNavigate("will-navigate"));
expect(getActiveSearch(getState())).toBe(null);
});
});