@thepalaceproject/circulation-admin 1.43.0 → 1.44.0-post.4
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.
- package/CLAUDE.md +28 -7
- package/README.md +11 -5
- package/dist/circulation-admin.js +1 -1
- package/eslint.config.mjs +9 -1
- package/jest.config.js +22 -8
- package/package.json +6 -20
- package/tests/jest/actions.test.ts +962 -0
- package/tests/jest/components/AccountPage.test.tsx +41 -0
- package/tests/jest/components/AdvancedSearchBooleanFilter.test.tsx +231 -0
- package/tests/jest/components/AdvancedSearchBuilder.test.tsx +93 -20
- package/tests/jest/components/AdvancedSearchFilter.test.tsx +142 -0
- package/tests/jest/components/AdvancedSearchFilterInput.test.tsx +212 -0
- package/tests/jest/components/AdvancedSearchFilterViewer.test.tsx +52 -0
- package/tests/jest/components/AdvancedSearchValueFilter.test.tsx +123 -0
- package/tests/jest/components/Announcement.test.tsx +76 -0
- package/tests/jest/components/AnnouncementForm.test.tsx +229 -0
- package/tests/jest/components/AnnouncementsSection.test.tsx +146 -0
- package/tests/jest/components/Autocomplete.test.tsx +67 -0
- package/tests/jest/components/BookCoverEditor.test.tsx +393 -0
- package/tests/jest/components/BookDetails.test.tsx +133 -0
- package/tests/jest/components/BookDetailsContainer.test.tsx +116 -0
- package/tests/jest/components/BookDetailsEditor.test.tsx +275 -0
- package/tests/jest/components/BookDetailsTabContainer.test.tsx +237 -0
- package/tests/jest/components/BookEditForm.test.tsx +352 -0
- package/tests/jest/components/BookEditor.test.tsx +20 -21
- package/tests/jest/components/CatalogPage.test.tsx +158 -0
- package/tests/jest/components/CatalogServices.test.tsx +100 -0
- package/tests/jest/components/ChangePasswordForm.test.tsx +163 -0
- package/tests/jest/components/CirculationEventsDownloadForm.test.tsx +41 -0
- package/tests/jest/components/Classifications.test.tsx +166 -0
- package/tests/jest/components/ClassificationsForm.test.tsx +458 -0
- package/tests/jest/components/ClassificationsTable.test.tsx +57 -0
- package/tests/jest/components/Collections.test.tsx +335 -7
- package/tests/jest/components/ColorPicker.test.tsx +58 -0
- package/tests/jest/components/ComplaintForm.test.tsx +171 -0
- package/tests/jest/components/Complaints.test.tsx +259 -0
- package/tests/jest/components/ConfigPage.test.tsx +58 -0
- package/tests/jest/components/ConfigTabContainer.test.tsx +196 -0
- package/tests/jest/components/ContextProvider.test.tsx +138 -0
- package/tests/jest/components/Contributors.test.tsx +157 -0
- package/tests/jest/components/CustomListEditor.test.tsx +367 -0
- package/tests/jest/components/CustomListEntriesEditor.test.tsx +1240 -0
- package/tests/jest/components/CustomListPage.test.tsx +57 -0
- package/tests/jest/components/CustomListSearch.test.tsx +275 -0
- package/tests/jest/components/CustomLists.test.tsx +621 -4
- package/tests/jest/components/CustomListsForBook.test.tsx +353 -0
- package/tests/jest/components/CustomListsSidebar.test.tsx +251 -0
- package/tests/jest/components/DashboardPage.test.tsx +76 -0
- package/tests/jest/components/DebugAuthentication.test.tsx +1 -5
- package/tests/jest/components/DiagnosticsServiceTabs.test.tsx +141 -0
- package/tests/jest/components/DiagnosticsServiceType.test.tsx +75 -0
- package/tests/jest/components/DiagnosticsTabContainer.test.tsx +147 -0
- package/tests/jest/components/DiscoveryServices.test.tsx +154 -7
- package/tests/jest/components/EditableConfigList.test.tsx +606 -9
- package/tests/jest/components/EditableInput.test.tsx +250 -1
- package/tests/jest/components/EditorField.test.tsx +95 -0
- package/tests/jest/components/EntryPointsContainer.test.tsx +97 -0
- package/tests/jest/components/EntryPointsTabs.test.tsx +88 -0
- package/tests/jest/components/ErrorMessage.test.tsx +97 -0
- package/tests/jest/components/Footer.test.tsx +141 -0
- package/tests/jest/components/GenreForm.test.tsx +152 -0
- package/tests/jest/components/Header.test.tsx +421 -0
- package/tests/jest/components/IndividualAdminEditForm.test.tsx +506 -1
- package/tests/jest/components/IndividualAdmins.test.tsx +124 -8
- package/tests/jest/components/InputList.test.tsx +493 -0
- package/tests/jest/components/InventoryReportRequestModal.test.tsx +16 -42
- package/tests/jest/components/JsonField.test.tsx +20 -0
- package/tests/jest/components/Lane.test.tsx +132 -10
- package/tests/jest/components/LaneCustomListsEditor.test.tsx +450 -0
- package/tests/jest/components/LaneEditor.test.tsx +377 -13
- package/tests/jest/components/LanePage.test.tsx +68 -0
- package/tests/jest/components/Lanes.test.tsx +446 -0
- package/tests/jest/components/LanesSidebar.test.tsx +621 -0
- package/tests/jest/components/LanguageField.test.tsx +40 -0
- package/tests/jest/components/Libraries.test.tsx +48 -0
- package/tests/jest/components/LibraryEditForm.test.tsx +383 -0
- package/tests/jest/components/LibraryRegistration.test.tsx +354 -0
- package/tests/jest/components/LibraryRegistrationForm.test.tsx +203 -0
- package/tests/jest/components/LoadButton.test.tsx +49 -0
- package/tests/jest/components/ManagePatrons.test.tsx +73 -0
- package/tests/jest/components/ManagePatronsForm.test.tsx +180 -0
- package/tests/jest/components/ManagePatronsTabContainer.test.tsx +143 -0
- package/tests/jest/components/MetadataServices.test.tsx +95 -0
- package/tests/jest/components/NeighborhoodAnalyticsForm.test.tsx +167 -0
- package/tests/jest/components/PairedMenus.test.tsx +220 -0
- package/tests/jest/components/PatronAuthServices.test.tsx +114 -0
- package/tests/jest/components/PatronBlockingRulesEditor.test.tsx +3 -1
- package/tests/jest/components/PatronInfo.test.tsx +54 -0
- package/tests/jest/components/ProtocolFormField.test.tsx +479 -7
- package/tests/jest/components/ResetAdobeId.test.tsx +302 -0
- package/tests/jest/components/SaveButton.test.tsx +47 -0
- package/tests/jest/components/SelfTestResult.test.tsx +164 -0
- package/tests/jest/components/SelfTests.test.tsx +601 -0
- package/tests/jest/components/SelfTestsCategory.test.tsx +200 -0
- package/tests/jest/components/SelfTestsTabContainer.test.tsx +216 -0
- package/tests/jest/components/ServiceEditForm.test.tsx +1092 -0
- package/tests/jest/components/ServiceWithRegistrationsEditForm.test.tsx +110 -0
- package/tests/jest/components/SetupPage.test.tsx +41 -0
- package/tests/jest/components/SingleStatListItem.test.tsx +62 -0
- package/tests/jest/components/SitewideAnnouncements.test.tsx +134 -0
- package/tests/jest/components/Stats.test.tsx +4 -15
- package/tests/jest/components/TabContainer.test.tsx +68 -0
- package/tests/jest/components/TextWithEditMode.test.tsx +218 -0
- package/tests/jest/components/Timestamp.test.tsx +74 -0
- package/tests/jest/components/ToolTip.test.tsx +46 -0
- package/tests/jest/components/TroubleshootingCategoryPage.test.tsx +69 -0
- package/tests/jest/components/TroubleshootingPage.test.tsx +94 -0
- package/tests/jest/components/TroubleshootingTabContainer.test.tsx +68 -0
- package/tests/jest/components/UpdatingLoader.test.tsx +36 -0
- package/tests/jest/components/WelcomePage.test.tsx +43 -0
- package/tests/jest/components/WithEditButton.test.tsx +55 -0
- package/tests/jest/components/WithRemoveButton.test.tsx +95 -0
- package/tests/jest/editorAdapter.test.ts +245 -0
- package/tests/jest/features/book.test.ts +75 -80
- package/tests/jest/fixtures/classificationsData.ts +45 -0
- package/tests/jest/fixtures/genreData.ts +811 -0
- package/tests/jest/index.test.tsx +50 -0
- package/tests/jest/models/Admin.test.ts +206 -0
- package/tests/jest/reducers/bookCoverPreview.test.ts +81 -0
- package/tests/jest/reducers/classifications.test.ts +161 -0
- package/tests/jest/reducers/collections.test.ts +96 -0
- package/tests/jest/reducers/complaints.test.ts +166 -0
- package/tests/jest/reducers/createFetchEditReducer.test.ts +220 -0
- package/tests/jest/reducers/createRegisterLibraryReducer.test.ts +51 -0
- package/tests/jest/reducers/customListDetails.test.ts +120 -0
- package/tests/jest/reducers/customListEditor.test.ts +2823 -0
- package/tests/jest/reducers/managePatrons.test.ts +71 -0
- package/tests/jest/testUtils/formDataShim.test.ts +135 -0
- package/tests/jest/testUtils/formDataShim.ts +112 -0
- package/tests/jest/utils/sharedFunctions.test.ts +121 -0
- package/tsconfig.json +3 -4
- package/testReporter.js +0 -29
- package/tests/jest/README.md +0 -6
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import complaints from "../../../src/reducers/complaints";
|
|
2
|
+
import ActionCreator from "../../../src/actions";
|
|
3
|
+
|
|
4
|
+
describe("complaints reducer", () => {
|
|
5
|
+
const initState = {
|
|
6
|
+
url: null,
|
|
7
|
+
data: null,
|
|
8
|
+
isFetching: false,
|
|
9
|
+
fetchError: null,
|
|
10
|
+
postError: null,
|
|
11
|
+
resolveError: null,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const errorState = {
|
|
15
|
+
url: "test url",
|
|
16
|
+
data: null,
|
|
17
|
+
isFetching: false,
|
|
18
|
+
fetchError: { status: 401, response: "test error", url: "test url" },
|
|
19
|
+
postError: null,
|
|
20
|
+
resolveError: null,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
it("returns initial state for unrecognized action", () => {
|
|
24
|
+
expect(complaints(undefined, {})).toStrictEqual(initState);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("handles COMPLAINTS_REQUEST", () => {
|
|
28
|
+
const action = { type: ActionCreator.COMPLAINTS_REQUEST, url: "test url" };
|
|
29
|
+
|
|
30
|
+
// start with empty state
|
|
31
|
+
let newState = Object.assign({}, initState, {
|
|
32
|
+
url: "test url",
|
|
33
|
+
isFetching: true,
|
|
34
|
+
});
|
|
35
|
+
expect(complaints(initState, action)).toStrictEqual(newState);
|
|
36
|
+
|
|
37
|
+
// start with error state
|
|
38
|
+
newState = Object.assign({}, errorState, {
|
|
39
|
+
isFetching: true,
|
|
40
|
+
fetchError: null,
|
|
41
|
+
});
|
|
42
|
+
expect(complaints(errorState, action)).toStrictEqual(newState);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("handles COMPLAINTS_FAILURE", () => {
|
|
46
|
+
const action = {
|
|
47
|
+
type: ActionCreator.COMPLAINTS_FAILURE,
|
|
48
|
+
error: "test error",
|
|
49
|
+
};
|
|
50
|
+
const oldState = {
|
|
51
|
+
url: "test url",
|
|
52
|
+
data: null,
|
|
53
|
+
isFetching: true,
|
|
54
|
+
fetchError: null,
|
|
55
|
+
postError: null,
|
|
56
|
+
resolveError: null,
|
|
57
|
+
};
|
|
58
|
+
const newState = Object.assign({}, oldState, {
|
|
59
|
+
fetchError: "test error",
|
|
60
|
+
isFetching: false,
|
|
61
|
+
});
|
|
62
|
+
expect(complaints(oldState, action)).toStrictEqual(newState);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("handles COMPLAINTS_LOAD", () => {
|
|
66
|
+
const action = {
|
|
67
|
+
type: ActionCreator.COMPLAINTS_LOAD,
|
|
68
|
+
data: { complaints: "test data" },
|
|
69
|
+
};
|
|
70
|
+
const oldState = {
|
|
71
|
+
url: "test url",
|
|
72
|
+
data: null,
|
|
73
|
+
isFetching: true,
|
|
74
|
+
fetchError: null,
|
|
75
|
+
postError: null,
|
|
76
|
+
resolveError: null,
|
|
77
|
+
};
|
|
78
|
+
const newState = Object.assign({}, oldState, {
|
|
79
|
+
data: "test data",
|
|
80
|
+
isFetching: false,
|
|
81
|
+
});
|
|
82
|
+
expect(complaints(oldState, action)).toStrictEqual(newState);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("handles POST_COMPLAINT_REQUEST", () => {
|
|
86
|
+
const action = {
|
|
87
|
+
type: ActionCreator.POST_COMPLAINT_REQUEST,
|
|
88
|
+
url: "test url",
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// start with empty state
|
|
92
|
+
let newState = Object.assign({}, initState, {
|
|
93
|
+
url: "test url",
|
|
94
|
+
isFetching: true,
|
|
95
|
+
});
|
|
96
|
+
expect(complaints(initState, action)).toStrictEqual(newState);
|
|
97
|
+
|
|
98
|
+
// start with error state
|
|
99
|
+
newState = Object.assign({}, errorState, {
|
|
100
|
+
isFetching: true,
|
|
101
|
+
fetchError: null,
|
|
102
|
+
});
|
|
103
|
+
expect(complaints(errorState, action)).toStrictEqual(newState);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("handles POST_COMPLAINT_FAILURE", () => {
|
|
107
|
+
const action = {
|
|
108
|
+
type: ActionCreator.POST_COMPLAINT_FAILURE,
|
|
109
|
+
error: "test error",
|
|
110
|
+
};
|
|
111
|
+
const oldState = {
|
|
112
|
+
url: "test url",
|
|
113
|
+
data: null,
|
|
114
|
+
isFetching: true,
|
|
115
|
+
fetchError: null,
|
|
116
|
+
postError: null,
|
|
117
|
+
resolveError: null,
|
|
118
|
+
};
|
|
119
|
+
const newState = Object.assign({}, oldState, {
|
|
120
|
+
postError: "test error",
|
|
121
|
+
isFetching: false,
|
|
122
|
+
});
|
|
123
|
+
expect(complaints(oldState, action)).toStrictEqual(newState);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("handles RESOLVE_COMPLAINTS_REQUEST", () => {
|
|
127
|
+
const action = {
|
|
128
|
+
type: ActionCreator.RESOLVE_COMPLAINTS_REQUEST,
|
|
129
|
+
url: "test url",
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// start with empty state
|
|
133
|
+
let newState = Object.assign({}, initState, {
|
|
134
|
+
url: "test url",
|
|
135
|
+
isFetching: true,
|
|
136
|
+
});
|
|
137
|
+
expect(complaints(initState, action)).toStrictEqual(newState);
|
|
138
|
+
|
|
139
|
+
// start with error state
|
|
140
|
+
newState = Object.assign({}, errorState, {
|
|
141
|
+
isFetching: true,
|
|
142
|
+
fetchError: null,
|
|
143
|
+
});
|
|
144
|
+
expect(complaints(errorState, action)).toStrictEqual(newState);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("handles RESOLVE_COMPLAINTS_FAILURE", () => {
|
|
148
|
+
const action = {
|
|
149
|
+
type: ActionCreator.RESOLVE_COMPLAINTS_FAILURE,
|
|
150
|
+
error: "test error",
|
|
151
|
+
};
|
|
152
|
+
const oldState = {
|
|
153
|
+
url: "test url",
|
|
154
|
+
data: null,
|
|
155
|
+
isFetching: true,
|
|
156
|
+
fetchError: null,
|
|
157
|
+
postError: null,
|
|
158
|
+
resolveError: null,
|
|
159
|
+
};
|
|
160
|
+
const newState = Object.assign({}, oldState, {
|
|
161
|
+
resolveError: "test error",
|
|
162
|
+
isFetching: false,
|
|
163
|
+
});
|
|
164
|
+
expect(complaints(oldState, action)).toStrictEqual(newState);
|
|
165
|
+
});
|
|
166
|
+
});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import createFetchEditReducer, {
|
|
2
|
+
FetchEditState,
|
|
3
|
+
} from "../../../src/reducers/createFetchEditReducer";
|
|
4
|
+
|
|
5
|
+
describe("fetch-edit reducer", () => {
|
|
6
|
+
interface TestData {
|
|
7
|
+
s: string;
|
|
8
|
+
n: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const testData: TestData = {
|
|
12
|
+
s: "test",
|
|
13
|
+
n: 5,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const initState: FetchEditState<TestData> = {
|
|
17
|
+
data: null,
|
|
18
|
+
isFetching: false,
|
|
19
|
+
isEditing: false,
|
|
20
|
+
fetchError: null,
|
|
21
|
+
formError: null,
|
|
22
|
+
isLoaded: false,
|
|
23
|
+
responseBody: null,
|
|
24
|
+
successMessage: null,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const errorState: FetchEditState<TestData> = {
|
|
28
|
+
data: null,
|
|
29
|
+
isFetching: false,
|
|
30
|
+
isEditing: false,
|
|
31
|
+
fetchError: { status: 400, response: "test error", url: "test url" },
|
|
32
|
+
formError: null,
|
|
33
|
+
isLoaded: true,
|
|
34
|
+
responseBody: null,
|
|
35
|
+
successMessage: null,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const manipulateData = (state) => {
|
|
39
|
+
const data = 10;
|
|
40
|
+
return Object.assign({}, state, {
|
|
41
|
+
data: data,
|
|
42
|
+
isLoaded: true,
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const extraActions = {
|
|
47
|
+
EXTRA_ACTION_REQUEST: (state) => state,
|
|
48
|
+
EXTRA_ACTION_LOAD: manipulateData,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const reducer = createFetchEditReducer<TestData>("TEST_FETCH", "TEST_EDIT");
|
|
52
|
+
const fetchOnlyReducer = createFetchEditReducer<TestData>("TEST_FETCH");
|
|
53
|
+
const extraActionReducer = createFetchEditReducer<TestData>(
|
|
54
|
+
"TEST_FETCH",
|
|
55
|
+
"TEST_EDIT",
|
|
56
|
+
extraActions
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
it("returns initial state for unrecognized action", () => {
|
|
60
|
+
expect(reducer(undefined, {})).toStrictEqual(initState);
|
|
61
|
+
expect(fetchOnlyReducer(undefined, {})).toStrictEqual(initState);
|
|
62
|
+
expect(extraActionReducer(undefined, {})).toStrictEqual(initState);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("handles clear", () => {
|
|
66
|
+
const action = { type: "TEST_FETCH_CLEAR" };
|
|
67
|
+
|
|
68
|
+
const state = Object.assign({}, initState, {
|
|
69
|
+
data: testData,
|
|
70
|
+
isLoaded: true,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
expect(reducer(state, action)).toStrictEqual(initState);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("handles fetch request", () => {
|
|
77
|
+
const action = { type: "TEST_FETCH_REQUEST", url: "test_url" };
|
|
78
|
+
|
|
79
|
+
// start with empty state
|
|
80
|
+
let newState = Object.assign({}, initState, {
|
|
81
|
+
isFetching: true,
|
|
82
|
+
});
|
|
83
|
+
expect(reducer(initState, action)).toStrictEqual(newState);
|
|
84
|
+
expect(fetchOnlyReducer(initState, action)).toStrictEqual(newState);
|
|
85
|
+
|
|
86
|
+
// start with error state
|
|
87
|
+
newState = Object.assign({}, errorState, {
|
|
88
|
+
isFetching: true,
|
|
89
|
+
isLoaded: false,
|
|
90
|
+
fetchError: null,
|
|
91
|
+
});
|
|
92
|
+
expect(reducer(errorState, action)).toStrictEqual(newState);
|
|
93
|
+
expect(fetchOnlyReducer(errorState, action)).toStrictEqual(newState);
|
|
94
|
+
|
|
95
|
+
// start with loaded state
|
|
96
|
+
const loadedState = Object.assign({}, initState, {
|
|
97
|
+
data: testData,
|
|
98
|
+
isLoaded: true,
|
|
99
|
+
});
|
|
100
|
+
newState = Object.assign({}, loadedState, {
|
|
101
|
+
data: null,
|
|
102
|
+
isLoaded: false,
|
|
103
|
+
isFetching: true,
|
|
104
|
+
});
|
|
105
|
+
expect(reducer(loadedState, action)).toStrictEqual(newState);
|
|
106
|
+
expect(fetchOnlyReducer(loadedState, action)).toStrictEqual(newState);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("handles fetch failure", () => {
|
|
110
|
+
const action = { type: "TEST_FETCH_FAILURE", error: "test error" };
|
|
111
|
+
const oldState = Object.assign({}, initState, { isFetching: true });
|
|
112
|
+
const newState = Object.assign({}, oldState, {
|
|
113
|
+
fetchError: "test error",
|
|
114
|
+
isFetching: false,
|
|
115
|
+
isLoaded: true,
|
|
116
|
+
});
|
|
117
|
+
expect(reducer(oldState, action)).toStrictEqual(newState);
|
|
118
|
+
expect(fetchOnlyReducer(oldState, action)).toStrictEqual(newState);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("handles success", () => {
|
|
122
|
+
const action = { type: "TEST_FETCH_SUCCESS", data: testData };
|
|
123
|
+
const oldState = Object.assign({}, initState, {
|
|
124
|
+
isFetching: true,
|
|
125
|
+
});
|
|
126
|
+
const newState = Object.assign({}, initState, {
|
|
127
|
+
isFetching: false,
|
|
128
|
+
});
|
|
129
|
+
expect(reducer(oldState, action)).toStrictEqual(newState);
|
|
130
|
+
expect(fetchOnlyReducer(oldState, action)).toStrictEqual(newState);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("handles load", () => {
|
|
134
|
+
const action = { type: "TEST_FETCH_LOAD", data: testData };
|
|
135
|
+
const newState = Object.assign({}, initState, {
|
|
136
|
+
data: testData,
|
|
137
|
+
isFetching: false,
|
|
138
|
+
isLoaded: true,
|
|
139
|
+
});
|
|
140
|
+
expect(reducer(initState, action)).toStrictEqual(newState);
|
|
141
|
+
expect(fetchOnlyReducer(initState, action)).toStrictEqual(newState);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("handles edit request", () => {
|
|
145
|
+
const action = { type: "TEST_EDIT_REQUEST", url: "test url" };
|
|
146
|
+
|
|
147
|
+
// start with empty state
|
|
148
|
+
let newState = Object.assign({}, initState, {
|
|
149
|
+
isEditing: true,
|
|
150
|
+
});
|
|
151
|
+
expect(reducer(initState, action)).toStrictEqual(newState);
|
|
152
|
+
// fetch only reducer does nothing
|
|
153
|
+
expect(fetchOnlyReducer(initState, action)).toStrictEqual(initState);
|
|
154
|
+
|
|
155
|
+
// start with error state
|
|
156
|
+
newState = Object.assign({}, errorState, {
|
|
157
|
+
isEditing: true,
|
|
158
|
+
fetchError: null,
|
|
159
|
+
});
|
|
160
|
+
expect(reducer(errorState, action)).toStrictEqual(newState);
|
|
161
|
+
// fetch only reducer does nothing
|
|
162
|
+
expect(fetchOnlyReducer(errorState, action)).toStrictEqual(errorState);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("handles edit failure", () => {
|
|
166
|
+
const action = { type: "TEST_EDIT_FAILURE", error: "test error" };
|
|
167
|
+
const oldState = Object.assign({}, initState, {
|
|
168
|
+
isEditing: true,
|
|
169
|
+
});
|
|
170
|
+
const newState = Object.assign({}, oldState, {
|
|
171
|
+
formError: "test error",
|
|
172
|
+
isEditing: false,
|
|
173
|
+
});
|
|
174
|
+
expect(reducer(oldState, action)).toStrictEqual(newState);
|
|
175
|
+
// fetch only reducer does nothing
|
|
176
|
+
expect(fetchOnlyReducer(oldState, action)).toStrictEqual(oldState);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("handles edit success", () => {
|
|
180
|
+
const action = { type: "TEST_EDIT_SUCCESS" };
|
|
181
|
+
const oldState = Object.assign({}, initState, {
|
|
182
|
+
isEditing: true,
|
|
183
|
+
});
|
|
184
|
+
const newState = Object.assign({}, oldState, {
|
|
185
|
+
isEditing: false,
|
|
186
|
+
});
|
|
187
|
+
expect(reducer(oldState, action)).toStrictEqual(newState);
|
|
188
|
+
// fetch only reducer does nothing
|
|
189
|
+
expect(fetchOnlyReducer(oldState, action)).toStrictEqual(oldState);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("handles edit load", () => {
|
|
193
|
+
const action = { type: "TEST_EDIT_LOAD", data: "5" };
|
|
194
|
+
const newState = Object.assign({}, initState, {
|
|
195
|
+
responseBody: "5",
|
|
196
|
+
successMessage: "5",
|
|
197
|
+
});
|
|
198
|
+
expect(reducer(initState, action)).toStrictEqual(newState);
|
|
199
|
+
// fetch only reducer does nothing
|
|
200
|
+
expect(fetchOnlyReducer(initState, action)).toStrictEqual(initState);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("handles extra action request", () => {
|
|
204
|
+
const action = { type: "EXTRA_ACTION_REQUEST", url: "test url" };
|
|
205
|
+
|
|
206
|
+
// start with empty state
|
|
207
|
+
const newState = Object.assign({}, initState);
|
|
208
|
+
expect(extraActionReducer(initState, action)).toStrictEqual(newState);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("handles extra action data load", () => {
|
|
212
|
+
const action = { type: "EXTRA_ACTION_LOAD", url: "test url" };
|
|
213
|
+
const newState = Object.assign({}, initState, {
|
|
214
|
+
data: 10,
|
|
215
|
+
isLoaded: true,
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
expect(extraActionReducer(initState, action)).toStrictEqual(newState);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import ActionCreator from "../../../src/actions";
|
|
2
|
+
import createRegisterLibraryReducer, {
|
|
3
|
+
RegisterLibraryState,
|
|
4
|
+
} from "../../../src/reducers/createRegisterLibraryReducer";
|
|
5
|
+
|
|
6
|
+
describe("register-library reducer", () => {
|
|
7
|
+
const initState: RegisterLibraryState = {
|
|
8
|
+
isFetching: false,
|
|
9
|
+
fetchError: null,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const errorState: RegisterLibraryState = {
|
|
13
|
+
isFetching: false,
|
|
14
|
+
fetchError: { status: 401, response: "test error", url: "test url" },
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const reducer = createRegisterLibraryReducer("TEST_REGISTER");
|
|
18
|
+
|
|
19
|
+
it("returns initial state for unrecognized action", () => {
|
|
20
|
+
expect(reducer(undefined, {})).toStrictEqual(initState);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("handles register library request", () => {
|
|
24
|
+
const action = { type: `TEST_REGISTER_${ActionCreator.REQUEST}` };
|
|
25
|
+
const newState = Object.assign({}, initState, { isFetching: true });
|
|
26
|
+
expect(reducer(initState, action)).toStrictEqual(newState);
|
|
27
|
+
expect(reducer(errorState, action)).toStrictEqual(newState);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("handles register library failure", () => {
|
|
31
|
+
const action = {
|
|
32
|
+
type: `TEST_REGISTER_${ActionCreator.FAILURE}`,
|
|
33
|
+
error: "test error",
|
|
34
|
+
};
|
|
35
|
+
const oldState = Object.assign({}, initState, { isFetching: true });
|
|
36
|
+
const newState = Object.assign({}, oldState, {
|
|
37
|
+
fetchError: "test error",
|
|
38
|
+
isFetching: false,
|
|
39
|
+
});
|
|
40
|
+
expect(reducer(oldState, action)).toStrictEqual(newState);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("handles register library success", () => {
|
|
44
|
+
const action = { type: `TEST_REGISTER_${ActionCreator.SUCCESS}` };
|
|
45
|
+
const oldState = Object.assign({}, initState, {
|
|
46
|
+
isFetching: true,
|
|
47
|
+
fetchError: "test error",
|
|
48
|
+
});
|
|
49
|
+
expect(reducer(oldState, action)).toStrictEqual(initState);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import customListDetails from "../../../src/reducers/customListDetails";
|
|
2
|
+
import ActionCreator from "../../../src/actions";
|
|
3
|
+
|
|
4
|
+
describe("customListDetails reducer", () => {
|
|
5
|
+
const initState = {
|
|
6
|
+
data: null,
|
|
7
|
+
isFetching: false,
|
|
8
|
+
isEditing: false,
|
|
9
|
+
fetchError: null,
|
|
10
|
+
formError: null,
|
|
11
|
+
responseBody: null,
|
|
12
|
+
successMessage: null,
|
|
13
|
+
isLoaded: false,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
it("returns initial state for unrecognized action", () => {
|
|
17
|
+
expect(customListDetails(undefined, {})).toStrictEqual(initState);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("handles CUSTOM_LIST_DETAILS_REQUEST", () => {
|
|
21
|
+
const action = {
|
|
22
|
+
type: `${ActionCreator.CUSTOM_LIST_DETAILS}_REQUEST`,
|
|
23
|
+
url: "test url",
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// start with empty state
|
|
27
|
+
const newState = Object.assign({}, initState, {
|
|
28
|
+
isFetching: true,
|
|
29
|
+
});
|
|
30
|
+
expect(customListDetails(initState, action)).toStrictEqual(newState);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("handles CUSTOM_LIST_DETAILS_MORE_REQUEST", () => {
|
|
34
|
+
const action = {
|
|
35
|
+
type: `${ActionCreator.CUSTOM_LIST_DETAILS_MORE}_REQUEST`,
|
|
36
|
+
url: "test url",
|
|
37
|
+
};
|
|
38
|
+
const oldState = {
|
|
39
|
+
url: "test url",
|
|
40
|
+
data: null,
|
|
41
|
+
isFetching: false,
|
|
42
|
+
isFetchingMoreEntries: false,
|
|
43
|
+
fetchError: null,
|
|
44
|
+
editError: null,
|
|
45
|
+
isLoaded: true,
|
|
46
|
+
isEditing: false,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const newState = Object.assign({}, oldState, {
|
|
50
|
+
isFetchingMoreEntries: true,
|
|
51
|
+
isLoaded: false,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
expect(customListDetails(oldState, action)).toStrictEqual(newState);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("handles CUSTOM_LIST_DETAILS_MORE_LOAD", () => {
|
|
58
|
+
const action = {
|
|
59
|
+
type: `${ActionCreator.CUSTOM_LIST_DETAILS_MORE}_LOAD`,
|
|
60
|
+
data: {
|
|
61
|
+
id: "1",
|
|
62
|
+
url: "url",
|
|
63
|
+
books: [
|
|
64
|
+
{ id: "4", title: "4" },
|
|
65
|
+
{ id: "5", title: "5" },
|
|
66
|
+
{ id: "6", title: "6" },
|
|
67
|
+
],
|
|
68
|
+
nextPageUrl: "nextpage?after=100",
|
|
69
|
+
navigationLinks: [],
|
|
70
|
+
lanes: [],
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
const oldState = {
|
|
74
|
+
url: "test url",
|
|
75
|
+
data: {
|
|
76
|
+
id: "1",
|
|
77
|
+
url: "url",
|
|
78
|
+
title: "custom list",
|
|
79
|
+
books: [
|
|
80
|
+
{ id: "1", title: "1" },
|
|
81
|
+
{ id: "2", title: "2" },
|
|
82
|
+
{ id: "3", title: "3" },
|
|
83
|
+
],
|
|
84
|
+
nextPageUrl: "nextpage?after=50",
|
|
85
|
+
navigationLinks: [],
|
|
86
|
+
lanes: [],
|
|
87
|
+
},
|
|
88
|
+
isFetching: false,
|
|
89
|
+
isFetchingMoreEntries: false,
|
|
90
|
+
fetchError: null,
|
|
91
|
+
editError: null,
|
|
92
|
+
isLoaded: true,
|
|
93
|
+
isEditing: false,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const newState = Object.assign({}, oldState, {
|
|
97
|
+
data: {
|
|
98
|
+
id: "1",
|
|
99
|
+
url: "url",
|
|
100
|
+
title: "custom list",
|
|
101
|
+
books: [
|
|
102
|
+
{ id: "1", title: "1" },
|
|
103
|
+
{ id: "2", title: "2" },
|
|
104
|
+
{ id: "3", title: "3" },
|
|
105
|
+
{ id: "4", title: "4" },
|
|
106
|
+
{ id: "5", title: "5" },
|
|
107
|
+
{ id: "6", title: "6" },
|
|
108
|
+
],
|
|
109
|
+
nextPageUrl: "nextpage?after=100",
|
|
110
|
+
navigationLinks: [],
|
|
111
|
+
lanes: [],
|
|
112
|
+
},
|
|
113
|
+
isFetching: false,
|
|
114
|
+
isFetchingMoreEntries: false,
|
|
115
|
+
isLoaded: true,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(customListDetails(oldState, action)).toStrictEqual(newState);
|
|
119
|
+
});
|
|
120
|
+
});
|