1 | "use strict";
|
2 |
|
3 | var _recompose = require("recompose");
|
4 |
|
5 | var _asyncReductions = require("./async-reductions");
|
6 |
|
7 | test('setAsyncRequest', function () {
|
8 | var asyncState = {};
|
9 | expect((0, _asyncReductions.setAsyncRequest)(asyncState, {
|
10 | key: 'foo'
|
11 | })).toEqual({
|
12 | foo: true
|
13 | });
|
14 | expect((0, _asyncReductions.setAsyncRequest)(asyncState, {
|
15 | key: 'foo',
|
16 | useStatus: true
|
17 | })).toEqual({
|
18 | foo: 'REQUEST'
|
19 | });
|
20 | expect((0, _asyncReductions.setAsyncRequest)(asyncState, {
|
21 | key: 'foo',
|
22 | status: 'CUSTOM'
|
23 | })).toEqual({
|
24 | foo: 'CUSTOM'
|
25 | });
|
26 | expect(function () {
|
27 | return (0, _asyncReductions.setAsyncRequest)(asyncState, {
|
28 | key: 'foo',
|
29 | useStatus: false,
|
30 | status: 'CUSTOM'
|
31 | });
|
32 | }).toThrow();
|
33 | expect((0, _recompose.compose)((0, _asyncReductions.setAsyncRequest)({
|
34 | key: 'foo',
|
35 | status: 'CUSTOM'
|
36 | }))(asyncState)).toEqual({
|
37 | foo: 'CUSTOM'
|
38 | });
|
39 | });
|
40 | test('setAsyncSuccess', function () {
|
41 | var asyncState = {
|
42 | foo: true
|
43 | };
|
44 | expect((0, _asyncReductions.setAsyncSuccess)(asyncState, {
|
45 | key: 'foo'
|
46 | })).toEqual({});
|
47 | expect((0, _asyncReductions.setAsyncSuccess)(asyncState, {
|
48 | key: 'foo',
|
49 | useStatus: true
|
50 | })).toEqual({
|
51 | foo: 'SUCCESS'
|
52 | });
|
53 | expect((0, _asyncReductions.setAsyncSuccess)(asyncState, {
|
54 | key: 'foo',
|
55 | status: 'CUSTOM'
|
56 | })).toEqual({
|
57 | foo: 'CUSTOM'
|
58 | });
|
59 | expect(function () {
|
60 | return (0, _asyncReductions.setAsyncSuccess)(asyncState, {
|
61 | key: 'foo',
|
62 | useStatus: false,
|
63 | status: 'CUSTOM'
|
64 | });
|
65 | }).toThrow();
|
66 | expect((0, _recompose.compose)((0, _asyncReductions.setAsyncSuccess)({
|
67 | key: 'foo',
|
68 | status: 'CUSTOM'
|
69 | }))(asyncState)).toEqual({
|
70 | foo: 'CUSTOM'
|
71 | });
|
72 | });
|
73 | test('setAsyncFailure', function () {
|
74 | var asyncState = {
|
75 | foo: true
|
76 | };
|
77 | expect((0, _asyncReductions.setAsyncFailure)(asyncState, {
|
78 | key: 'foo'
|
79 | })).toEqual({});
|
80 | expect((0, _asyncReductions.setAsyncFailure)(asyncState, {
|
81 | key: 'foo',
|
82 | useStatus: true
|
83 | })).toEqual({
|
84 | foo: 'FAILURE'
|
85 | });
|
86 | expect((0, _asyncReductions.setAsyncFailure)(asyncState, {
|
87 | key: 'foo',
|
88 | status: 'CUSTOM'
|
89 | })).toEqual({
|
90 | foo: 'CUSTOM'
|
91 | });
|
92 | expect(function () {
|
93 | return (0, _asyncReductions.setAsyncFailure)(asyncState, {
|
94 | key: 'foo',
|
95 | useStatus: false,
|
96 | status: 'CUSTOM'
|
97 | });
|
98 | }).toThrow();
|
99 | expect((0, _recompose.compose)((0, _asyncReductions.setAsyncFailure)({
|
100 | key: 'foo',
|
101 | status: 'CUSTOM'
|
102 | }))(asyncState)).toEqual({
|
103 | foo: 'CUSTOM'
|
104 | });
|
105 | });
|
106 | test('delAsyncEntry', function () {
|
107 | var asyncState = {
|
108 | foo: 'foo'
|
109 | };
|
110 | expect(function () {
|
111 | return (0, _asyncReductions.delAsyncEntry)();
|
112 | }).toThrow();
|
113 | expect(function () {
|
114 | return (0, _asyncReductions.delAsyncEntry)(1);
|
115 | }).toThrow();
|
116 | expect((0, _asyncReductions.delAsyncEntry)('foo')(asyncState)).toEqual({});
|
117 | expect((0, _recompose.compose)((0, _asyncReductions.delAsyncEntry)('foo'))(asyncState)).toEqual({});
|
118 | });
|
119 | test('clearAsync', function () {
|
120 | var asyncState = {
|
121 | foo: 'foo',
|
122 | bar: 'bar'
|
123 | };
|
124 | expect((0, _asyncReductions.clearAsync)()).toEqual({});
|
125 | expect((0, _asyncReductions.clearAsync)('foo')(asyncState)).toEqual({
|
126 | foo: 'foo'
|
127 | });
|
128 | expect((0, _recompose.compose)((0, _asyncReductions.clearAsync)('foo'))(asyncState)).toEqual({
|
129 | foo: 'foo'
|
130 | });
|
131 | }); |
\ | No newline at end of file |