forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchBar.spec.js
More file actions
106 lines (93 loc) · 2.53 KB
/
Copy pathSearchBar.spec.js
File metadata and controls
106 lines (93 loc) · 2.53 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
/* 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 React from "react";
import { shallow } from "enzyme";
import SearchBar from "../SearchBar";
import "../../../workers/search";
import "../../../utils/editor";
// $FlowIgnore
const SearchBarComponent = SearchBar.WrappedComponent;
jest.mock("../../../workers/search", () => ({
getMatches: () => Promise.resolve(["result"])
}));
jest.mock("../../../utils/editor", () => ({
find: () => ({ ch: "1", line: "1" })
}));
function generateDefaults() {
return {
query: "",
searchOn: true,
symbolSearchOn: true,
editor: {},
searchResults: {},
selectedSymbolType: "functions",
selectedSource: {
text: " text text query text"
},
selectedContentLoaded: true,
setFileSearchQuery: msg => msg,
symbolSearchResults: [],
modifiers: {
get: jest.fn(),
toJS: () => ({ caseSensitive: true, wholeWord: false, regexMatch: false })
},
selectedResultIndex: 0,
updateSearchResults: jest.fn(),
doSearch: jest.fn()
};
}
function render(overrides = {}) {
const defaults = generateDefaults();
const props = { ...defaults, ...overrides };
const component = shallow(<SearchBarComponent {...props} />, {
disableLifecycleMethods: true
});
return { component, props };
}
describe("SearchBar", () => {
it("should render", () => {
const { component } = render();
expect(component).toMatchSnapshot();
});
});
describe("doSearch", () => {
it("should complete a search", async () => {
const { component, props } = render();
component
.find("SearchInput")
.simulate("change", { target: { value: "query" } });
const doSearchArgs = props.doSearch.mock.calls[0][1];
expect(doSearchArgs).toMatchSnapshot();
});
});
describe("showErrorEmoji", () => {
it("true if query + no results", () => {
const { component } = render({
query: "test",
searchResults: {
count: 0
}
});
expect(component).toMatchSnapshot();
});
it("false if no query + no results", () => {
const { component } = render({
query: "",
searchResults: {
count: 0
}
});
expect(component).toMatchSnapshot();
});
it("false if query + results", () => {
const { component } = render({
query: "test",
searchResults: {
count: 10
}
});
expect(component).toMatchSnapshot();
});
});