Skip to content

Commit 631ead2

Browse files
committed
PoC implementation of **item** actions and reducer
1 parent 5573f19 commit 631ead2

File tree

16 files changed

+555
-2
lines changed

16 files changed

+555
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Topcoder React Utils Changelog
22

3+
### v0.4.4
4+
PoC implementation of **item** actions and reducer.
5+
36
### v0.4.3
47
- Removes `adopt-dev-deps` script (use
58
[`topcoder-lib-setup`](docs/topcoder-lib-setup-script.md) instead).

__tests__/__snapshots__/index.js.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ Object {
2020
"loadItemDone": [Function],
2121
"loadItemInit": [Function],
2222
},
23+
"item": Object {
24+
"dropData": [Function],
25+
"loadDataDone": [Function],
26+
"loadDataInit": [Function],
27+
"setData": [Function],
28+
"updateReferenceCounter": [Function],
29+
},
2330
},
2431
"client": [Function],
2532
"config": undefined,
@@ -32,6 +39,7 @@ Object {
3239
},
3340
"reducers": Object {
3441
"collection": [Function],
42+
"item": [Function],
3543
},
3644
"redux": Object {
3745
"combineReducers": [Function],
@@ -162,6 +170,13 @@ Object {
162170
"loadItemDone": [Function],
163171
"loadItemInit": [Function],
164172
},
173+
"item": Object {
174+
"dropData": [Function],
175+
"loadDataDone": [Function],
176+
"loadDataInit": [Function],
177+
"setData": [Function],
178+
"updateReferenceCounter": [Function],
179+
},
165180
},
166181
"client": [Function],
167182
"config": Config {
@@ -179,6 +194,7 @@ Object {
179194
},
180195
"reducers": Object {
181196
"collection": [Function],
197+
"item": [Function],
182198
},
183199
"redux": Object {
184200
"combineReducers": [Function],

__tests__/shared/actions/__snapshots__/index.js.snap

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,12 @@ Object {
1010
"loadItemDone": [Function],
1111
"loadItemInit": [Function],
1212
},
13+
"item": Object {
14+
"dropData": [Function],
15+
"loadDataDone": [Function],
16+
"loadDataInit": [Function],
17+
"setData": [Function],
18+
"updateReferenceCounter": [Function],
19+
},
1320
}
1421
`;
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Module exports 1`] = `
4+
Object {
5+
"item": Object {
6+
"dropData": [Function],
7+
"loadDataDone": [Function],
8+
"loadDataInit": [Function],
9+
"setData": [Function],
10+
"updateReferenceCounter": [Function],
11+
},
12+
}
13+
`;
14+
15+
exports[`dropData 1`] = `
16+
Object {
17+
"payload": 1.7976931348623157e+308,
18+
"type": "ITEM/DROP_DATA",
19+
}
20+
`;
21+
22+
exports[`dropData 2`] = `
23+
Object {
24+
"payload": 12345,
25+
"type": "ITEM/DROP_DATA",
26+
}
27+
`;
28+
29+
exports[`getDataDone 1`] = `
30+
Object {
31+
"payload": Object {
32+
"data": "Dummy Data",
33+
"loadingOperationId": "12345",
34+
"timestamp": 1527961703000,
35+
},
36+
"type": "ITEM/LOAD_DATA_DONE",
37+
}
38+
`;
39+
40+
exports[`getDataInit 1`] = `
41+
Object {
42+
"payload": "12345",
43+
"type": "ITEM/LOAD_DATA_INIT",
44+
}
45+
`;
46+
47+
exports[`setData 1`] = `
48+
Object {
49+
"payload": Object {
50+
"data": "Dummy Data",
51+
"timestamp": 1527961703000,
52+
},
53+
"type": "ITEM/SET_DATA",
54+
}
55+
`;
56+
57+
exports[`updateReferenceCounter 1`] = `
58+
Object {
59+
"payload": 123,
60+
"type": "ITEM/UPDATE_REFERENCE_COUNTER",
61+
}
62+
`;
63+
64+
exports[`updateReferenceCounter 2`] = `
65+
Object {
66+
"payload": -123,
67+
"type": "ITEM/UPDATE_REFERENCE_COUNTER",
68+
}
69+
`;

__tests__/shared/actions/item.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Testing of payload creators for item actions.
3+
*/
4+
5+
import actions from 'actions/item';
6+
import MockDate from 'mockdate';
7+
8+
const a = actions.item;
9+
10+
beforeAll(() => MockDate.set('2018-06-02T19:11:23+01:23'));
11+
afterAll(() => MockDate.reset());
12+
13+
test('Module exports', () => expect(actions).toMatchSnapshot());
14+
15+
test('dropData', () => {
16+
expect(a.dropData()).toMatchSnapshot();
17+
expect(a.dropData(12345)).toMatchSnapshot();
18+
});
19+
20+
test('getDataInit', () => {
21+
expect(a.loadDataInit('12345')).toMatchSnapshot();
22+
});
23+
24+
test('getDataDone', () => {
25+
expect(a.loadDataDone('12345', 'Dummy Data')).toMatchSnapshot();
26+
});
27+
28+
test('setData', () => {
29+
expect(a.setData('Dummy Data')).toMatchSnapshot();
30+
});
31+
32+
test('updateReferenceCounter', () => {
33+
expect(a.updateReferenceCounter(123)).toMatchSnapshot();
34+
expect(a.updateReferenceCounter(-123)).toMatchSnapshot();
35+
});
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Snapshot testing case #1 1`] = `
4+
Object {
5+
"data": null,
6+
"loadingOperationId": null,
7+
"numRefs": 0,
8+
"timestamp": 0,
9+
}
10+
`;
11+
12+
exports[`Snapshot testing case #1 2`] = `
13+
Object {
14+
"data": null,
15+
"loadingOperationId": null,
16+
"numRefs": 1,
17+
"timestamp": 0,
18+
}
19+
`;
20+
21+
exports[`Snapshot testing case #1 3`] = `
22+
Object {
23+
"data": "Test data",
24+
"loadingOperationId": null,
25+
"numRefs": 1,
26+
"timestamp": 1527945685468,
27+
}
28+
`;
29+
30+
exports[`Snapshot testing case #1 4`] = `
31+
Object {
32+
"data": "Test data",
33+
"loadingOperationId": null,
34+
"numRefs": 1,
35+
"timestamp": 1527945685468,
36+
}
37+
`;
38+
39+
exports[`Snapshot testing case #1 5`] = `
40+
Object {
41+
"data": "Test data",
42+
"loadingOperationId": null,
43+
"numRefs": 0,
44+
"timestamp": 1527945685468,
45+
}
46+
`;
47+
48+
exports[`Snapshot testing case #1 6`] = `
49+
Object {
50+
"data": null,
51+
"loadingOperationId": null,
52+
"numRefs": 0,
53+
"timestamp": 0,
54+
}
55+
`;
56+
57+
exports[`Snapshot testing case #2 1`] = `
58+
Object {
59+
"data": null,
60+
"loadingOperationId": null,
61+
"numRefs": 0,
62+
"timestamp": 0,
63+
}
64+
`;
65+
66+
exports[`Snapshot testing case #2 2`] = `
67+
Object {
68+
"data": null,
69+
"loadingOperationId": 12345,
70+
"numRefs": 0,
71+
"timestamp": 0,
72+
}
73+
`;
74+
75+
exports[`Snapshot testing case #2 3`] = `
76+
Object {
77+
"data": null,
78+
"loadingOperationId": 12345,
79+
"numRefs": 0,
80+
"timestamp": 0,
81+
}
82+
`;
83+
84+
exports[`Snapshot testing case #2 4`] = `
85+
Object {
86+
"data": "Temporary Data",
87+
"loadingOperationId": 12345,
88+
"numRefs": 0,
89+
"timestamp": 1527945694106,
90+
}
91+
`;
92+
93+
exports[`Snapshot testing case #2 5`] = `
94+
Object {
95+
"data": "Temporary Data",
96+
"loadingOperationId": 12345,
97+
"numRefs": 0,
98+
"timestamp": 1527945694106,
99+
}
100+
`;
101+
102+
exports[`Snapshot testing case #2 6`] = `
103+
Object {
104+
"data": "Correct data",
105+
"loadingOperationId": null,
106+
"numRefs": 0,
107+
"timestamp": 1527945696574,
108+
}
109+
`;
110+
111+
exports[`Snapshot testing case #2 7`] = `
112+
Object {
113+
"data": "Correct data",
114+
"loadingOperationId": null,
115+
"numRefs": 0,
116+
"timestamp": 1527945696574,
117+
}
118+
`;
119+
120+
exports[`Snapshot testing case #2 8`] = `
121+
Object {
122+
"data": "Correct data",
123+
"loadingOperationId": null,
124+
"numRefs": -3,
125+
"timestamp": 1527945696574,
126+
}
127+
`;
128+
129+
exports[`Snapshot testing case #2 9`] = `
130+
Object {
131+
"data": null,
132+
"loadingOperationId": null,
133+
"numRefs": -3,
134+
"timestamp": 0,
135+
}
136+
`;

__tests__/shared/reducers/item.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import actions from 'actions/item';
2+
import reducer from 'reducers/item';
3+
import mockDate from 'mockdate';
4+
5+
beforeAll(() => mockDate.set('2018-06-02T18:31:23+05:10'));
6+
afterAll(() => mockDate.reset());
7+
8+
describe('Snapshot testing', () => {
9+
const a = actions.item;
10+
let state;
11+
12+
function check(action) {
13+
state = reducer(state, action);
14+
expect(state).toMatchSnapshot();
15+
mockDate.set(Date.now() + 1234);
16+
}
17+
18+
beforeEach(() => {
19+
state = undefined;
20+
});
21+
22+
test('case #1', () => {
23+
check('@@INIT');
24+
check(a.updateReferenceCounter(1));
25+
check(a.setData('Test data'));
26+
check(a.dropData());
27+
check(a.updateReferenceCounter(-1));
28+
check(a.dropData());
29+
});
30+
31+
test('case #2', () => {
32+
check('@@INIT');
33+
check(a.loadDataInit(12345));
34+
check(a.dropData());
35+
check(a.setData('Temporary Data'));
36+
check(a.loadDataDone(0, 'Wrong data'));
37+
check(a.loadDataDone(12345, 'Correct data'));
38+
check(a.dropData(Date.now() - 10000));
39+
check(a.updateReferenceCounter(-3));
40+
check(a.dropData());
41+
});
42+
});

0 commit comments

Comments
 (0)