@thepalaceproject/circulation-admin 1.43.0-post.3 → 1.43.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/package.json +1 -1
- package/tests/jest/editorAdapter.test.ts +245 -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/utils/sharedFunctions.test.ts +121 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import ManagePatrons from "../../../src/reducers/managePatrons";
|
|
2
|
+
import ActionCreator from "../../../src/actions";
|
|
3
|
+
|
|
4
|
+
describe("ManagePatrons 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(ManagePatrons(undefined, {})).toStrictEqual(initState);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("handles CLEAR_PATRON_DATA_LOAD", () => {
|
|
21
|
+
const action = {
|
|
22
|
+
type: `${ActionCreator.CLEAR_PATRON_DATA}_LOAD`,
|
|
23
|
+
data: null,
|
|
24
|
+
};
|
|
25
|
+
const oldPatronState = {
|
|
26
|
+
url: "test url",
|
|
27
|
+
data: {
|
|
28
|
+
authorization_expires: "",
|
|
29
|
+
authorization_identifier: "1234",
|
|
30
|
+
authorization_identifiers: [],
|
|
31
|
+
block_reason: "",
|
|
32
|
+
external_type: "",
|
|
33
|
+
fines: "",
|
|
34
|
+
permanent_id: "1234",
|
|
35
|
+
},
|
|
36
|
+
isFetching: true,
|
|
37
|
+
fetchError: null,
|
|
38
|
+
editError: null,
|
|
39
|
+
isLoaded: true,
|
|
40
|
+
isEditing: false,
|
|
41
|
+
};
|
|
42
|
+
const oldErrorState = {
|
|
43
|
+
url: "test url",
|
|
44
|
+
data: null,
|
|
45
|
+
isFetching: true,
|
|
46
|
+
fetchError: {
|
|
47
|
+
status: 400,
|
|
48
|
+
response: "No patron found",
|
|
49
|
+
url: "",
|
|
50
|
+
},
|
|
51
|
+
editError: null,
|
|
52
|
+
isLoaded: true,
|
|
53
|
+
isEditing: false,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const newPatronState = Object.assign({}, oldPatronState, {
|
|
57
|
+
data: null,
|
|
58
|
+
isFetching: false,
|
|
59
|
+
isLoaded: true,
|
|
60
|
+
});
|
|
61
|
+
const newErrorState = Object.assign({}, oldErrorState, {
|
|
62
|
+
data: null,
|
|
63
|
+
isFetching: false,
|
|
64
|
+
isLoaded: true,
|
|
65
|
+
fetchError: null,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(ManagePatrons(oldPatronState, action)).toStrictEqual(newPatronState);
|
|
69
|
+
expect(ManagePatrons(oldErrorState, action)).toStrictEqual(newErrorState);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findDefault,
|
|
3
|
+
formatString,
|
|
4
|
+
isEqual,
|
|
5
|
+
} from "../../../src/utils/sharedFunctions";
|
|
6
|
+
|
|
7
|
+
describe("findDefault", () => {
|
|
8
|
+
const settingWithoutDefaults = {
|
|
9
|
+
key: "test_setting_no_default",
|
|
10
|
+
options: [
|
|
11
|
+
{ key: "true", label: "Yes" },
|
|
12
|
+
{ key: "false", label: "No" },
|
|
13
|
+
],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const settingWithOneDefault = {
|
|
17
|
+
default: "true",
|
|
18
|
+
key: "test_setting_1_default",
|
|
19
|
+
options: [
|
|
20
|
+
{ key: "true", label: "Yes" },
|
|
21
|
+
{ key: "false", label: "No" },
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const settingWithMultipleDefaults = {
|
|
26
|
+
default: ["first default", "second default"],
|
|
27
|
+
key: "test_setting_mult_defaults",
|
|
28
|
+
options: [
|
|
29
|
+
{ key: "first default", label: "Yes" },
|
|
30
|
+
{ key: "no", label: "No" },
|
|
31
|
+
{ key: "second default", label: "This one too" },
|
|
32
|
+
{ key: "also no", label: "Not this one" },
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
it("doesn't return anything if the setting has no default value", () => {
|
|
37
|
+
const result = findDefault(settingWithoutDefaults);
|
|
38
|
+
expect(result).toBeUndefined();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("identifies the default setting from a list of options", () => {
|
|
42
|
+
const result = findDefault(settingWithOneDefault);
|
|
43
|
+
expect(result.length).toBe(1);
|
|
44
|
+
expect(result[0].key).toBe("true");
|
|
45
|
+
expect(result[0].label).toBe("Yes");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("identifies multiple default settings from a list of options", () => {
|
|
49
|
+
const result = findDefault(settingWithMultipleDefaults);
|
|
50
|
+
expect(result.length).toBe(2);
|
|
51
|
+
expect(result[0].key).toBe("first default");
|
|
52
|
+
expect(result[0].label).toBe("Yes");
|
|
53
|
+
expect(result[1].key).toBe("second default");
|
|
54
|
+
expect(result[1].label).toBe("This one too");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("formatString", () => {
|
|
59
|
+
const stringToFormat = "this-is-a-sentence.";
|
|
60
|
+
it("capitalizes the first letter of a string by default", () => {
|
|
61
|
+
const result = formatString(stringToFormat);
|
|
62
|
+
expect(result).toBe("This-is-a-sentence.");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("can be prevented from capitalizing", () => {
|
|
66
|
+
const result = formatString(stringToFormat, null, false);
|
|
67
|
+
expect(result).toBe("this-is-a-sentence.");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("replaces characters", () => {
|
|
71
|
+
const result = formatString(stringToFormat, ["-", " "], false);
|
|
72
|
+
expect(result).toBe("this is a sentence.");
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("replaces characters and capitalizes", () => {
|
|
76
|
+
const result = formatString(stringToFormat, ["-", "!"]);
|
|
77
|
+
expect(result).toBe("This!is!a!sentence.");
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("replaces multiple characters", () => {
|
|
81
|
+
const result = formatString("need-to-replace!multiple-characters", [
|
|
82
|
+
"-",
|
|
83
|
+
"!",
|
|
84
|
+
" ",
|
|
85
|
+
]);
|
|
86
|
+
expect(result).toBe("Need to replace multiple characters");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("defaults to replacing characters with a space", () => {
|
|
90
|
+
const result = formatString(stringToFormat, ["-"]);
|
|
91
|
+
expect(result).toBe("This is a sentence.");
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("isEqual", () => {
|
|
96
|
+
const arr1 = ["a", "b", "c"];
|
|
97
|
+
|
|
98
|
+
it("returns false if the arrays are not the same length", () => {
|
|
99
|
+
const arr2 = ["a", "b", "c", "d"];
|
|
100
|
+
expect(isEqual(arr1, arr2)).toBe(false);
|
|
101
|
+
});
|
|
102
|
+
it("returns false if the lengths are the same but not all of the elements match", () => {
|
|
103
|
+
const arr2 = ["a", "b", "d"];
|
|
104
|
+
expect(isEqual(arr1, arr2)).toBe(false);
|
|
105
|
+
});
|
|
106
|
+
it("returns false if there are duplicates", () => {
|
|
107
|
+
const arr2 = ["a", "a", "b"];
|
|
108
|
+
expect(isEqual(arr1, arr2)).toBe(false);
|
|
109
|
+
});
|
|
110
|
+
it("returns true if the arrays are the same", () => {
|
|
111
|
+
const arr2 = ["a", "b", "c"];
|
|
112
|
+
expect(isEqual(arr1, arr2)).toBe(true);
|
|
113
|
+
});
|
|
114
|
+
it("returns true even if the arrays do not list the elements in the same order", () => {
|
|
115
|
+
const arr2 = ["b", "c", "a"];
|
|
116
|
+
expect(isEqual(arr1, arr2)).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
it("returns true if the arrays have the same duplicates", () => {
|
|
119
|
+
expect(isEqual(["a", "a", "b"], ["b", "a", "a"])).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
});
|