GlobalInlineMessageBarReducer test
[aai/sparky-fe.git] / test / app / globalInlineMessageBar / GlobalInlineMessageBarReducer.test.js
1 import GlobalInlineMessageBarReducer from 'app/globalInlineMessageBar/GlobalInlineMessageBarReducer';
2 import {
3   globalInlineMessageBarActionTypes
4 } from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants';
5 import {
6   MESSAGE_LEVEL_WARNING
7 } from 'utils/GlobalConstants'
8
9 describe('GlobalInlineMessageBarReducerTests', () => {
10   it('Action Type: SET_GLOBAL_MESSAGE', () => {
11     // Given
12     const action = {
13       type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE,
14       data: {
15         msgText: 'some error message here',
16         msgSeverity: MESSAGE_LEVEL_WARNING
17       }
18     };
19     let state = {};
20
21     // When
22     state = GlobalInlineMessageBarReducer(state, action);
23
24     // Then
25     expect(state).toEqual({
26       feedbackMsgText: action.data.msgText,
27       feedbackMsgSeverity: action.data.msgSeverity
28     });
29   });
30
31   it('Action Type: CLEAR_GLOBAL_MESSAGE', () => {
32     // Given
33     const action = {
34       type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE
35     };
36     let state = {
37       feedbackMsgText: 'some error message here',
38       feedbackMsgSeverity: MESSAGE_LEVEL_WARNING
39     };
40
41     // When
42     state = GlobalInlineMessageBarReducer(state, action);
43
44     // Then
45     expect(state).toEqual({
46       feedbackMsgText: '',
47       feedbackMsgSeverity: ''
48     });
49   });
50
51   it('Action Type: unknown', () => {
52     // Given
53     const action = {
54       type: "TestUnknownType"
55     };
56     const initialState = {
57       feedbackMsgText: 'some error message here',
58       feedbackMsgSeverity: MESSAGE_LEVEL_WARNING
59     };
60
61     // When
62     const newState = GlobalInlineMessageBarReducer(initialState, action);
63
64     // Then
65     expect(newState).toEqual(initialState);
66   });
67 });