2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * Copyright © 2017 Amdocs
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
19 * ============LICENSE_END=========================================================
\r
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 import {expect} from 'chai';
\r
24 import React from 'react';
\r
25 import {Provider} from 'react-redux';
\r
26 import TestUtils from 'react-dom/lib/ReactTestUtils';
\r
27 import {tierSupportActionTypes} from 'app/tierSupport/TierSupportConstants.js';
\r
28 import reducer from 'app/tierSupport/autoCompleteSearchBar/AutoCompleteSearchBarReducer.js';
\r
29 import {MESSAGE_LEVEL_WARNING, MESSAGE_LEVEL_DANGER} from 'utils/GlobalConstants.js';
\r
31 autoCompleteSearchBarActionTypes,
\r
33 ERROR_INVALID_SEARCH_TERMS} from 'app/tierSupport/autoCompleteSearchBar/AutoCompleteSearchBarConstants.js';
\r
35 ERROR_RETRIEVING_DATA} from 'app/networking/NetworkConstants.js';
\r
37 describe('AutoCompleteSearchBar - Reducer test ', function() {
\r
39 const testSuggestionData = [
\r
40 {_source:{ entityType: 'vserver',searchTags:'testing'}},
\r
41 {_source:{ entityType: 'vserver',searchTags:'someTag'}},
\r
42 {_source:{ entityType: 'vserver',searchTags:'test2'}}];
\r
44 it('AutoCompleteSearchBar reducer - Suggestion not found', function() {
\r
45 const feedbackMsgText = '';
\r
46 const suggestions = [];
\r
47 const action = {type: autoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND};
\r
48 const initialState = {
\r
49 suggestions: suggestions
\r
52 const newState = reducer(initialState, action);
\r
53 expect(newState.suggestions).to.have.deep.property('[0]._source.entityType', 'No Matches Found');
\r
56 it('AutoCompleteSearchBar reducer - Suggestion found', function() {
\r
57 const feedbackMsgText = '';
\r
60 type: autoCompleteSearchBarActionTypes.SUGGESTION_FOUND,
\r
62 suggestions: testSuggestionData
\r
65 const initialState = {
\r
69 const newState = reducer(initialState, action);
\r
70 expect(newState.suggestions).to.have.deep.property('[0]._source.searchTags', 'testing');
\r
71 expect(newState.suggestions).to.have.deep.property('[1]._source.searchTags', 'someTag');
\r
72 expect(newState.suggestions).to.have.deep.property('[2]._source.searchTags', 'test2');
\r
75 it('AutoCompleteSearchBar reducer - Clear Suggestion field', function() {
\r
76 const feedbackMsgText = '';
\r
77 const action = {type: autoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD, value: 'test'};
\r
78 const initialState = {
\r
79 suggestions: testSuggestionData
\r
82 const newState = reducer(initialState, action);
\r
83 expect(newState.suggestions).to.be.empty;
\r
84 expect(newState.value).to.equal('');
\r
87 it('AutoCompleteSearchBar reducer - Clear Suggestions', function() {
\r
88 const feedbackMsgText = '';
\r
89 const action = {type: autoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS, value: 'test'};
\r
90 const initialState = {
\r
91 suggestions: testSuggestionData
\r
94 const newState = reducer(initialState, action);
\r
95 expect(newState.suggestions).to.be.empty;
\r
98 it('AutoCompleteSearchBar reducer - Suggestions changed', function() {
\r
99 const feedbackMsgText = '';
\r
100 const action = {type: autoCompleteSearchBarActionTypes.SUGGESTION_CHANGED, value: 'test'};
\r
101 const initialState = {
\r
102 suggestions: testSuggestionData
\r
105 const newState = reducer(initialState, action);
\r
106 expect(newState.suggestions).to.have.deep.property('[0]._source.searchTags', 'testing');
\r
107 expect(newState.suggestions).to.have.deep.property('[1]._source.searchTags', 'someTag');
\r
108 expect(newState.suggestions).to.have.deep.property('[2]._source.searchTags', 'test2');
\r
111 it('AutoCompleteSearchBar reducer - Network error', function() {
\r
112 const feedbackMsgText = '';
\r
113 const feedbackMsgSeverity = '';
\r
114 const action = {type: tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR, data: {value: 'test', errorMsg: ERROR_RETRIEVING_DATA}};
\r
115 const initialState = {
\r
116 suggestions: testSuggestionData
\r
119 const newState = reducer(initialState, action);
\r
120 expect(newState.suggestions).to.be.empty;
\r
121 expect(newState.feedbackMsgText).to.equal(ERROR_RETRIEVING_DATA);
\r
122 expect(newState.feedbackMsgSeverity).to.equal(MESSAGE_LEVEL_DANGER);
\r
125 it('AutoCompleteSearchBar reducer - TS_NODE_SEARCH_INVALID_TERMS', function(){
\r
126 const feedbackMsgText = ERROR_INVALID_SEARCH_TERMS;
\r
127 const action = {type: tierSupportActionTypes.TS_NODE_SEARCH_INVALID_TERMS, data: {value: 'test', errorMsg: ERROR_INVALID_SEARCH_TERMS}};
\r
128 const initialState = {
\r
129 suggestions: testSuggestionData
\r
131 const newState = reducer(initialState, action);
\r
132 expect(newState.suggestions).to.be.empty;
\r
133 expect(newState.cachedSuggestions).to.be.empty;
\r
134 expect(newState.feedbackMsgText).to.equal(ERROR_INVALID_SEARCH_TERMS);
\r
135 expect(newState.feedbackMsgSeverity).to.equal(MESSAGE_LEVEL_WARNING);
\r