redux-paginator-immutable 17.0.16 → 17.0.21
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/lib/Info.d.ts +9 -0
- package/lib/Info.js +19 -41
- package/lib/Info.js.map +1 -0
- package/lib/LoadDataItem.d.ts +23 -0
- package/lib/LoadDataItem.js +59 -110
- package/lib/LoadDataItem.js.map +1 -0
- package/lib/LoadPaginator.d.ts +41 -0
- package/lib/LoadPaginator.js +109 -216
- package/lib/LoadPaginator.js.map +1 -0
- package/lib/LoadingButton.d.ts +11 -0
- package/lib/LoadingButton.js +22 -75
- package/lib/LoadingButton.js.map +1 -0
- package/lib/actionTypes.d.ts +9 -0
- package/lib/actionTypes.js +13 -16
- package/lib/actionTypes.js.map +1 -0
- package/lib/actions.d.ts +42 -0
- package/lib/actions.js +82 -136
- package/lib/actions.js.map +1 -0
- package/lib/agent.d.ts +8 -0
- package/lib/agent.js +37 -86
- package/lib/agent.js.map +1 -0
- package/lib/createDataReducer.d.ts +14 -0
- package/lib/createDataReducer.js +60 -79
- package/lib/createDataReducer.js.map +1 -0
- package/lib/createItemReducer.d.ts +9 -0
- package/lib/createItemReducer.js +14 -32
- package/lib/createItemReducer.js.map +1 -0
- package/lib/createPaginator.d.ts +14 -0
- package/lib/createPaginator.js +83 -140
- package/lib/createPaginator.js.map +1 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +30 -58
- package/lib/index.js.map +1 -0
- package/lib/paginatorMiddleware.d.ts +5 -0
- package/lib/paginatorMiddleware.js +68 -102
- package/lib/paginatorMiddleware.js.map +1 -0
- package/lib/reducerItemData.d.ts +18 -0
- package/lib/reducerItemData.js +56 -63
- package/lib/reducerItemData.js.map +1 -0
- package/lib/reducerOperations.d.ts +3 -0
- package/lib/reducerOperations.js +69 -114
- package/lib/reducerOperations.js.map +1 -0
- package/lib/reducers.d.ts +4 -0
- package/lib/reducers.js +75 -87
- package/lib/reducers.js.map +1 -0
- package/lib/selectors.d.ts +58 -0
- package/lib/selectors.js +79 -129
- package/lib/selectors.js.map +1 -0
- package/lib/types/actions.d.ts +85 -0
- package/lib/types/actions.js +3 -1
- package/lib/types/actions.js.map +1 -0
- package/lib/types/index.d.ts +21 -0
- package/lib/types/index.js +16 -29
- package/lib/types/index.js.map +1 -0
- package/lib/types/state.d.ts +6 -0
- package/lib/types/state.js +3 -1
- package/lib/types/state.js.map +1 -0
- package/lib/util.d.ts +9 -0
- package/lib/util.js +49 -73
- package/lib/util.js.map +1 -0
- package/lib/words.d.ts +9 -0
- package/lib/words.js +12 -15
- package/lib/words.js.map +1 -0
- package/package.json +35 -21
- package/src/Info.tsx +29 -0
- package/src/LoadDataItem.tsx +84 -0
- package/src/{LoadPaginator.jsx → LoadPaginator.tsx} +77 -94
- package/src/LoadingButton.tsx +40 -0
- package/src/__tests__/createPaginator.spec.js +6 -6
- package/src/__tests__/reducers.spec.js +28 -28
- package/src/__tests__/selectors.spec.js +80 -81
- package/src/{actionTypes.js → actionTypes.ts} +0 -4
- package/src/actions.ts +157 -0
- package/src/agent.ts +62 -0
- package/src/createDataReducer.ts +91 -0
- package/src/{createItemReducer.js → createItemReducer.ts} +7 -13
- package/src/createPaginator.ts +107 -0
- package/src/{index.js → index.ts} +0 -13
- package/src/paginatorMiddleware.ts +93 -0
- package/src/reducerItemData.ts +74 -0
- package/src/reducerOperations.ts +101 -0
- package/src/{reducers.js → reducers.ts} +9 -18
- package/src/selectors.ts +113 -0
- package/src/types/{actions.js → actions.ts} +27 -39
- package/src/types/{index.js → index.ts} +6 -13
- package/src/types/{state.js → state.ts} +3 -6
- package/src/util.ts +51 -0
- package/src/{words.js → words.ts} +0 -2
- package/lib/__tests__/actions.spec.js +0 -117
- package/lib/__tests__/agent.spec.js +0 -32
- package/lib/__tests__/createPaginator.spec.js +0 -39
- package/lib/__tests__/reducers.spec.js +0 -126
- package/lib/__tests__/selectors.spec.js +0 -162
- package/lib/__tests__/setup.js +0 -3
- package/src/Info.jsx +0 -34
- package/src/LoadDataItem.jsx +0 -116
- package/src/LoadingButton.jsx +0 -55
- package/src/actions.js +0 -153
- package/src/agent.js +0 -55
- package/src/createDataReducer.js +0 -94
- package/src/createPaginator.js +0 -131
- package/src/paginatorMiddleware.js +0 -94
- package/src/reducerItemData.jsx +0 -64
- package/src/reducerOperations.jsx +0 -112
- package/src/selectors.js +0 -143
- package/src/util.js +0 -71
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import type { EndPointCb } from "./index";
|
|
4
2
|
|
|
5
3
|
export type RequestPageAction = {
|
|
6
|
-
type
|
|
7
|
-
meta
|
|
4
|
+
type: "@@redux-paginator-immutable/REQUEST_PAGE";
|
|
5
|
+
meta: {
|
|
8
6
|
endpoint: string;
|
|
9
7
|
endpointCb: EndPointCb;
|
|
10
8
|
manageEntity: any;
|
|
@@ -18,10 +16,9 @@ export type RequestPageAction = {
|
|
|
18
16
|
token: string;
|
|
19
17
|
};
|
|
20
18
|
};
|
|
21
|
-
|
|
22
19
|
export type ReceivePageAction = {
|
|
23
|
-
type
|
|
24
|
-
meta
|
|
20
|
+
type: "@@redux-paginator-immutable/RECEIVE_PAGE";
|
|
21
|
+
meta: {
|
|
25
22
|
endpoint: string;
|
|
26
23
|
endpointCb: EndPointCb;
|
|
27
24
|
manageEntity: any;
|
|
@@ -33,14 +30,13 @@ export type ReceivePageAction = {
|
|
|
33
30
|
token: string;
|
|
34
31
|
items: Array<any>;
|
|
35
32
|
total: number;
|
|
36
|
-
error:
|
|
33
|
+
error: boolean;
|
|
37
34
|
raw?: string;
|
|
38
35
|
};
|
|
39
36
|
};
|
|
40
|
-
|
|
41
37
|
export type ChangeViewAction = {
|
|
42
|
-
type
|
|
43
|
-
meta
|
|
38
|
+
type: "@@redux-paginator-immutable/CHANGE_VIEW";
|
|
39
|
+
meta: {
|
|
44
40
|
endpoint: string;
|
|
45
41
|
};
|
|
46
42
|
payload: {
|
|
@@ -48,44 +44,38 @@ export type ChangeViewAction = {
|
|
|
48
44
|
token: string;
|
|
49
45
|
};
|
|
50
46
|
};
|
|
51
|
-
|
|
52
47
|
export type ResetViewAction = {
|
|
53
|
-
type
|
|
54
|
-
meta
|
|
48
|
+
type: "@@redux-paginator-immutable/RESET_VIEW";
|
|
49
|
+
meta: {
|
|
55
50
|
endpoint: string;
|
|
56
51
|
};
|
|
57
52
|
payload: {
|
|
58
53
|
token: string;
|
|
59
54
|
};
|
|
60
55
|
};
|
|
61
|
-
|
|
62
56
|
export type ClearDataAction = {
|
|
63
|
-
type
|
|
64
|
-
meta
|
|
57
|
+
type: "@@redux-paginator-immutable/CLEAR_DATA";
|
|
58
|
+
meta: {
|
|
65
59
|
endpoint: string;
|
|
66
60
|
};
|
|
67
61
|
};
|
|
68
|
-
|
|
69
62
|
export type FetchCurrentCompanyInfoPending = {
|
|
70
|
-
type
|
|
63
|
+
type: "FETCH_CURRENT_COMPANY_INFO_PENDING";
|
|
71
64
|
};
|
|
72
|
-
|
|
73
65
|
export type FetchItemDataPending = {
|
|
74
|
-
type
|
|
66
|
+
type: "@@redux-paginator-immutable/FETCH_ITEM_DATA_PENDING";
|
|
75
67
|
meta: {
|
|
76
68
|
id: string;
|
|
77
|
-
}
|
|
69
|
+
};
|
|
78
70
|
};
|
|
79
|
-
|
|
80
71
|
export type FetchItemDataRejected = {
|
|
81
|
-
type
|
|
72
|
+
type: "@@redux-paginator-immutable/FETCH_ITEM_DATA_REJECTED";
|
|
82
73
|
meta: {
|
|
83
74
|
id: string;
|
|
84
|
-
}
|
|
75
|
+
};
|
|
85
76
|
};
|
|
86
|
-
|
|
87
77
|
export type FetchItemDataFulFilled = {
|
|
88
|
-
type
|
|
78
|
+
type: "@@redux-paginator-immutable/FETCH_ITEM_DATA_FULFILLED";
|
|
89
79
|
payload: {
|
|
90
80
|
Data: any;
|
|
91
81
|
};
|
|
@@ -93,15 +83,13 @@ export type FetchItemDataFulFilled = {
|
|
|
93
83
|
id: string;
|
|
94
84
|
};
|
|
95
85
|
};
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
|
99
|
-
|
|
|
100
|
-
|
|
|
101
|
-
|
|
|
102
|
-
|
|
103
|
-
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|FetchItemDataRejected
|
|
107
|
-
|FetchItemDataFulFilled;
|
|
86
|
+
export type Action =
|
|
87
|
+
RequestPageAction |
|
|
88
|
+
ReceivePageAction |
|
|
89
|
+
ResetViewAction |
|
|
90
|
+
ChangeViewAction |
|
|
91
|
+
ClearDataAction |
|
|
92
|
+
FetchCurrentCompanyInfoPending |
|
|
93
|
+
FetchItemDataPending |
|
|
94
|
+
FetchItemDataRejected |
|
|
95
|
+
FetchItemDataFulFilled;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
/* eslint-disable no-use-before-define */
|
|
3
|
-
|
|
4
2
|
export * from "./actions";
|
|
5
3
|
export * from "./state";
|
|
6
|
-
|
|
7
4
|
import type { State } from "./state";
|
|
8
5
|
import type { Action } from "./actions";
|
|
9
6
|
|
|
@@ -11,28 +8,24 @@ export type GetState = () => State;
|
|
|
11
8
|
export type PromiseAction = Promise<Action>;
|
|
12
9
|
export type ThunkAction = (dispatch: Dispatch, getState: GetState) => any;
|
|
13
10
|
export type Dispatch = (action: Action | ThunkAction | PromiseAction | Array<Action>) => any;
|
|
11
|
+
export type EndPointCb = ((token?: string) => string) | null;
|
|
14
12
|
|
|
15
|
-
export type EndPointCb = ((token? : string) => string) | null;
|
|
16
13
|
|
|
17
14
|
export type PaginatorSettings = {
|
|
18
15
|
key: string;
|
|
19
16
|
manageEntity: any;
|
|
20
17
|
resultsKey: string;
|
|
21
|
-
dataItemURL: string;
|
|
22
|
-
normalizeDataItem: any;
|
|
23
|
-
|
|
24
18
|
// by default "{rowsPerLoad} from x25/utility/others"
|
|
25
19
|
rowsPerLoad?: number;
|
|
26
|
-
|
|
27
20
|
// by default "(items) => items"
|
|
28
21
|
manipulateItems?: (items: any) => any;
|
|
29
|
-
|
|
30
22
|
// by default "Total"
|
|
31
23
|
totalKey?: string;
|
|
32
|
-
|
|
33
|
-
// by default "page"
|
|
24
|
+
// by default "page"
|
|
34
25
|
pageArgName?: string;
|
|
35
|
-
|
|
36
26
|
// default "ID"
|
|
37
27
|
idKey?: string;
|
|
38
|
-
|
|
28
|
+
|
|
29
|
+
dataItemURL?: string;
|
|
30
|
+
normalizeDataItem?: any;
|
|
31
|
+
};
|
package/src/util.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/* eslint-disable no-duplicate-imports */
|
|
2
|
+
type NormalizrEntity = (data: any) => any;
|
|
3
|
+
|
|
4
|
+
import type { Map as ImmutableMap } from "immutable";
|
|
5
|
+
import * as Immutable from "immutable";
|
|
6
|
+
import { createSelector } from "reselect";
|
|
7
|
+
|
|
8
|
+
type ManageDataEntity = ImmutableMap<string, any>;
|
|
9
|
+
|
|
10
|
+
// simple item
|
|
11
|
+
const
|
|
12
|
+
manageEntity = (normalizrEntity: NormalizrEntity) => (
|
|
13
|
+
(item: any, state: any, keyID: string): ManageDataEntity => {
|
|
14
|
+
// prevent rewrite
|
|
15
|
+
const old = state.get(String(item[keyID]));
|
|
16
|
+
|
|
17
|
+
if (typeof old === "undefined") {
|
|
18
|
+
return Immutable.Map(normalizrEntity(item));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return old;
|
|
22
|
+
}
|
|
23
|
+
),
|
|
24
|
+
manipulateItems = (sortKey = "ID") => createSelector(
|
|
25
|
+
(data : any) => data,
|
|
26
|
+
(data : any) => data.sortBy((current : any) => -current.get(sortKey)),
|
|
27
|
+
),
|
|
28
|
+
|
|
29
|
+
// data item
|
|
30
|
+
manageDataEntity = (normalizrEntity: NormalizrEntity) => (
|
|
31
|
+
(item: any, state: any, keyID: string): ManageDataEntity => {
|
|
32
|
+
// prevent rewrite
|
|
33
|
+
const old = state.get(String(item[keyID]));
|
|
34
|
+
|
|
35
|
+
if (typeof old === "undefined") {
|
|
36
|
+
return Immutable.Map({
|
|
37
|
+
Data: normalizrEntity(item),
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return old;
|
|
42
|
+
}
|
|
43
|
+
),
|
|
44
|
+
manipulateDataItems = (sortKey = "ID") => (
|
|
45
|
+
createSelector(
|
|
46
|
+
(data : any) => data,
|
|
47
|
+
(data : any) => data.sortBy((current : any) => -current.getIn(["Data", sortKey])),
|
|
48
|
+
)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export { manageDataEntity, manipulateDataItems, manipulateItems, manageEntity };
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _expect = require("expect");
|
|
4
|
-
|
|
5
|
-
var _expect2 = _interopRequireDefault(_expect);
|
|
6
|
-
|
|
7
|
-
var _fluxStandardAction = require("flux-standard-action");
|
|
8
|
-
|
|
9
|
-
var _actions = require("../actions");
|
|
10
|
-
|
|
11
|
-
var _actions2 = _interopRequireDefault(_actions);
|
|
12
|
-
|
|
13
|
-
var _actionTypes = require("../actionTypes");
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
|
|
17
|
-
var receivePage = _actions2.default.receivePage,
|
|
18
|
-
requestPage = _actions2.default.requestPage,
|
|
19
|
-
resetView = _actions2.default.resetView,
|
|
20
|
-
changeView = _actions2.default.changeView; /* eslint-disable no-undefined, max-lines-per-function, no-magic-numbers */
|
|
21
|
-
|
|
22
|
-
describe("actions", function () {
|
|
23
|
-
|
|
24
|
-
it("should create receive page action", function () {
|
|
25
|
-
var action = receivePage({
|
|
26
|
-
endpoint: "some/api/endpoint/",
|
|
27
|
-
pageArgName: "p",
|
|
28
|
-
idKey: "id",
|
|
29
|
-
page: 2,
|
|
30
|
-
token: "foo=bar",
|
|
31
|
-
items: ["foo", "bar", "baz"],
|
|
32
|
-
total: 42
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
(0, _expect2.default)(action).toEqual({
|
|
36
|
-
type: _actionTypes.RECEIVE_PAGE,
|
|
37
|
-
meta: {
|
|
38
|
-
endpoint: "some/api/endpoint/",
|
|
39
|
-
pageArgName: "p",
|
|
40
|
-
idKey: "id"
|
|
41
|
-
},
|
|
42
|
-
payload: {
|
|
43
|
-
token: "foo=bar",
|
|
44
|
-
page: 2,
|
|
45
|
-
items: ["foo", "bar", "baz"],
|
|
46
|
-
total: 42
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
(0, _expect2.default)((0, _fluxStandardAction.isFSA)(action)).toEqual(true);
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("should create request page action", function () {
|
|
54
|
-
var action = requestPage({
|
|
55
|
-
endpoint: "some/api/endpoint/",
|
|
56
|
-
resultsKey: "results",
|
|
57
|
-
totalKey: "total",
|
|
58
|
-
pageArgName: "p",
|
|
59
|
-
idKey: "id",
|
|
60
|
-
page: 2,
|
|
61
|
-
token: "foo=bar"
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
(0, _expect2.default)(action).toEqual({
|
|
65
|
-
type: _actionTypes.REQUEST_PAGE,
|
|
66
|
-
meta: {
|
|
67
|
-
endpoint: "some/api/endpoint/",
|
|
68
|
-
resultsKey: "results",
|
|
69
|
-
totalKey: "total",
|
|
70
|
-
pageArgName: "p",
|
|
71
|
-
idKey: "id"
|
|
72
|
-
},
|
|
73
|
-
payload: {
|
|
74
|
-
token: "foo=bar",
|
|
75
|
-
page: 2
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
(0, _expect2.default)((0, _fluxStandardAction.isFSA)(action)).toEqual(true);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("should create reset view action", function () {
|
|
83
|
-
var action = resetView("some/api/endpoint/", "name");
|
|
84
|
-
|
|
85
|
-
(0, _expect2.default)(action).toEqual({
|
|
86
|
-
type: _actionTypes.RESET_VIEW,
|
|
87
|
-
meta: {
|
|
88
|
-
endpoint: "some/api/endpoint/"
|
|
89
|
-
},
|
|
90
|
-
payload: {
|
|
91
|
-
token: "name"
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
(0, _expect2.default)((0, _fluxStandardAction.isFSA)(action)).toEqual(true);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
it("should create change view action", function () {
|
|
99
|
-
var action = changeView("some/api/endpoint/", {
|
|
100
|
-
token: "name",
|
|
101
|
-
view: 2
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
(0, _expect2.default)(action).toEqual({
|
|
105
|
-
type: _actionTypes.CHANGE_VIEW,
|
|
106
|
-
meta: {
|
|
107
|
-
endpoint: "some/api/endpoint/"
|
|
108
|
-
},
|
|
109
|
-
payload: {
|
|
110
|
-
view: 2,
|
|
111
|
-
token: "name"
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
(0, _expect2.default)((0, _fluxStandardAction.isFSA)(action)).toEqual(true);
|
|
116
|
-
});
|
|
117
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _expect = require("expect");
|
|
4
|
-
|
|
5
|
-
var _expect2 = _interopRequireDefault(_expect);
|
|
6
|
-
|
|
7
|
-
var _agent = require("../agent");
|
|
8
|
-
|
|
9
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
|
|
11
|
-
describe("buildSuffix", function () {
|
|
12
|
-
|
|
13
|
-
it("should correctly build the url suffix when simple params are provided", function () {
|
|
14
|
-
(0, _expect2.default)((0, _agent.buildSuffix)("p", 1, "foo=bar")).toEqual("?foo=bar&p=1");
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("should correctly build the url suffix when less simple params are provided", function () {
|
|
18
|
-
(0, _expect2.default)((0, _agent.buildSuffix)("p", 1, "foo=bar&baz=foo")).toEqual("?baz=foo&foo=bar&p=1");
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("should correctly build the url suffix when params contains no extractable query params", function () {
|
|
22
|
-
(0, _expect2.default)((0, _agent.buildSuffix)("p", 1, "foo/bar")).toEqual("foo/bar?p=1");
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('should correctly build the url suffix when "params" is not provided', function () {
|
|
26
|
-
(0, _expect2.default)((0, _agent.buildSuffix)("p", 1, "")).toEqual("?p=1");
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("should correctly build the url suffix when complex params are provided", function () {
|
|
30
|
-
(0, _expect2.default)((0, _agent.buildSuffix)("p", 1, "foo/bar?bar=biz&baz=foo")).toEqual("foo/bar?baz=foo&bar=biz&p=1");
|
|
31
|
-
});
|
|
32
|
-
});
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _expect = require("expect");
|
|
4
|
-
|
|
5
|
-
var _expect2 = _interopRequireDefault(_expect);
|
|
6
|
-
|
|
7
|
-
var _actions = require("../actions");
|
|
8
|
-
|
|
9
|
-
var _actions2 = _interopRequireDefault(_actions);
|
|
10
|
-
|
|
11
|
-
var _createPaginator = require("../createPaginator");
|
|
12
|
-
|
|
13
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
|
-
|
|
15
|
-
var requestPage = _actions2.default.requestPage; /* eslint-disable max-len, no-undefined, no-magic-numbers */
|
|
16
|
-
|
|
17
|
-
describe("createPaginator", function () {
|
|
18
|
-
|
|
19
|
-
it("should create correct request action creator", function () {
|
|
20
|
-
var paginator = (0, _createPaginator.createPaginator)("some/api/endpoint", {
|
|
21
|
-
pageArgName: "p",
|
|
22
|
-
idKey: "id_field",
|
|
23
|
-
resultsKey: "results",
|
|
24
|
-
totalKey: "count"
|
|
25
|
-
});
|
|
26
|
-
var action = paginator.requestPage(42, "foo=bar");
|
|
27
|
-
|
|
28
|
-
(0, _expect2.default)(action).toEqual(requestPage({
|
|
29
|
-
endpoint: "some/api/endpoint",
|
|
30
|
-
endpointCb: null,
|
|
31
|
-
resultsKey: "results",
|
|
32
|
-
totalKey: "count",
|
|
33
|
-
pageArgName: "p",
|
|
34
|
-
idKey: "id_field",
|
|
35
|
-
page: 42,
|
|
36
|
-
token: "foo=bar"
|
|
37
|
-
}));
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _immutable = require("immutable");
|
|
4
|
-
|
|
5
|
-
var Immutable = _interopRequireWildcard(_immutable);
|
|
6
|
-
|
|
7
|
-
var _chai = require("chai");
|
|
8
|
-
|
|
9
|
-
var _chai2 = _interopRequireDefault(_chai);
|
|
10
|
-
|
|
11
|
-
var _chaiImmutable = require("chai-immutable");
|
|
12
|
-
|
|
13
|
-
var _chaiImmutable2 = _interopRequireDefault(_chaiImmutable);
|
|
14
|
-
|
|
15
|
-
var _actions = require("../actions");
|
|
16
|
-
|
|
17
|
-
var _actions2 = _interopRequireDefault(_actions);
|
|
18
|
-
|
|
19
|
-
var _reducers = require("../reducers");
|
|
20
|
-
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
|
|
23
|
-
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
|
24
|
-
|
|
25
|
-
_chai2.default.use(_chaiImmutable2.default); /* eslint-disable max-len, no-undefined, max-lines-per-function */
|
|
26
|
-
|
|
27
|
-
var requestPage = _actions2.default.requestPage,
|
|
28
|
-
receivePage = _actions2.default.receivePage;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var requestPageAction = requestPage({
|
|
32
|
-
endpoint: "some/api/endpoint",
|
|
33
|
-
resultsKey: "results",
|
|
34
|
-
totalKey: "total",
|
|
35
|
-
pageArgName: "p",
|
|
36
|
-
idKey: "id",
|
|
37
|
-
page: 2,
|
|
38
|
-
token: "foo=bar"
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
var receivePageAction = receivePage({
|
|
42
|
-
endpoint: "some/api/endpoint/",
|
|
43
|
-
pageArgName: "p",
|
|
44
|
-
idKey: "id",
|
|
45
|
-
page: 2,
|
|
46
|
-
token: "foo=bar",
|
|
47
|
-
items: [{
|
|
48
|
-
id: "baz",
|
|
49
|
-
fooField: "bazValue"
|
|
50
|
-
}, {
|
|
51
|
-
id: "bar",
|
|
52
|
-
fooField: "barValue"
|
|
53
|
-
}],
|
|
54
|
-
total: 2
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe("pages reducer", function () {
|
|
58
|
-
|
|
59
|
-
it("should return the state by default", function () {
|
|
60
|
-
var state = (0, _reducers.pages)(Immutable.Map({
|
|
61
|
-
some: "state"
|
|
62
|
-
}), { type: "some action" });
|
|
63
|
-
|
|
64
|
-
(0, _chai.expect)(state).to.equal(Immutable.Map({
|
|
65
|
-
some: "state"
|
|
66
|
-
}));
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
it("should initialize the pages map with a new page entry when requesting new page", function () {
|
|
70
|
-
var state = (0, _reducers.pages)(undefined, requestPageAction);
|
|
71
|
-
|
|
72
|
-
(0, _chai.expect)(state).to.equal(Immutable.Map({
|
|
73
|
-
"foo=bar": Immutable.Map({
|
|
74
|
-
page: 2,
|
|
75
|
-
token: "foo=bar",
|
|
76
|
-
ids: Immutable.List(),
|
|
77
|
-
fetching: true,
|
|
78
|
-
error: false,
|
|
79
|
-
view: 1,
|
|
80
|
-
fetched: false
|
|
81
|
-
})
|
|
82
|
-
}));
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should populate the pages map at the page url key with the item ids", function () {
|
|
86
|
-
var state = (0, _reducers.pages)(Immutable.Map({
|
|
87
|
-
"foo=bar": Immutable.Map({
|
|
88
|
-
page: 2,
|
|
89
|
-
token: "foo=bar",
|
|
90
|
-
ids: Immutable.List(),
|
|
91
|
-
fetching: true,
|
|
92
|
-
fetched: false
|
|
93
|
-
})
|
|
94
|
-
}), receivePageAction);
|
|
95
|
-
|
|
96
|
-
(0, _chai.expect)(state).to.equal(Immutable.Map({
|
|
97
|
-
"foo=bar": Immutable.Map({
|
|
98
|
-
page: 2,
|
|
99
|
-
token: "foo=bar",
|
|
100
|
-
ids: Immutable.List(["baz", "bar"]),
|
|
101
|
-
fetching: false,
|
|
102
|
-
fetched: true,
|
|
103
|
-
error: false,
|
|
104
|
-
total: 2
|
|
105
|
-
})
|
|
106
|
-
}));
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
describe("items reducer", function () {
|
|
111
|
-
|
|
112
|
-
it("should populate the items map with item received", function () {
|
|
113
|
-
var state = (0, _reducers.items)(undefined, receivePageAction);
|
|
114
|
-
|
|
115
|
-
(0, _chai.expect)(state).to.equal(Immutable.Map({
|
|
116
|
-
"baz": Immutable.Map({
|
|
117
|
-
id: "baz",
|
|
118
|
-
fooField: "bazValue"
|
|
119
|
-
}),
|
|
120
|
-
"bar": Immutable.Map({
|
|
121
|
-
id: "bar",
|
|
122
|
-
fooField: "barValue"
|
|
123
|
-
})
|
|
124
|
-
}));
|
|
125
|
-
});
|
|
126
|
-
});
|