-
Notifications
You must be signed in to change notification settings - Fork 4
/
ConfigTabContainer-test.tsx
190 lines (175 loc) · 6.03 KB
/
ConfigTabContainer-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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { expect } from "chai";
import { stub } from "sinon";
import * as React from "react";
import { mount } from "enzyme";
import buildStore from "../../store";
import ConfigTabContainer from "../ConfigTabContainer";
import Libraries from "../Libraries";
import Collections from "../Collections";
import IndividualAdmins from "../IndividualAdmins";
import PatronAuthServices from "../PatronAuthServices";
import MetadataServices from "../MetadataServices";
import CatalogServices from "../CatalogServices";
import DiscoveryServices from "../DiscoveryServices";
import SitewideAnnouncements from "../SitewideAnnouncements";
import { mockRouterContext } from "./routing";
import Admin from "../../models/Admin";
describe("ConfigTabContainer", () => {
let wrapper;
let context;
let push;
let store;
const systemAdmin = new Admin([{ role: "system" }]);
const libraryManagerA = new Admin([{ role: "manager", library: "a" }]);
const sitewideLibrarian = new Admin([{ role: "librarian-all" }]);
describe("for system admin", () => {
beforeEach(() => {
store = buildStore();
push = stub();
context = mockRouterContext(push);
context["admin"] = systemAdmin;
wrapper = mount(
<ConfigTabContainer
tab={null}
csrfToken="token"
store={store}
editOrCreate="edit"
identifier="identifier"
/>,
{ context }
);
});
it("shows tabs", () => {
const links = wrapper.find("ul.nav-tabs").find("a");
const linkTexts = links.map((link) => link.text());
expect(linkTexts).to.contain("Libraries");
expect(linkTexts).to.contain("Admins");
expect(linkTexts).to.contain("Collections");
expect(linkTexts).to.contain("Patron Authentication");
expect(linkTexts).to.contain("Metadata");
expect(linkTexts).to.contain("External Catalogs");
expect(linkTexts).to.contain("Sitewide Announcements");
});
it("shows components", () => {
const componentClasses = [
Libraries,
IndividualAdmins,
Collections,
PatronAuthServices,
MetadataServices,
CatalogServices,
DiscoveryServices,
SitewideAnnouncements,
];
for (const componentClass of componentClasses) {
const component = wrapper.find(componentClass);
expect(component.props().csrfToken).to.equal("token");
expect(component.props().editOrCreate).to.equal("edit");
expect(component.props().identifier).to.equal("identifier");
}
});
it("uses router to navigate when tab is clicked", () => {
const tabs = wrapper.find("ul.nav-tabs").find("a");
tabs
.at(1)
.simulate("click", { target: { dataset: { tabkey: "collections" } } });
expect(push.callCount).to.equal(1);
expect(push.args[0][0]).to.equal("/admin/web/config/collections");
});
});
describe("for library manager", () => {
beforeEach(() => {
store = buildStore();
push = stub();
context = mockRouterContext(push);
context["admin"] = libraryManagerA;
wrapper = mount(
<ConfigTabContainer
tab={null}
csrfToken="token"
store={store}
editOrCreate="edit"
identifier="identifier"
/>,
{ context }
);
});
it("shows tabs", () => {
const links = wrapper.find("ul.nav-tabs").find("a");
const linkTexts = links.map((link) => link.text());
expect(linkTexts).to.contain("Libraries");
expect(linkTexts).to.contain("Admins");
expect(linkTexts).not.to.contain("Collections");
expect(linkTexts).not.to.contain("Patron Authentication");
expect(linkTexts).not.to.contain("Metadata");
expect(linkTexts).not.to.contain("External Catalogs");
});
it("shows components", () => {
const expectedComponentClasses = [Libraries, IndividualAdmins];
for (const componentClass of expectedComponentClasses) {
const component = wrapper.find(componentClass);
expect(component.props().csrfToken).to.equal("token");
expect(component.props().editOrCreate).to.equal("edit");
expect(component.props().identifier).to.equal("identifier");
}
const hiddenComponentClasses = [
Collections,
PatronAuthServices,
MetadataServices,
CatalogServices,
DiscoveryServices,
SitewideAnnouncements,
];
for (const componentClass of hiddenComponentClasses) {
const component = wrapper.find(componentClass);
expect(component.length).to.equal(0);
}
});
});
describe("for librarian", () => {
beforeEach(() => {
store = buildStore();
push = stub();
context = mockRouterContext(push);
context["admin"] = sitewideLibrarian;
wrapper = mount(
<ConfigTabContainer
tab={null}
csrfToken="token"
store={store}
editOrCreate="edit"
identifier="identifier"
/>,
{ context }
);
});
it("shows tabs", () => {
const links = wrapper.find("ul.nav-tabs").find("a");
expect(links.length).to.equal(1);
const linkTexts = links.map((link) => link.text());
expect(linkTexts).to.contain("Libraries");
});
it("shows components", () => {
const expectedComponentClasses = [Libraries];
for (const componentClass of expectedComponentClasses) {
const component = wrapper.find(componentClass);
expect(component.props().csrfToken).to.equal("token");
expect(component.props().editOrCreate).to.equal("edit");
expect(component.props().identifier).to.equal("identifier");
}
const hiddenComponentClasses = [
Collections,
IndividualAdmins,
PatronAuthServices,
MetadataServices,
CatalogServices,
DiscoveryServices,
SitewideAnnouncements,
];
for (const componentClass of hiddenComponentClasses) {
const component = wrapper.find(componentClass);
expect(component.length).to.equal(0);
}
});
});
});