Add tests to Inventory module
[aai/sparky-fe.git] / test / globalAutoCompleteSearchBar / GlobalAutoCompleteSearchBarReducer.test.js
1 import i18n from 'utils/i18n/i18n';
2 import GlobalAutoCompleteSearchBarReducer from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.js';
3 import {
4   globalAutoCompleteSearchBarActionTypes,
5   NO_MATCHES_FOUND
6 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
7 import {
8   MESSAGE_LEVEL_WARNING,
9   MESSAGE_LEVEL_DANGER
10 } from 'utils/GlobalConstants.js';
11
12 describe('GlobalAutoCompleteSearchBarReducerTests', () => {
13   it('Action Type: SUGGESTION_FOUND', () => {
14     const suggestions = [
15       {
16         entityType: 'some entity type',
17         value: 'selected value'
18       },
19       {
20         entityType: 'some entity type',
21         value: 'other selected value'
22       }
23     ];
24     const errMsg = 'some error message';
25     const action = {
26       type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_FOUND,
27       data: {
28         suggestions: suggestions,
29         errorMsg: errMsg
30       }
31     };
32     let state = {};
33     state = GlobalAutoCompleteSearchBarReducer(state, action);
34     expect(state).toEqual({
35       suggestions: suggestions,
36       cachedSuggestions: suggestions,
37       feedbackMsgText: errMsg,
38       feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
39     });
40   });
41
42   it('Action Type: SUGGESTION_NOT_FOUND', () => {
43     const action = {
44       type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND,
45     };
46     let state = {};
47     state = GlobalAutoCompleteSearchBarReducer(state, action);
48     expect(state).toEqual({
49       suggestions: [{ text: i18n(NO_MATCHES_FOUND)}],
50       cachedSuggestions: [{ entityType: i18n(NO_MATCHES_FOUND)}],
51       feedbackMsgText: '',
52       feedbackMsgSeverity: ''
53     });
54   });
55
56   it('Action Type: CLEAR_SUGGESTIONS_TEXT_FIELD', () => {
57     const action = {
58       type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD,
59     };
60     let state = {};
61     state = GlobalAutoCompleteSearchBarReducer(state, action);
62     expect(state).toEqual({
63       suggestions: [],
64       cachedSuggestions: [],
65       value: '',
66       feedbackMsgText: '',
67       feedbackMsgSeverity: '',
68       clearSearchText: false
69     });
70   });
71
72   it('Action Type: CLEAR_SUGGESTIONS', () => {
73     const action = {
74       type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS,
75     };
76     let state = {};
77     state = GlobalAutoCompleteSearchBarReducer(state, action);
78     expect(state).toEqual({
79       suggestions: []
80     });
81   });
82
83   it('Action Type: SUGGESTION_CHANGED', () => {
84     const suggestionText = 'some suggestion text';
85     const action = {
86       type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CHANGED,
87       data: suggestionText
88     };
89     let state = {};
90     state = GlobalAutoCompleteSearchBarReducer(state, action);
91     expect(state).toEqual({
92       value: suggestionText,
93       feedbackMsgText: '',
94       feedbackMsgSeverity: ''
95     });
96   });
97
98   it('Action Type: SUGGESTION_CLICKED', () => {
99     const suggestion = {
100       entityType: 'some entity type',
101       value: 'selected value'
102     };
103     const action = {
104       type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CLICKED,
105       data: {
106         selectedSuggestion: suggestion
107       }
108     };
109     let state = {};
110     state = GlobalAutoCompleteSearchBarReducer(state, action);
111     expect(state).toEqual({
112       selectedSuggestion: suggestion,
113       performPrepareVisualization: true,
114       feedbackMsgText: '',
115       feedbackMsgSeverity: ''
116     });
117   });
118
119   it('Action Type: NETWORK_ERROR', () => {
120     const errMsg = 'some error message';
121     const action = {
122       type: globalAutoCompleteSearchBarActionTypes.NETWORK_ERROR,
123       data: {
124         errorMsg: errMsg
125       }
126     };
127     let state = {};
128     state = GlobalAutoCompleteSearchBarReducer(state, action);
129     expect(state).toEqual({
130       suggestions: [],
131       cachedSuggestions: [],
132       feedbackMsgText: errMsg,
133       feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
134     });
135   });
136
137   it('Action Type: SEARCH_WARNING_EVENT', () => {
138     const errMsg = 'some error message';
139     const action = {
140       type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT,
141       data: {
142         errorMsg: errMsg
143       }
144     };
145     let state = {};
146     state = GlobalAutoCompleteSearchBarReducer(state, action);
147     expect(state).toEqual({
148       suggestions: [],
149       cachedSuggestions: [],
150       feedbackMsgText: errMsg,
151       feedbackMsgSeverity: MESSAGE_LEVEL_WARNING
152     });
153   });
154 })

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use