-
Notifications
You must be signed in to change notification settings - Fork 4
/
Collections-test.tsx
131 lines (117 loc) · 4.24 KB
/
Collections-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
import { expect } from "chai";
import { stub } from "sinon";
import * as React from "react";
import { shallow, mount } from "enzyme";
import * as PropTypes from "prop-types";
import Admin from "../../models/Admin";
import { Collections } from "../Collections";
const collections = [
{
id: "2",
protocol: "test protocol",
marked_for_deletion: false,
name: "ODL",
},
{
id: "3",
protocol: "test protocol",
marked_for_deletion: true,
name: "Enki",
},
{
id: "4",
protocol: "test protocol",
marked_for_deletion: false,
name: "RBDigital",
},
];
import buildStore from "../../store";
describe("Collections", () => {
let wrapper;
let registerLibrary;
let fetchLibraryRegistrations;
const systemAdmin = new Admin([{ role: "system", library: "nypl" }]);
const childContextTypes = {
admin: PropTypes.object.isRequired,
};
describe("In Edit mode", () => {
beforeEach(() => {
registerLibrary = stub().returns(
new Promise<void>((resolve) => resolve())
);
fetchLibraryRegistrations = stub();
wrapper = mount(
<Collections
csrfToken="token"
editOrCreate="edit"
data={{ collections, protocols: [] }}
identifier="2"
registerLibrary={registerLibrary}
fetchLibraryRegistrations={fetchLibraryRegistrations}
/>,
{ context: { admin: systemAdmin } }
);
});
it("includes registerLibrary in child context, and fetches library registrations on mount and after registering", async () => {
const context = wrapper.instance().getChildContext();
expect(fetchLibraryRegistrations.callCount).to.equal(1);
const library = { short_name: "nypl" };
context.registerLibrary(library);
expect(registerLibrary.callCount).to.equal(1);
const formData = registerLibrary.args[0][0];
expect(formData.get("library_short_name")).to.equal("nypl");
expect(formData.get("collection_id")).to.equal("2");
const pause = new Promise<void>((resolve) => setTimeout(resolve, 0));
await pause;
expect(fetchLibraryRegistrations.callCount).to.equal(2);
});
});
describe("In create/list mode", () => {
beforeEach(() => {
registerLibrary = stub().returns(
new Promise<void>((resolve) => resolve())
);
fetchLibraryRegistrations = stub();
const store = buildStore();
wrapper = mount(
<Collections
csrfToken="token"
store={store}
data={{ collections, protocols: [] }}
registerLibrary={registerLibrary}
fetchLibraryRegistrations={fetchLibraryRegistrations}
/>,
{ context: { admin: systemAdmin } }
);
});
it("should render a list of collections and the second collection is marked for deletion", () => {
const h2 = wrapper.find("h2");
const ul = wrapper.find("ul");
const li = ul.find("li");
// The second collection is marked for deletion.
const deletedCollection = li.at(1);
expect(h2.text()).to.equal("Collection configuration");
expect(ul.length).to.equal(1);
expect(li.length).to.equal(3);
// Only one collection is marked as deleted and that list item
// should have the `deleted-collection` class for display in the UI
expect(ul.find(".deleted-collection").length).to.equal(1);
// The second collection is marked for deletion.
expect(deletedCollection.find("h4").text()).to.equal("Enki");
expect(deletedCollection.find("p").text()).to.equal(
"This collection cannot be edited and is currently being deleted. " +
"The deletion process is gradual and this collection will be removed once it is complete."
);
});
it("should not render edit or delete buttons for the deleted collection", () => {
const ul = wrapper.find("ul");
const li = ul.find("li");
const firstCollection = li.at(0);
const deletedCollection = li.at(1);
expect(firstCollection.find("a.edit-item").length).to.equal(1);
expect(firstCollection.find("button.delete-item").length).to.equal(1);
expect(deletedCollection.find("a.edit-item").length).to.equal(0);
expect(deletedCollection.find("button.delete-item").length).to.equal(0);
});
});
});