-
Notifications
You must be signed in to change notification settings - Fork 4
/
AdvancedSearchBuilder-test.tsx
133 lines (104 loc) · 4.03 KB
/
AdvancedSearchBuilder-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
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
122
123
124
125
126
127
128
129
130
131
132
133
import { expect } from "chai";
import { stub } from "sinon";
import * as React from "react";
import { mount } from "enzyme";
import AdvancedSearchBuilder from "../AdvancedSearchBuilder";
import AdvancedSearchFilterInput from "../AdvancedSearchFilterInput";
import AdvancedSearchFilterViewer from "../AdvancedSearchFilterViewer";
describe("AdvancedSearchBuilder", () => {
let wrapper;
let addQuery;
let updateQueryBoolean;
let moveQuery;
let removeQuery;
let selectQuery;
let query;
beforeEach(() => {
addQuery = stub();
updateQueryBoolean = stub();
moveQuery = stub();
removeQuery = stub();
selectQuery = stub();
query = {
id: "0",
key: "genre",
value: "Horror",
};
wrapper = mount(
<AdvancedSearchBuilder
isOwner={true}
name="include"
query={query}
selectedQueryId="0"
addQuery={addQuery}
updateQueryBoolean={updateQueryBoolean}
moveQuery={moveQuery}
removeQuery={removeQuery}
selectQuery={selectQuery}
/>
);
});
it("should render an AdvancedSearchFilterInput and an AdvancedSearchFilterViewer", () => {
const filterInput = wrapper.find(AdvancedSearchFilterInput);
expect(filterInput).to.have.length(1);
expect(filterInput.prop("name")).to.equal("include");
const filterViewer = wrapper.find(AdvancedSearchFilterViewer);
expect(filterViewer).to.have.length(1);
expect(filterViewer.prop("query")).to.equal(query);
expect(filterViewer.prop("selectedQueryId")).to.equal("0");
});
it("should not render an AdvancedSearchFilterInput when isOwner is false", () => {
wrapper.setProps({
isOwner: false,
});
const filterInput = wrapper.find(AdvancedSearchFilterInput);
expect(filterInput).to.have.length(0);
});
it("should set readOnly to true on the AdvancedSearchFilterViewer when isOwner is false", () => {
wrapper.setProps({
isOwner: false,
});
expect(wrapper.find(AdvancedSearchFilterViewer).prop("readOnly")).to.equal(
true
);
});
it("should call addQuery with the correct name when a query is added in the AdvancedSearchFilterInput", () => {
const filterInput = wrapper.find(AdvancedSearchFilterInput);
const onAdd = filterInput.prop("onAdd");
const newQuery = {
key: "title",
value: "The Shining",
};
onAdd(newQuery);
expect(addQuery.callCount).to.equal(1);
expect(addQuery.args[0]).to.deep.equal(["include", newQuery]);
});
it("should call updateQueryBoolean with the correct name when a boolean query operator is changed in the AdvancedSearchFilterViewer", () => {
const filterViewer = wrapper.find(AdvancedSearchFilterViewer);
const onBooleanChange = filterViewer.prop("onBooleanChange");
onBooleanChange("2", "or");
expect(updateQueryBoolean.callCount).to.equal(1);
expect(updateQueryBoolean.args[0]).to.deep.equal(["include", "2", "or"]);
});
it("should call moveQuery with the correct name when a query is moved in the AdvancedSearchFilterViewer", () => {
const filterViewer = wrapper.find(AdvancedSearchFilterViewer);
const onMove = filterViewer.prop("onMove");
onMove("2", "33");
expect(moveQuery.callCount).to.equal(1);
expect(moveQuery.args[0]).to.deep.equal(["include", "2", "33"]);
});
it("should call removeQuery with the correct name when a query is removed in the AdvancedSearchFilterViewer", () => {
const filterViewer = wrapper.find(AdvancedSearchFilterViewer);
const onRemove = filterViewer.prop("onRemove");
onRemove("2");
expect(removeQuery.callCount).to.equal(1);
expect(removeQuery.args[0]).to.deep.equal(["include", "2"]);
});
it("should call selectQuery with the correct name when a query is selected in the AdvancedSearchFilterViewer", () => {
const filterViewer = wrapper.find(AdvancedSearchFilterViewer);
const onSelect = filterViewer.prop("onSelect");
onSelect("2");
expect(selectQuery.callCount).to.equal(1);
expect(selectQuery.args[0]).to.deep.equal(["include", "2"]);
});
});