GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 043e72...5d2753 )
by Benjamin
06:48 queued 02:54
created

test/reducers/components/plugins/selection.test.js   A

Complexity

Total Complexity 23
Complexity/F 1

Size

Lines of Code 294
Function Count 23

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
cc 0
wmc 23
c 3
b 0
f 2
nc 1
mnd 0
bc 19
fnc 23
dl 0
loc 294
rs 10
bpm 0.826
cpm 1
noi 1
1
/* eslint-enable describe it */
2
import expect from 'expect';
3
import { fromJS } from 'immutable';
4
5
import {
6
    SELECT_ALL,
7
    SET_SELECTION,
8
    DESELECT_ALL,
9
    SET_DATA
10
} from './../../../../src/constants/ActionTypes';
11
12
import
13
    selection,
14
    { setIndexes }
15
from './../../../../src/reducers/components/plugins/selection';
16
17
import {
18
    generateLastUpdate,
19
    resetLastUpdate
20
} from './../../../../src/util/lastUpdate';
21
22
describe('The selectAll func in the selection reducer', () => {
23
    beforeEach(() => resetLastUpdate());
24
25
    const state = fromJS({
26
        'test-grid': {
27
            fakeRow: false,
28
            anotherRow: false
29
        }
30
    });
31
32
    const action = {
33
        type: SELECT_ALL,
34
        stateKey: 'test-grid',
35
        selection: {
36
            fakeRow: true,
37
            anotherRow: true
38
        }
39
    };
40
41
    it('Should return all rows as selected', () => {
42
        expect(
43
            selection(state, action)
44
        ).toEqualImmutable(
45
            fromJS({
46
                'test-grid': {
47
                    fakeRow: true,
48
                    anotherRow: true,
49
                    lastUpdate: 1
50
                }
51
            })
52
        );
53
    });
54
55
});
56
57
describe('The deselectAll func in the selection reducer', () => {
58
    beforeEach(() => resetLastUpdate());
59
60
    const state = fromJS({
61
        'test-grid': {
62
            fakeRow: false,
63
            anotherRow: false
64
        }
65
    });
66
67
    const action = {
68
        type: DESELECT_ALL,
69
        stateKey: 'test-grid'
70
    };
71
72
    it('Should return an empty map upon deselect', () => {
73
        expect(
74
            selection(state, action)
75
        ).toEqualImmutable(
76
            fromJS({
77
                'test-grid': { lastUpdate: 1 }
78
            })
79
        );
80
    });
81
82
});
83
84
describe('The setSelection setIndexes tests', () => {
85
86
    it('Should set an index if none are present', () => {
87
88
        expect(
89
            setIndexes(1, undefined)
90
        ).toEqual([
91
            1
92
        ]);
93
94
    });
95
96
    it('Should not set duplicate index', () => {
97
98
        expect(
99
            setIndexes(1, [1])
100
        ).toEqual([
101
            1
102
        ]);
103
104
    });
105
106
    it(['Should not set duplicate index,',
107
        'but be able to add array values'].join(' '), () => {
108
109
        expect(
110
            setIndexes([1, 2], [1])
111
        ).toEqual([
112
            1, 2
113
        ]);
114
115
    });
116
117
    it('Should not set duplicate index even if they are passed', () => {
118
119
        expect(
120
            setIndexes([1, 2, 3, 4, 4], [1])
121
        ).toEqual([
122
            1, 2, 3, 4
123
        ]);
124
125
    });
126
127
    it('Should remove a value', () => {
128
129
        expect(
130
            setIndexes(1, [1], true)
131
        ).toEqual([]);
132
133
    });
134
135
    it('Should remove multiple values', () => {
136
137
        expect(
138
            setIndexes([1, 2], [1, 2, 3], true)
139
        ).toEqual([3]);
140
141
    });
142
143
    it('Should remove multiple values, and return empty arr', () => {
144
145
        expect(
146
            setIndexes([1, 2], [1, 2, 3], true)
147
        ).toEqual([3]);
148
149
    });
150
});
151
152
describe('The SET_DATA action in the selection reducer', () => {
153
    beforeEach(() => resetLastUpdate());
154
155
    const state = fromJS({
156
        'test-grid': {
157
            fakeRow: true,
158
            anotherRow: false,
159
            indexes: [0]
160
        }
161
    });
162
163
    const action = {
164
        type: SET_DATA,
165
        stateKey: 'test-grid'
166
    };
167
168
    it('Should wipe out all previous selections', () => {
169
        expect(selection(state, action))
170
            .toEqualImmutable(fromJS({
171
                'test-grid': {
172
                    lastUpdate: 1
173
                }
174
            }));
175
    });
176
177
});
178
179
describe('The setSelection func in the selection reducer', () => {
180
    beforeEach(() => resetLastUpdate());
181
182
    const state = fromJS({
183
        'test-grid': {
184
            fakeRow: true,
185
            anotherRow: false,
186
            indexes: [0]
187
        }
188
    });
189
190
    it(['Should should select a value and clear other values, ',
191
        'and clearSelections is passed'].join(''), () => {
192
193
        const action = {
194
            type: SET_SELECTION,
195
            stateKey: 'test-grid',
196
            clearSelections: true,
197
            id: 'anotherRow',
198
            index: 1
199
        };
200
201
        expect(
202
            selection(state, action)
203
        ).toEqualImmutable(
204
            fromJS({
205
                'test-grid': {
206
                    anotherRow: true,
207
                    lastUpdate: 1,
208
                    indexes: [1]
209
                }
210
            })
211
        );
212
    });
213
214
    it(['Should deselect a value if already selected, ',
215
        'and clearSelections is passed'].join(''), () => {
216
217
        const action = {
218
            type: SET_SELECTION,
219
            stateKey: 'test-grid',
220
            clearSelections: true,
221
            allowDeselect: true,
222
            id: 'fakeRow',
223
            index: 1
224
        };
225
226
        expect(
227
            selection(state, action)
228
        ).toEqualImmutable(
229
            fromJS({
230
                'test-grid': {
231
                    fakeRow: false,
232
                    lastUpdate: 1,
233
                    indexes: []
234
                }
235
            })
236
        );
237
    });
238
239
    it('Should select initial value if none are selected', () => {
240
241
        const innerState = fromJS({});
242
243
        const action = {
244
            type: SET_SELECTION,
245
            stateKey: 'test-grid',
246
            id: 'fakeRow',
247
            index: 11
248
        };
249
250
        expect(
251
            selection(innerState, action)
252
        ).toEqualImmutable(
253
            fromJS({
254
                'test-grid': {
255
                    fakeRow: true,
256
                    lastUpdate: 1,
257
                    indexes: [11]
258
                }
259
            })
260
        );
261
    });
262
263
    it('Should allow multiselect if clearSelections is false', () => {
264
265
        const selectedState = fromJS({
266
            'test-grid': {
267
                fakeRow: true,
268
                indexes: [0]
269
            }
270
        });
271
272
        const action = {
273
            type: SET_SELECTION,
274
            stateKey: 'test-grid',
275
            id: 'anotherRow',
276
            clearSelections: false,
277
            index: 1
278
        };
279
280
        expect(
281
            selection(selectedState, action)
282
        ).toEqualImmutable(
283
            fromJS({
284
                'test-grid': {
285
                    fakeRow: true,
286
                    anotherRow: true,
287
                    indexes: [0, 1],
288
                    lastUpdate: 1
289
                }
290
            })
291
        );
292
293
    });
294
295
});
296