summaryrefslogtreecommitdiffstats
path: root/test/app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.test.js
blob: 1078df6a5fcd106d6964ef2a8a6e3ad8d6d57a14 (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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import i18n from 'utils/i18n/i18n';
import GlobalAutoCompleteSearchBarReducer from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.js';
import {
  globalAutoCompleteSearchBarActionTypes,
  NO_MATCHES_FOUND
} from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js';
import {
  MESSAGE_LEVEL_WARNING,
  MESSAGE_LEVEL_DANGER
} from 'utils/GlobalConstants.js';

describe('GlobalAutoCompleteSearchBarReducerTests', () => {
  it('Action Type: SUGGESTION_FOUND', () => {
    const suggestions = [
      {
        entityType: 'some entity type',
        value: 'selected value'
      },
      {
        entityType: 'some entity type',
        value: 'other selected value'
      }
    ];
    const errMsg = 'some error message';
    const action = {
      type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_FOUND,
      data: {
        suggestions: suggestions,
        errorMsg: errMsg
      }
    };
    let state = {};
    state = GlobalAutoCompleteSearchBarReducer(state, action);
    expect(state).toEqual({
      suggestions: suggestions,
      cachedSuggestions: suggestions,
      feedbackMsgText: errMsg,
      feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
    });
  });

  it('Action Type: SUGGESTION_NOT_FOUND', () => {
    const action = {
      type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND,
    };
    let state = {};
    state = GlobalAutoCompleteSearchBarReducer(state, action);
    expect(state).toEqual({
      suggestions: [{ text: i18n(NO_MATCHES_FOUND)}],
      cachedSuggestions: [{ entityType: i18n(NO_MATCHES_FOUND)}],
      feedbackMsgText: '',
      feedbackMsgSeverity: ''
    });
  });

  it('Action Type: CLEAR_SUGGESTIONS_TEXT_FIELD', () => {
    const action = {
      type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD,
    };
    let state = {};
    state = GlobalAutoCompleteSearchBarReducer(state, action);
    expect(state).toEqual({
      suggestions: [],
      cachedSuggestions: [],
      value: '',
      feedbackMsgText: '',
      feedbackMsgSeverity: '',
      clearSearchText: false
    });
  });

  it('Action Type: CLEAR_SUGGESTIONS', () => {
    const action = {
      type: globalAutoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS,
    };
    let state = {};
    state = GlobalAutoCompleteSearchBarReducer(state, action);
    expect(state).toEqual({
      suggestions: []
    });
  });

  it('Action Type: SUGGESTION_CHANGED', () => {
    const suggestionText = 'some suggestion text';
    const action = {
      type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CHANGED,
      data: suggestionText
    };
    let state = {};
    state = GlobalAutoCompleteSearchBarReducer(state, action);
    expect(state).toEqual({
      value: suggestionText,
      feedbackMsgText: '',
      feedbackMsgSeverity: ''
    });
  });

  it('Action Type: SUGGESTION_CLICKED', () => {
    const suggestion = {
      entityType: 'some entity type',
      value: 'selected value'
    };
    const action = {
      type: globalAutoCompleteSearchBarActionTypes.SUGGESTION_CLICKED,
      data: {
        selectedSuggestion: suggestion
      }
    };
    let state = {};
    state = GlobalAutoCompleteSearchBarReducer(state, action);
    expect(state).toEqual({
      selectedSuggestion: suggestion,
      performPrepareVisualization: true,
      feedbackMsgText: '',
      feedbackMsgSeverity: ''
    });
  });

  it('Action Type: NETWORK_ERROR', () => {
    const errMsg = 'some error message';
    const action = {
      type: globalAutoCompleteSearchBarActionTypes.NETWORK_ERROR,
      data: {
        errorMsg: errMsg
      }
    };
    let state = {};
    state = GlobalAutoCompleteSearchBarReducer(state, action);
    expect(state).toEqual({
      suggestions: [],
      cachedSuggestions: [],
      feedbackMsgText: errMsg,
      feedbackMsgSeverity: MESSAGE_LEVEL_DANGER
    });
  });

  it('Action Type: SEARCH_WARNING_EVENT', () => {
    const errMsg = 'some error message';
    const action = {
      type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT,
      data: {
        errorMsg: errMsg
      }
    };
    let state = {};
    state = GlobalAutoCompleteSearchBarReducer(state, action);
    expect(state).toEqual({
      suggestions: [],
      cachedSuggestions: [],
      feedbackMsgText: errMsg,
      feedbackMsgSeverity: MESSAGE_LEVEL_WARNING
    });
  });
})