MainScreenWrapperActionHelper test
[aai/sparky-fe.git] / test / app / MainScreenWrapperActionHelper.test.js
1 import configureStore from 'redux-mock-store';
2 import thunk from 'redux-thunk'
3 import {
4   windowResize,
5   showMainMenu,
6   extensibleViewMessageCallback,
7   clearExtensibleViewData,
8   setSecondaryTitle
9 } from 'app/MainScreenWrapperActionHelper';
10 import {
11   getSetGlobalMessageEvent,
12   getClearGlobalMessageEvent
13 } from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions';
14 import {
15   globalInlineMessageBarActionTypes
16 } from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants';
17 import {aaiActionTypes} from 'app/MainScreenWrapperConstants';
18
19 const mockStore = configureStore([thunk]);
20
21 describe('MainScreenWrapperActionHelper', () => {
22   let store;
23
24   beforeEach(() => {
25     store = mockStore({ tierSupportReducer: {} });
26   });
27
28   describe('windowResize', () => {
29     it('emits action', () => {
30       // Given
31       const expectedActions = [{
32         type: aaiActionTypes.AAI_WINDOW_RESIZE
33       }];
34
35       // When
36       store.dispatch(windowResize());
37
38       // Then
39       expect(store.getActions()).toEqual(expectedActions);
40     });
41   });
42
43   describe('showMainMenu', () => {
44     it('emits action with payload', () => {
45       // Given
46       const input = "testInput";
47       const expectedActions = [{
48         type: aaiActionTypes.AAI_SHOW_MENU,
49         data: {
50           showMenu: input
51         }
52       }];
53
54       // When
55       store.dispatch(showMainMenu(input));
56
57       // Then
58       expect(store.getActions()).toEqual(expectedActions);
59     });
60   });
61
62   describe('extensibleViewMessageCallback', () => {
63     const msgSeverity = "msgSeverity";
64
65     it('emits action with payload when msgText is not blank', () => {
66       // Given
67       const msgText = "msgText";
68       const expectedActions = [{
69         type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE,
70         data: {
71           msgText: msgText,
72           msgSeverity: msgSeverity
73         }
74       }];
75
76       // When
77       store.dispatch(extensibleViewMessageCallback(msgText, msgSeverity));
78
79       // Then
80       expect(store.getActions()).toEqual(expectedActions);
81     });
82
83     it('emits action when msgText is blank', () => {
84       // Given
85       const msgText = "";
86       const expectedActions = [{
87         type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE
88
89       }];
90
91       // When
92       store.dispatch(extensibleViewMessageCallback(msgText, msgSeverity));
93
94       // Then
95       expect(store.getActions()).toEqual(expectedActions);
96     });
97   });
98
99   describe('clearExtensibleViewData', () => {
100     it('emits action with payload', () => {
101       // Given
102       const expectedActions = [{
103         type: aaiActionTypes.EXTENSIBLE_VIEW_NETWORK_CALLBACK_CLEAR_DATA,
104         data: {}
105       }];
106
107       // When
108       store.dispatch(clearExtensibleViewData());
109
110       // Then
111       expect(store.getActions()).toEqual(expectedActions);
112     });
113   });
114
115   describe('setSecondaryTitle', () => {
116     it('emits action with payload', () => {
117       // Given
118       const title = "testTitle";
119       const expectedActions = [{
120         type: aaiActionTypes.SET_SECONDARY_TITLE,
121         data: title
122       }];
123
124       // When
125       store.dispatch(setSecondaryTitle(title));
126
127       // Then
128       expect(store.getActions()).toEqual(expectedActions);
129     });
130   });
131
132 });