summaryrefslogtreecommitdiffstats
path: root/test/app/MainScreenWrapperActionHelper.test.js
blob: 011010ecadef9a6a982efcc1c272ff58dc35360e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk'
import {
  windowResize,
  showMainMenu,
  extensibleViewMessageCallback,
  clearExtensibleViewData,
  setSecondaryTitle
} from 'app/MainScreenWrapperActionHelper';
import {
  getSetGlobalMessageEvent,
  getClearGlobalMessageEvent
} from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions';
import {
  globalInlineMessageBarActionTypes
} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants';
import {aaiActionTypes} from 'app/MainScreenWrapperConstants';

const mockStore = configureStore([thunk]);

describe('MainScreenWrapperActionHelper', () => {
  let store;

  beforeEach(() => {
    store = mockStore({ tierSupportReducer: {} });
  });

  describe('windowResize', () => {
    it('emits action', () => {
      // Given
      const expectedActions = [{
        type: aaiActionTypes.AAI_WINDOW_RESIZE
      }];

      // When
      store.dispatch(windowResize());

      // Then
      expect(store.getActions()).toEqual(expectedActions);
    });
  });

  describe('showMainMenu', () => {
    it('emits action with payload', () => {
      // Given
      const input = "testInput";
      const expectedActions = [{
        type: aaiActionTypes.AAI_SHOW_MENU,
        data: {
          showMenu: input
        }
      }];

      // When
      store.dispatch(showMainMenu(input));

      // Then
      expect(store.getActions()).toEqual(expectedActions);
    });
  });

  describe('extensibleViewMessageCallback', () => {
    const msgSeverity = "msgSeverity";

    it('emits action with payload when msgText is not blank', () => {
      // Given
      const msgText = "msgText";
      const expectedActions = [{
        type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE,
        data: {
          msgText: msgText,
          msgSeverity: msgSeverity
        }
      }];

      // When
      store.dispatch(extensibleViewMessageCallback(msgText, msgSeverity));

      // Then
      expect(store.getActions()).toEqual(expectedActions);
    });

    it('emits action when msgText is blank', () => {
      // Given
      const msgText = "";
      const expectedActions = [{
        type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE

      }];

      // When
      store.dispatch(extensibleViewMessageCallback(msgText, msgSeverity));

      // Then
      expect(store.getActions()).toEqual(expectedActions);
    });
  });

  describe('clearExtensibleViewData', () => {
    it('emits action with payload', () => {
      // Given
      const expectedActions = [{
        type: aaiActionTypes.EXTENSIBLE_VIEW_NETWORK_CALLBACK_CLEAR_DATA,
        data: {}
      }];

      // When
      store.dispatch(clearExtensibleViewData());

      // Then
      expect(store.getActions()).toEqual(expectedActions);
    });
  });

  describe('setSecondaryTitle', () => {
    it('emits action with payload', () => {
      // Given
      const title = "testTitle";
      const expectedActions = [{
        type: aaiActionTypes.SET_SECONDARY_TITLE,
        data: title
      }];

      // When
      store.dispatch(setSecondaryTitle(title));

      // Then
      expect(store.getActions()).toEqual(expectedActions);
    });
  });

});