@thepalaceproject/circulation-admin 1.43.0-post.2 → 1.43.0-post.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/CLAUDE.md +26 -12
  2. package/README.md +11 -5
  3. package/dist/circulation-admin.js +1 -1
  4. package/jest.config.js +17 -18
  5. package/package.json +4 -22
  6. package/tests/jest/actions.test.ts +962 -0
  7. package/tests/jest/components/AccountPage.test.tsx +41 -0
  8. package/tests/jest/components/AdvancedSearchBooleanFilter.test.tsx +231 -0
  9. package/tests/jest/components/AdvancedSearchBuilder.test.tsx +93 -20
  10. package/tests/jest/components/AdvancedSearchFilter.test.tsx +142 -0
  11. package/tests/jest/components/AdvancedSearchFilterInput.test.tsx +212 -0
  12. package/tests/jest/components/AdvancedSearchFilterViewer.test.tsx +52 -0
  13. package/tests/jest/components/AdvancedSearchValueFilter.test.tsx +123 -0
  14. package/tests/jest/components/Announcement.test.tsx +76 -0
  15. package/tests/jest/components/AnnouncementForm.test.tsx +229 -0
  16. package/tests/jest/components/AnnouncementsSection.test.tsx +146 -0
  17. package/tests/jest/components/Autocomplete.test.tsx +67 -0
  18. package/tests/jest/components/BookCoverEditor.test.tsx +393 -0
  19. package/tests/jest/components/BookDetails.test.tsx +133 -0
  20. package/tests/jest/components/BookDetailsContainer.test.tsx +116 -0
  21. package/tests/jest/components/BookDetailsEditor.test.tsx +275 -0
  22. package/tests/jest/components/BookDetailsTabContainer.test.tsx +237 -0
  23. package/tests/jest/components/BookEditForm.test.tsx +352 -0
  24. package/tests/jest/components/BookEditor.test.tsx +20 -21
  25. package/tests/jest/components/CatalogPage.test.tsx +158 -0
  26. package/tests/jest/components/CatalogServices.test.tsx +100 -0
  27. package/tests/jest/components/ChangePasswordForm.test.tsx +163 -0
  28. package/tests/jest/components/CirculationEventsDownloadForm.test.tsx +41 -0
  29. package/tests/jest/components/Classifications.test.tsx +166 -0
  30. package/tests/jest/components/ClassificationsForm.test.tsx +458 -0
  31. package/tests/jest/components/ClassificationsTable.test.tsx +57 -0
  32. package/tests/jest/components/Collections.test.tsx +335 -7
  33. package/tests/jest/components/ColorPicker.test.tsx +58 -0
  34. package/tests/jest/components/ComplaintForm.test.tsx +171 -0
  35. package/tests/jest/components/Complaints.test.tsx +259 -0
  36. package/tests/jest/components/ConfigPage.test.tsx +58 -0
  37. package/tests/jest/components/ConfigTabContainer.test.tsx +196 -0
  38. package/tests/jest/components/ContextProvider.test.tsx +138 -0
  39. package/tests/jest/components/Contributors.test.tsx +157 -0
  40. package/tests/jest/components/CustomListEditor.test.tsx +367 -0
  41. package/tests/jest/components/CustomListEntriesEditor.test.tsx +1240 -0
  42. package/tests/jest/components/CustomListPage.test.tsx +57 -0
  43. package/tests/jest/components/CustomListSearch.test.tsx +275 -0
  44. package/tests/jest/components/CustomLists.test.tsx +621 -4
  45. package/tests/jest/components/CustomListsForBook.test.tsx +353 -0
  46. package/tests/jest/components/CustomListsSidebar.test.tsx +251 -0
  47. package/tests/jest/components/DashboardPage.test.tsx +76 -0
  48. package/tests/jest/components/DebugAuthentication.test.tsx +1 -5
  49. package/tests/jest/components/DiagnosticsServiceTabs.test.tsx +141 -0
  50. package/tests/jest/components/DiagnosticsServiceType.test.tsx +75 -0
  51. package/tests/jest/components/DiagnosticsTabContainer.test.tsx +147 -0
  52. package/tests/jest/components/DiscoveryServices.test.tsx +154 -7
  53. package/tests/jest/components/EditableConfigList.test.tsx +606 -9
  54. package/tests/jest/components/EditableInput.test.tsx +250 -1
  55. package/tests/jest/components/EditorField.test.tsx +95 -0
  56. package/tests/jest/components/EntryPointsContainer.test.tsx +97 -0
  57. package/tests/jest/components/EntryPointsTabs.test.tsx +88 -0
  58. package/tests/jest/components/ErrorMessage.test.tsx +97 -0
  59. package/tests/jest/components/Footer.test.tsx +141 -0
  60. package/tests/jest/components/GenreForm.test.tsx +152 -0
  61. package/tests/jest/components/Header.test.tsx +421 -0
  62. package/tests/jest/components/IndividualAdminEditForm.test.tsx +506 -1
  63. package/tests/jest/components/IndividualAdmins.test.tsx +124 -8
  64. package/tests/jest/components/InputList.test.tsx +493 -0
  65. package/tests/jest/components/InventoryReportRequestModal.test.tsx +16 -42
  66. package/tests/jest/components/Lane.test.tsx +132 -10
  67. package/tests/jest/components/LaneCustomListsEditor.test.tsx +450 -0
  68. package/tests/jest/components/LaneEditor.test.tsx +377 -13
  69. package/tests/jest/components/LanePage.test.tsx +68 -0
  70. package/tests/jest/components/Lanes.test.tsx +446 -0
  71. package/tests/jest/components/LanesSidebar.test.tsx +621 -0
  72. package/tests/jest/components/LanguageField.test.tsx +40 -0
  73. package/tests/jest/components/Libraries.test.tsx +48 -0
  74. package/tests/jest/components/LibraryEditForm.test.tsx +383 -0
  75. package/tests/jest/components/LibraryRegistration.test.tsx +354 -0
  76. package/tests/jest/components/LibraryRegistrationForm.test.tsx +203 -0
  77. package/tests/jest/components/LoadButton.test.tsx +49 -0
  78. package/tests/jest/components/ManagePatrons.test.tsx +73 -0
  79. package/tests/jest/components/ManagePatronsForm.test.tsx +180 -0
  80. package/tests/jest/components/ManagePatronsTabContainer.test.tsx +143 -0
  81. package/tests/jest/components/MetadataServices.test.tsx +95 -0
  82. package/tests/jest/components/NeighborhoodAnalyticsForm.test.tsx +167 -0
  83. package/tests/jest/components/PairedMenus.test.tsx +220 -0
  84. package/tests/jest/components/PatronAuthServices.test.tsx +114 -0
  85. package/tests/jest/components/PatronBlockingRulesEditor.test.tsx +3 -1
  86. package/tests/jest/components/PatronInfo.test.tsx +54 -0
  87. package/tests/jest/components/ProtocolFormField.test.tsx +443 -7
  88. package/tests/jest/components/ResetAdobeId.test.tsx +302 -0
  89. package/tests/jest/components/SaveButton.test.tsx +47 -0
  90. package/tests/jest/components/SelfTestResult.test.tsx +164 -0
  91. package/tests/jest/components/SelfTests.test.tsx +601 -0
  92. package/tests/jest/components/SelfTestsCategory.test.tsx +200 -0
  93. package/tests/jest/components/SelfTestsTabContainer.test.tsx +216 -0
  94. package/tests/jest/components/ServiceEditForm.test.tsx +1092 -0
  95. package/tests/jest/components/ServiceWithRegistrationsEditForm.test.tsx +110 -0
  96. package/tests/jest/components/SetupPage.test.tsx +41 -0
  97. package/tests/jest/components/SingleStatListItem.test.tsx +62 -0
  98. package/tests/jest/components/SitewideAnnouncements.test.tsx +134 -0
  99. package/tests/jest/components/Stats.test.tsx +4 -15
  100. package/tests/jest/components/TabContainer.test.tsx +68 -0
  101. package/tests/jest/components/TextWithEditMode.test.tsx +218 -0
  102. package/tests/jest/components/Timestamp.test.tsx +74 -0
  103. package/tests/jest/components/ToolTip.test.tsx +46 -0
  104. package/tests/jest/components/TroubleshootingCategoryPage.test.tsx +69 -0
  105. package/tests/jest/components/TroubleshootingPage.test.tsx +94 -0
  106. package/tests/jest/components/TroubleshootingTabContainer.test.tsx +68 -0
  107. package/tests/jest/components/UpdatingLoader.test.tsx +36 -0
  108. package/tests/jest/components/WelcomePage.test.tsx +43 -0
  109. package/tests/jest/components/WithEditButton.test.tsx +55 -0
  110. package/tests/jest/components/WithRemoveButton.test.tsx +95 -0
  111. package/tests/jest/editorAdapter.test.ts +245 -0
  112. package/tests/jest/features/book.test.ts +75 -80
  113. package/tests/jest/fixtures/classificationsData.ts +45 -0
  114. package/tests/jest/fixtures/genreData.ts +811 -0
  115. package/tests/jest/index.test.tsx +50 -0
  116. package/tests/jest/models/Admin.test.ts +206 -0
  117. package/tests/jest/reducers/bookCoverPreview.test.ts +81 -0
  118. package/tests/jest/reducers/classifications.test.ts +161 -0
  119. package/tests/jest/reducers/collections.test.ts +96 -0
  120. package/tests/jest/reducers/complaints.test.ts +166 -0
  121. package/tests/jest/reducers/createFetchEditReducer.test.ts +220 -0
  122. package/tests/jest/reducers/createRegisterLibraryReducer.test.ts +51 -0
  123. package/tests/jest/reducers/customListDetails.test.ts +120 -0
  124. package/tests/jest/reducers/customListEditor.test.ts +2823 -0
  125. package/tests/jest/reducers/managePatrons.test.ts +71 -0
  126. package/tests/jest/testUtils/formDataShim.test.ts +135 -0
  127. package/tests/jest/testUtils/formDataShim.ts +112 -0
  128. package/tests/jest/utils/sharedFunctions.test.ts +121 -0
  129. package/tsconfig.json +3 -4
  130. package/.nycrc.json +0 -8
  131. package/testReporter.js +0 -29
  132. package/tests/jest/README.md +0 -6
@@ -0,0 +1,50 @@
1
+ import * as React from "react";
2
+ import * as ReactDOM from "react-dom";
3
+ import { Router } from "react-router";
4
+
5
+ import SetupPage from "../../src/components/SetupPage";
6
+
7
+ // index.tsx does `export = CirculationAdmin`.
8
+ const CirculationAdmin = require("../../src/index");
9
+
10
+ /** Walk a React element tree for an element of the given type — the structural
11
+ * analog of enzyme's `wrapper.find(Type)`, used where the tree is the app root
12
+ * and there is no rendered DOM to query against. */
13
+ function containsType(node: any, type: React.ElementType): boolean {
14
+ if (!node || typeof node !== "object") return false;
15
+ if (Array.isArray(node)) return node.some((n) => containsType(n, type));
16
+ if (node.type === type) return true;
17
+ return containsType(node.props && node.props.children, type);
18
+ }
19
+
20
+ describe("CirculationAdmin", () => {
21
+ let renderSpy: jest.SpyInstance;
22
+
23
+ beforeEach(() => {
24
+ // Capture what the bootstrap hands to ReactDOM.render without letting it
25
+ // paint into the jsdom document. We assert on the captured element tree
26
+ // (the structural analog of the original enzyme `wrapper.find(...)`); what
27
+ // SetupPage and the routed pages render is covered by their own tests.
28
+ renderSpy = jest
29
+ .spyOn(ReactDOM, "render")
30
+ .mockImplementation(() => undefined);
31
+ });
32
+
33
+ afterEach(() => {
34
+ jest.restoreAllMocks();
35
+ });
36
+
37
+ it("renders the setup page when setting up", () => {
38
+ new CirculationAdmin({ settingUp: true, csrfToken: "token" });
39
+
40
+ expect(renderSpy).toHaveBeenCalledTimes(1);
41
+ expect(containsType(renderSpy.mock.calls[0][0], SetupPage)).toBe(true);
42
+ });
43
+
44
+ it("renders the router otherwise", () => {
45
+ new CirculationAdmin({ csrfToken: "token" });
46
+
47
+ expect(renderSpy).toHaveBeenCalledTimes(1);
48
+ expect(containsType(renderSpy.mock.calls[0][0], Router)).toBe(true);
49
+ });
50
+ });
@@ -0,0 +1,206 @@
1
+ import Admin from "../../../src/models/Admin";
2
+
3
+ describe("Admin", () => {
4
+ const systemAdmin = new Admin([{ role: "system" }]);
5
+ const sitewideLibraryManager = new Admin([{ role: "manager-all" }]);
6
+ const sitewideLibrarian = new Admin([{ role: "librarian-all" }]);
7
+ const libraryManagerA = new Admin([{ role: "manager", library: "a" }]);
8
+ const librarianA = new Admin([{ role: "librarian", library: "a" }]);
9
+ const libraryManagerB = new Admin([{ role: "manager", library: "b" }]);
10
+ const librarianB = new Admin([{ role: "librarian", library: "b" }]);
11
+ const libraryManagerASitewideLibrarian = new Admin([
12
+ { role: "librarian-all" },
13
+ { role: "manager", library: "a" },
14
+ ]);
15
+ const libraryManagerALibrarianB = new Admin([
16
+ { role: "manager", library: "a" },
17
+ { role: "librarian", library: "b" },
18
+ ]);
19
+
20
+ it("stores email", () => {
21
+ expect(new Admin([], "email").email).toBe("email");
22
+ expect(new Admin([]).email).toBeFalsy();
23
+ });
24
+
25
+ it("identifies system admins", () => {
26
+ expect(systemAdmin.isSystemAdmin()).toBeTruthy();
27
+ expect(sitewideLibraryManager.isSystemAdmin()).toBeFalsy();
28
+ expect(sitewideLibrarian.isSystemAdmin()).toBeFalsy();
29
+ expect(libraryManagerA.isSystemAdmin()).toBeFalsy();
30
+ expect(librarianA.isSystemAdmin()).toBeFalsy();
31
+ expect(libraryManagerB.isSystemAdmin()).toBeFalsy();
32
+ expect(librarianB.isSystemAdmin()).toBeFalsy();
33
+ expect(libraryManagerASitewideLibrarian.isSystemAdmin()).toBeFalsy();
34
+ expect(libraryManagerALibrarianB.isSystemAdmin()).toBeFalsy();
35
+ });
36
+
37
+ it("identifies sitewide library managers", () => {
38
+ expect(systemAdmin.isSitewideLibraryManager()).toBeTruthy();
39
+ expect(sitewideLibraryManager.isSitewideLibraryManager()).toBeTruthy();
40
+ expect(sitewideLibrarian.isSitewideLibraryManager()).toBeFalsy();
41
+ expect(libraryManagerA.isSitewideLibraryManager()).toBeFalsy();
42
+ expect(librarianA.isSitewideLibraryManager()).toBeFalsy();
43
+ expect(libraryManagerB.isSitewideLibraryManager()).toBeFalsy();
44
+ expect(librarianB.isSitewideLibraryManager()).toBeFalsy();
45
+ expect(
46
+ libraryManagerASitewideLibrarian.isSitewideLibraryManager()
47
+ ).toBeFalsy();
48
+ expect(libraryManagerALibrarianB.isSitewideLibraryManager()).toBeFalsy();
49
+ });
50
+
51
+ it("identifies sitewide librarians", () => {
52
+ expect(systemAdmin.isSitewideLibrarian()).toBeTruthy();
53
+ expect(sitewideLibraryManager.isSitewideLibrarian()).toBeTruthy();
54
+ expect(sitewideLibrarian.isSitewideLibrarian()).toBeTruthy();
55
+ expect(libraryManagerA.isSitewideLibrarian()).toBeFalsy();
56
+ expect(librarianA.isSitewideLibrarian()).toBeFalsy();
57
+ expect(libraryManagerB.isSitewideLibrarian()).toBeFalsy();
58
+ expect(librarianB.isSitewideLibrarian()).toBeFalsy();
59
+ expect(libraryManagerASitewideLibrarian.isSitewideLibrarian()).toBeTruthy();
60
+ expect(libraryManagerALibrarianB.isSitewideLibrarian()).toBeFalsy();
61
+ });
62
+
63
+ it("identifies library managers", () => {
64
+ expect(systemAdmin.isLibraryManager("a")).toBeTruthy();
65
+ expect(sitewideLibraryManager.isLibraryManager("a")).toBeTruthy();
66
+ expect(sitewideLibrarian.isLibraryManager("a")).toBeFalsy();
67
+ expect(libraryManagerA.isLibraryManager("a")).toBeTruthy();
68
+ expect(librarianA.isLibraryManager("a")).toBeFalsy();
69
+ expect(libraryManagerB.isLibraryManager("a")).toBeFalsy();
70
+ expect(librarianB.isLibraryManager("a")).toBeFalsy();
71
+ expect(libraryManagerASitewideLibrarian.isLibraryManager("a")).toBeTruthy();
72
+ expect(libraryManagerALibrarianB.isLibraryManager("a")).toBeTruthy();
73
+
74
+ expect(systemAdmin.isLibraryManager("b")).toBeTruthy();
75
+ expect(sitewideLibraryManager.isLibraryManager("b")).toBeTruthy();
76
+ expect(sitewideLibrarian.isLibraryManager("b")).toBeFalsy();
77
+ expect(libraryManagerA.isLibraryManager("b")).toBeFalsy();
78
+ expect(librarianA.isLibraryManager("b")).toBeFalsy();
79
+ expect(libraryManagerB.isLibraryManager("b")).toBeTruthy();
80
+ expect(librarianB.isLibraryManager("b")).toBeFalsy();
81
+ expect(libraryManagerASitewideLibrarian.isLibraryManager("b")).toBeFalsy();
82
+ expect(libraryManagerALibrarianB.isLibraryManager("b")).toBeFalsy();
83
+ });
84
+
85
+ it("identifies librarians", () => {
86
+ expect(systemAdmin.isLibrarian("a")).toBeTruthy();
87
+ expect(sitewideLibraryManager.isLibrarian("a")).toBeTruthy();
88
+ expect(sitewideLibrarian.isLibrarian("a")).toBeTruthy();
89
+ expect(libraryManagerA.isLibrarian("a")).toBeTruthy();
90
+ expect(librarianA.isLibrarian("a")).toBeTruthy();
91
+ expect(libraryManagerB.isLibrarian("a")).toBeFalsy();
92
+ expect(librarianB.isLibrarian("a")).toBeFalsy();
93
+ expect(libraryManagerASitewideLibrarian.isLibrarian("a")).toBeTruthy();
94
+ expect(libraryManagerALibrarianB.isLibrarian("a")).toBeTruthy();
95
+
96
+ expect(systemAdmin.isLibrarian("b")).toBeTruthy();
97
+ expect(sitewideLibraryManager.isLibrarian("b")).toBeTruthy();
98
+ expect(sitewideLibrarian.isLibrarian("b")).toBeTruthy();
99
+ expect(libraryManagerA.isLibrarian("b")).toBeFalsy();
100
+ expect(librarianA.isLibrarian("b")).toBeFalsy();
101
+ expect(libraryManagerB.isLibrarian("b")).toBeTruthy();
102
+ expect(librarianB.isLibrarian("b")).toBeTruthy();
103
+ expect(libraryManagerASitewideLibrarian.isLibrarian("b")).toBeTruthy();
104
+ expect(libraryManagerALibrarianB.isLibrarian("b")).toBeTruthy();
105
+ });
106
+
107
+ it("identifies all library managers", () => {
108
+ expect(systemAdmin.isLibraryManagerOfSomeLibrary()).toBeTruthy();
109
+ expect(sitewideLibraryManager.isLibraryManagerOfSomeLibrary()).toBeTruthy();
110
+ expect(sitewideLibrarian.isLibraryManagerOfSomeLibrary()).toBeFalsy();
111
+ expect(libraryManagerA.isLibraryManagerOfSomeLibrary()).toBeTruthy();
112
+ expect(librarianA.isLibraryManagerOfSomeLibrary()).toBeFalsy();
113
+ expect(libraryManagerB.isLibraryManagerOfSomeLibrary()).toBeTruthy();
114
+ expect(librarianB.isLibraryManagerOfSomeLibrary()).toBeFalsy();
115
+ expect(
116
+ libraryManagerASitewideLibrarian.isLibraryManagerOfSomeLibrary()
117
+ ).toBeTruthy();
118
+ expect(
119
+ libraryManagerALibrarianB.isLibraryManagerOfSomeLibrary()
120
+ ).toBeTruthy();
121
+ });
122
+
123
+ it("checks for specific roles", () => {
124
+ expect(systemAdmin.hasRole("system")).toBeTruthy();
125
+ expect(systemAdmin.hasRole("manager-all")).toBeTruthy();
126
+ expect(systemAdmin.hasRole("librarian-all")).toBeTruthy();
127
+ expect(systemAdmin.hasRole("manager", "a")).toBeTruthy();
128
+ expect(systemAdmin.hasRole("librarian", "a")).toBeTruthy();
129
+ expect(systemAdmin.hasRole("manager", "b")).toBeTruthy();
130
+ expect(systemAdmin.hasRole("librarian", "b")).toBeTruthy();
131
+
132
+ expect(sitewideLibraryManager.hasRole("system")).toBeFalsy();
133
+ expect(sitewideLibraryManager.hasRole("manager-all")).toBeTruthy();
134
+ expect(sitewideLibraryManager.hasRole("librarian-all")).toBeTruthy();
135
+ expect(sitewideLibraryManager.hasRole("manager", "a")).toBeTruthy();
136
+ expect(sitewideLibraryManager.hasRole("librarian", "a")).toBeTruthy();
137
+ expect(sitewideLibraryManager.hasRole("manager", "b")).toBeTruthy();
138
+ expect(sitewideLibraryManager.hasRole("librarian", "b")).toBeTruthy();
139
+
140
+ expect(sitewideLibrarian.hasRole("system")).toBeFalsy();
141
+ expect(sitewideLibrarian.hasRole("manager-all")).toBeFalsy();
142
+ expect(sitewideLibrarian.hasRole("librarian-all")).toBeTruthy();
143
+ expect(sitewideLibrarian.hasRole("manager", "a")).toBeFalsy();
144
+ expect(sitewideLibrarian.hasRole("librarian", "a")).toBeTruthy();
145
+ expect(sitewideLibrarian.hasRole("manager", "b")).toBeFalsy();
146
+ expect(sitewideLibrarian.hasRole("librarian", "b")).toBeTruthy();
147
+
148
+ expect(libraryManagerA.hasRole("system")).toBeFalsy();
149
+ expect(libraryManagerA.hasRole("manager-all")).toBeFalsy();
150
+ expect(libraryManagerA.hasRole("librarian-all")).toBeFalsy();
151
+ expect(libraryManagerA.hasRole("manager", "a")).toBeTruthy();
152
+ expect(libraryManagerA.hasRole("librarian", "a")).toBeTruthy();
153
+ expect(libraryManagerA.hasRole("manager", "b")).toBeFalsy();
154
+ expect(libraryManagerA.hasRole("librarian", "b")).toBeFalsy();
155
+
156
+ expect(librarianA.hasRole("system")).toBeFalsy();
157
+ expect(librarianA.hasRole("manager-all")).toBeFalsy();
158
+ expect(librarianA.hasRole("librarian-all")).toBeFalsy();
159
+ expect(librarianA.hasRole("manager", "a")).toBeFalsy();
160
+ expect(librarianA.hasRole("librarian", "a")).toBeTruthy();
161
+ expect(librarianA.hasRole("manager", "b")).toBeFalsy();
162
+ expect(librarianA.hasRole("librarian", "b")).toBeFalsy();
163
+
164
+ expect(libraryManagerB.hasRole("system")).toBeFalsy();
165
+ expect(libraryManagerB.hasRole("manager-all")).toBeFalsy();
166
+ expect(libraryManagerB.hasRole("librarian-all")).toBeFalsy();
167
+ expect(libraryManagerB.hasRole("manager", "a")).toBeFalsy();
168
+ expect(libraryManagerB.hasRole("librarian", "a")).toBeFalsy();
169
+ expect(libraryManagerB.hasRole("manager", "b")).toBeTruthy();
170
+ expect(libraryManagerB.hasRole("librarian", "b")).toBeTruthy();
171
+
172
+ expect(librarianB.hasRole("system")).toBeFalsy();
173
+ expect(librarianB.hasRole("manager-all")).toBeFalsy();
174
+ expect(librarianB.hasRole("librarian-all")).toBeFalsy();
175
+ expect(librarianB.hasRole("manager", "a")).toBeFalsy();
176
+ expect(librarianB.hasRole("librarian", "a")).toBeFalsy();
177
+ expect(librarianB.hasRole("manager", "b")).toBeFalsy();
178
+ expect(librarianB.hasRole("librarian", "b")).toBeTruthy();
179
+
180
+ expect(libraryManagerASitewideLibrarian.hasRole("system")).toBeFalsy();
181
+ expect(libraryManagerASitewideLibrarian.hasRole("manager-all")).toBeFalsy();
182
+ expect(
183
+ libraryManagerASitewideLibrarian.hasRole("librarian-all")
184
+ ).toBeTruthy();
185
+ expect(
186
+ libraryManagerASitewideLibrarian.hasRole("manager", "a")
187
+ ).toBeTruthy();
188
+ expect(
189
+ libraryManagerASitewideLibrarian.hasRole("librarian", "a")
190
+ ).toBeTruthy();
191
+ expect(
192
+ libraryManagerASitewideLibrarian.hasRole("manager", "b")
193
+ ).toBeFalsy();
194
+ expect(
195
+ libraryManagerASitewideLibrarian.hasRole("librarian", "b")
196
+ ).toBeTruthy();
197
+
198
+ expect(libraryManagerALibrarianB.hasRole("system")).toBeFalsy();
199
+ expect(libraryManagerALibrarianB.hasRole("manager-all")).toBeFalsy();
200
+ expect(libraryManagerALibrarianB.hasRole("librarian-all")).toBeFalsy();
201
+ expect(libraryManagerALibrarianB.hasRole("manager", "a")).toBeTruthy();
202
+ expect(libraryManagerALibrarianB.hasRole("librarian", "a")).toBeTruthy();
203
+ expect(libraryManagerALibrarianB.hasRole("manager", "b")).toBeFalsy();
204
+ expect(libraryManagerALibrarianB.hasRole("librarian", "b")).toBeTruthy();
205
+ });
206
+ });
@@ -0,0 +1,81 @@
1
+ import reducer, {
2
+ BookCoverPreviewState,
3
+ } from "../../../src/reducers/bookCoverPreview";
4
+ import ActionCreator from "../../../src/actions";
5
+
6
+ describe("book cover preview reducer", () => {
7
+ const preview = "image data";
8
+
9
+ const initState: BookCoverPreviewState = {
10
+ data: null,
11
+ isFetching: false,
12
+ fetchError: null,
13
+ };
14
+
15
+ const errorState: BookCoverPreviewState = {
16
+ data: null,
17
+ isFetching: false,
18
+ fetchError: { status: 401, response: "test error", url: "test url" },
19
+ };
20
+
21
+ const loadedState = Object.assign({}, initState, {
22
+ data: preview,
23
+ });
24
+
25
+ it("returns initial state for unrecognized action", () => {
26
+ expect(reducer(undefined, {})).toStrictEqual(initState);
27
+ });
28
+
29
+ it("handles PREVIEW_BOOK_COVER_REQUEST", () => {
30
+ const action = {
31
+ type: `${ActionCreator.PREVIEW_BOOK_COVER}_${ActionCreator.REQUEST}`,
32
+ url: "test url",
33
+ };
34
+
35
+ // start with empty state
36
+ let newState = Object.assign({}, initState, {
37
+ isFetching: true,
38
+ });
39
+ expect(reducer(initState, action)).toStrictEqual(newState);
40
+
41
+ // start with error state
42
+ newState = Object.assign({}, errorState, {
43
+ isFetching: true,
44
+ fetchError: null,
45
+ });
46
+ expect(reducer(errorState, action)).toStrictEqual(newState);
47
+ });
48
+
49
+ it("handles PREVIEW_BOOK_COVER_FAILURE", () => {
50
+ const action = {
51
+ type: `${ActionCreator.PREVIEW_BOOK_COVER}_${ActionCreator.FAILURE}`,
52
+ error: "test error",
53
+ };
54
+ const oldState = Object.assign({}, initState, { isFetching: true });
55
+ const newState = Object.assign({}, oldState, {
56
+ fetchError: "test error",
57
+ isFetching: false,
58
+ });
59
+ expect(reducer(oldState, action)).toStrictEqual(newState);
60
+ });
61
+
62
+ it("handles PREVIEW_BOOK_COVER_LOAD", () => {
63
+ const action = {
64
+ type: `${ActionCreator.PREVIEW_BOOK_COVER}_${ActionCreator.LOAD}`,
65
+ data: preview,
66
+ };
67
+ const newState = Object.assign({}, initState, {
68
+ data: preview,
69
+ isFetching: false,
70
+ });
71
+ expect(reducer(initState, action)).toStrictEqual(newState);
72
+ });
73
+
74
+ it("handles PREVIEW_BOOK_COVER_CLEAR", () => {
75
+ const action = {
76
+ type: `${ActionCreator.PREVIEW_BOOK_COVER}_${ActionCreator.CLEAR}`,
77
+ };
78
+ expect(reducer(loadedState, action)).toStrictEqual(initState);
79
+ expect(reducer(errorState, action)).toStrictEqual(initState);
80
+ });
81
+ });
@@ -0,0 +1,161 @@
1
+ import reducer, {
2
+ ClassificationsState,
3
+ } from "../../../src/reducers/classifications";
4
+ import ActionCreator from "../../../src/actions";
5
+
6
+ describe("classifications reducer", () => {
7
+ const genreData = {
8
+ Fiction: {},
9
+ Nonfiction: {},
10
+ };
11
+
12
+ const classificationsData = [
13
+ {
14
+ type: "type",
15
+ name: "name",
16
+ source: "source",
17
+ weight: "weight",
18
+ },
19
+ ];
20
+
21
+ const initState: ClassificationsState = {
22
+ genreTree: null,
23
+ classifications: null,
24
+ isFetchingGenreTree: false,
25
+ isEditingClassifications: false,
26
+ isFetchingClassifications: false,
27
+ fetchError: null,
28
+ };
29
+
30
+ const errorState: ClassificationsState = {
31
+ genreTree: null,
32
+ classifications: null,
33
+ isFetchingGenreTree: false,
34
+ isEditingClassifications: false,
35
+ isFetchingClassifications: false,
36
+ fetchError: { status: 401, response: "test error", url: "test url" },
37
+ };
38
+
39
+ it("returns initial state for unrecognized action", () => {
40
+ expect(reducer(undefined, {})).toStrictEqual(initState);
41
+ });
42
+
43
+ it("handles GENRE_TREE_REQUEST", () => {
44
+ const action = { type: ActionCreator.GENRE_TREE_REQUEST, url: "test url" };
45
+
46
+ // start with empty state
47
+ let newState = Object.assign({}, initState, {
48
+ isFetchingGenreTree: true,
49
+ });
50
+ expect(reducer(initState, action)).toStrictEqual(newState);
51
+
52
+ // start with error state
53
+ newState = Object.assign({}, errorState, {
54
+ isFetchingGenreTree: true,
55
+ fetchError: null,
56
+ });
57
+ expect(reducer(errorState, action)).toStrictEqual(newState);
58
+ });
59
+
60
+ it("handles GENRE_TREE_FAILURE", () => {
61
+ const action = {
62
+ type: ActionCreator.GENRE_TREE_FAILURE,
63
+ error: "test error",
64
+ };
65
+ const oldState = Object.assign({}, initState, { isFetching: true });
66
+ const newState = Object.assign({}, oldState, {
67
+ fetchError: "test error",
68
+ isFetchingGenreTree: false,
69
+ });
70
+ expect(reducer(oldState, action)).toStrictEqual(newState);
71
+ });
72
+
73
+ it("handles GENRE_TREE_LOAD", () => {
74
+ const action = { type: ActionCreator.GENRE_TREE_LOAD, data: genreData };
75
+ const newState = Object.assign({}, initState, {
76
+ genreTree: genreData,
77
+ isFetchingGenreTree: false,
78
+ });
79
+ expect(reducer(initState, action)).toStrictEqual(newState);
80
+ });
81
+
82
+ it("handles EDIT_CLASSIFICATIONS_REQUEST", () => {
83
+ const action = {
84
+ type: ActionCreator.EDIT_CLASSIFICATIONS_REQUEST,
85
+ url: "test url",
86
+ };
87
+
88
+ // start with empty state
89
+ let newState = Object.assign({}, initState, {
90
+ isEditingClassifications: true,
91
+ });
92
+ expect(reducer(initState, action)).toStrictEqual(newState);
93
+
94
+ // start with error state
95
+ newState = Object.assign({}, errorState, {
96
+ isEditingClassifications: true,
97
+ fetchError: null,
98
+ });
99
+ expect(reducer(errorState, action)).toStrictEqual(newState);
100
+ });
101
+
102
+ it("handles EDIT_CLASSIFICATIONS_FAILURE", () => {
103
+ const action = {
104
+ type: ActionCreator.EDIT_CLASSIFICATIONS_FAILURE,
105
+ error: "test error",
106
+ };
107
+ const oldState = Object.assign({}, initState, {
108
+ isEditingClassifications: true,
109
+ });
110
+ const newState = Object.assign({}, oldState, {
111
+ fetchError: "test error",
112
+ isEditingClassifications: false,
113
+ });
114
+ expect(reducer(oldState, action)).toStrictEqual(newState);
115
+ });
116
+
117
+ it("handles CLASSIFICATIONS_REQUEST", () => {
118
+ const action = {
119
+ type: ActionCreator.CLASSIFICATIONS_REQUEST,
120
+ url: "test url",
121
+ };
122
+
123
+ // start with empty state
124
+ let newState = Object.assign({}, initState, {
125
+ isFetchingClassifications: true,
126
+ });
127
+ expect(reducer(initState, action)).toStrictEqual(newState);
128
+
129
+ // start with error state
130
+ newState = Object.assign({}, errorState, {
131
+ isFetchingClassifications: true,
132
+ fetchError: null,
133
+ });
134
+ expect(reducer(errorState, action)).toStrictEqual(newState);
135
+ });
136
+
137
+ it("handles CLASSIFICATIONS_FAILURE", () => {
138
+ const action = {
139
+ type: ActionCreator.CLASSIFICATIONS_FAILURE,
140
+ error: "test error",
141
+ };
142
+ const oldState = Object.assign({}, initState, { isFetching: true });
143
+ const newState = Object.assign({}, oldState, {
144
+ fetchError: "test error",
145
+ isFetchingClassifications: false,
146
+ });
147
+ expect(reducer(oldState, action)).toStrictEqual(newState);
148
+ });
149
+
150
+ it("handles CLASSIFICATIONS_LOAD", () => {
151
+ const action = {
152
+ type: ActionCreator.CLASSIFICATIONS_LOAD,
153
+ data: { classifications: classificationsData },
154
+ };
155
+ const newState = Object.assign({}, initState, {
156
+ classifications: classificationsData,
157
+ isFetchingClassifications: false,
158
+ });
159
+ expect(reducer(initState, action)).toStrictEqual(newState);
160
+ });
161
+ });
@@ -0,0 +1,96 @@
1
+ import collections from "../../../src/reducers/collections";
2
+ import ActionCreator from "../../../src/actions";
3
+
4
+ describe("collections reducer", () => {
5
+ const initState = {
6
+ data: null,
7
+ isFetching: false,
8
+ isEditing: false,
9
+ fetchError: null,
10
+ formError: null,
11
+ responseBody: null,
12
+ isLoaded: false,
13
+ successMessage: null,
14
+ };
15
+
16
+ it("returns initial state for unrecognized action", () => {
17
+ expect(collections(undefined, {})).toStrictEqual(initState);
18
+ });
19
+
20
+ it("handles COLLECTIONS_REQUEST", () => {
21
+ const action = {
22
+ type: `${ActionCreator.COLLECTIONS}_REQUEST`,
23
+ url: "test url",
24
+ };
25
+
26
+ // start with empty state
27
+ const newState = Object.assign({}, initState, {
28
+ isFetching: true,
29
+ });
30
+ expect(collections(initState, action)).toStrictEqual(newState);
31
+ });
32
+
33
+ it("handles EDIT_COLLECTION_REQUEST", () => {
34
+ const action = { type: `${ActionCreator.EDIT_COLLECTION}_REQUEST` };
35
+ const newState = Object.assign({}, initState, {
36
+ fetchError: null,
37
+ isFetching: false,
38
+ isEditing: true,
39
+ });
40
+ expect(collections(initState, action)).toStrictEqual(newState);
41
+ });
42
+
43
+ it("handles GET_SELF_TESTS_LOAD", () => {
44
+ const emptySelfTestData = {
45
+ duration: null,
46
+ start: "",
47
+ end: "",
48
+ results: [],
49
+ };
50
+ const selfTestData = {
51
+ duration: 0.12,
52
+ start: "start",
53
+ end: "end",
54
+ results: [],
55
+ };
56
+ const action = {
57
+ type: `${ActionCreator.GET_SELF_TESTS}_LOAD`,
58
+ data: {
59
+ self_test_results: {
60
+ id: 1,
61
+ self_test_results: selfTestData,
62
+ protocol: "",
63
+ },
64
+ },
65
+ };
66
+ const oldState = {
67
+ url: "test url",
68
+ data: {
69
+ collections: [
70
+ { id: 1, self_test_results: emptySelfTestData, protocol: "" },
71
+ { id: 2, protocol: "" },
72
+ ],
73
+ protocols: [],
74
+ },
75
+ isFetching: true,
76
+ fetchError: null,
77
+ editError: null,
78
+ isLoaded: true,
79
+ isEditing: false,
80
+ };
81
+
82
+ const newState = Object.assign({}, oldState, {
83
+ data: {
84
+ collections: [
85
+ { id: 1, self_test_results: selfTestData, protocol: "" },
86
+ { id: 2, protocol: "" },
87
+ ],
88
+ protocols: [],
89
+ },
90
+ isFetching: false,
91
+ isLoaded: true,
92
+ });
93
+
94
+ expect(collections(oldState, action)).toStrictEqual(newState);
95
+ });
96
+ });