|
1
|
|
|
/* eslint-enable describe it */ |
|
2
|
|
|
import expect from 'expect'; |
|
3
|
|
|
import { fromJS } from 'immutable'; |
|
4
|
|
|
|
|
5
|
|
|
import { |
|
6
|
|
|
ERROR_OCCURRED, |
|
7
|
|
|
DISMISS_ERROR |
|
8
|
|
|
} from './../../../../src/constants/ActionTypes'; |
|
9
|
|
|
|
|
10
|
|
|
import |
|
11
|
|
|
errorhandler |
|
12
|
|
|
from './../../../../src/reducers/components/plugins/errorhandler'; |
|
13
|
|
|
|
|
14
|
|
|
import { |
|
15
|
|
|
generateLastUpdate, |
|
16
|
|
|
resetLastUpdate |
|
17
|
|
|
} from './../../../../src/util/lastUpdate'; |
|
18
|
|
|
|
|
19
|
|
|
describe('The errorhandler reducer', () => { |
|
20
|
|
|
beforeEach(() => resetLastUpdate()); |
|
21
|
|
|
|
|
22
|
|
|
it('Should set an error if state was blank', () => { |
|
23
|
|
|
|
|
24
|
|
|
const state = fromJS({}); |
|
25
|
|
|
|
|
26
|
|
|
const action = { |
|
27
|
|
|
type: ERROR_OCCURRED, |
|
28
|
|
|
error: 'A generic error occurred dude', |
|
29
|
|
|
stateKey: 'test-grid' |
|
30
|
|
|
}; |
|
31
|
|
|
|
|
32
|
|
|
expect( |
|
33
|
|
|
errorhandler(state, action) |
|
34
|
|
|
).toEqualImmutable(fromJS({ |
|
35
|
|
|
'test-grid': { |
|
36
|
|
|
error: 'A generic error occurred dude', |
|
37
|
|
|
errorOccurred: true, |
|
38
|
|
|
lastUpdate: 1 |
|
39
|
|
|
} |
|
40
|
|
|
})); |
|
41
|
|
|
|
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
it('Should set an error if state was had an earlier error', () => { |
|
45
|
|
|
|
|
46
|
|
|
const state = fromJS({ |
|
47
|
|
|
'test-grid': { |
|
48
|
|
|
error: 'A generic error occurred dude', |
|
49
|
|
|
errorOccurred: true |
|
50
|
|
|
} |
|
51
|
|
|
}); |
|
52
|
|
|
|
|
53
|
|
|
const action = { |
|
54
|
|
|
type: ERROR_OCCURRED, |
|
55
|
|
|
error: 'A newer error happened', |
|
56
|
|
|
stateKey: 'test-grid' |
|
57
|
|
|
}; |
|
58
|
|
|
|
|
59
|
|
|
expect( |
|
60
|
|
|
errorhandler(state, action) |
|
61
|
|
|
).toEqualImmutable(fromJS({ |
|
62
|
|
|
'test-grid': { |
|
63
|
|
|
error: 'A newer error happened', |
|
64
|
|
|
errorOccurred: true, |
|
65
|
|
|
lastUpdate: 1 |
|
66
|
|
|
} |
|
67
|
|
|
})); |
|
68
|
|
|
|
|
69
|
|
|
}); |
|
70
|
|
|
|
|
71
|
|
|
it('Should wipe an error if state was had an earlier error', () => { |
|
72
|
|
|
|
|
73
|
|
|
const state = fromJS({ |
|
74
|
|
|
'test-grid': { |
|
75
|
|
|
error: 'A generic error occurred dude', |
|
76
|
|
|
errorOccurred: true, |
|
77
|
|
|
lastUpdate: 1 |
|
78
|
|
|
} |
|
79
|
|
|
}); |
|
80
|
|
|
|
|
81
|
|
|
const action = { |
|
82
|
|
|
type: DISMISS_ERROR, |
|
83
|
|
|
stateKey: 'test-grid' |
|
84
|
|
|
}; |
|
85
|
|
|
|
|
86
|
|
|
expect( |
|
87
|
|
|
errorhandler(state, action) |
|
88
|
|
|
).toEqualImmutable(fromJS({ |
|
89
|
|
|
'test-grid': { |
|
90
|
|
|
error: '', |
|
91
|
|
|
errorOccurred: false, |
|
92
|
|
|
lastUpdate: 1 |
|
93
|
|
|
} |
|
94
|
|
|
})); |
|
95
|
|
|
|
|
96
|
|
|
}); |
|
97
|
|
|
|
|
98
|
|
|
}); |
|
99
|
|
|
|