1 import i18n from 'utils/i18n/i18n';
2 import GlobalAutoCompleteSearchBarReducer from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.js';
4 globalAutoCompleteSearchBarActionTypes,
6 } from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
10 } from 'utils/GlobalConstants.js';
12 describe('GlobalAutoCompleteSearchBarReducerTests', () => {
13 it('Action Type: SUGGESTION_FOUND', () => {
16 entityType: 'some entity type',
17 value: 'selected value'
20 entityType: 'some entity type',
21 value: 'other selected value'
24 const errMsg = 'some error message';
26 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_FOUND,
28 suggestions: suggestions,
33 state = GlobalAutoCompleteSearchBarReducer(state, action);
34 expect(state).toEqual({
35 suggestions: suggestions,
36 cachedSuggestions: suggestions,
37 feedbackMsgText: errMsg,
38 feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
42 it('Action Type: SUGGESTION_NOT_FOUND', () => {
44 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND,
47 state = GlobalAutoCompleteSearchBarReducer(state, action);
48 expect(state).toEqual({
49 suggestions: [{ text: i18n(NO_MATCHES_FOUND)}],
50 cachedSuggestions: [{ entityType: i18n(NO_MATCHES_FOUND)}],
52 feedbackMsgSeverity: ''
56 it('Action Type: CLEAR_SUGGESTIONS_TEXT_FIELD', () => {
58 type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD,
61 state = GlobalAutoCompleteSearchBarReducer(state, action);
62 expect(state).toEqual({
64 cachedSuggestions: [],
67 feedbackMsgSeverity: '',
68 clearSearchText: false
72 it('Action Type: CLEAR_SUGGESTIONS', () => {
74 type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS,
77 state = GlobalAutoCompleteSearchBarReducer(state, action);
78 expect(state).toEqual({
83 it('Action Type: SUGGESTION_CHANGED', () => {
84 const suggestionText = 'some suggestion text';
86 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CHANGED,
90 state = GlobalAutoCompleteSearchBarReducer(state, action);
91 expect(state).toEqual({
92 value: suggestionText,
94 feedbackMsgSeverity: ''
98 it('Action Type: SUGGESTION_CLICKED', () => {
100 entityType: 'some entity type',
101 value: 'selected value'
104 type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CLICKED,
106 selectedSuggestion: suggestion
110 state = GlobalAutoCompleteSearchBarReducer(state, action);
111 expect(state).toEqual({
112 selectedSuggestion: suggestion,
113 performPrepareVisualization: true,
115 feedbackMsgSeverity: ''
119 it('Action Type: NETWORK_ERROR', () => {
120 const errMsg = 'some error message';
122 type: globalAutoCompleteSearchBarActionTypes.NETWORK_ERROR,
128 state = GlobalAutoCompleteSearchBarReducer(state, action);
129 expect(state).toEqual({
131 cachedSuggestions: [],
132 feedbackMsgText: errMsg,
133 feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
137 it('Action Type: SEARCH_WARNING_EVENT', () => {
138 const errMsg = 'some error message';
140 type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT,
146 state = GlobalAutoCompleteSearchBarReducer(state, action);
147 expect(state).toEqual({
149 cachedSuggestions: [],
150 feedbackMsgText: errMsg,
151 feedbackMsgSeverity: MESSAGE_LEVEL_WARNING