2 * ============LICENSE_START=======================================================
\r
3 * SPARKY (AAI UI service)
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property.
\r
6 * Copyright © 2017 Amdocs
\r
7 * All rights reserved.
\r
8 * ================================================================================
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
13 * http://www.apache.org/licenses/LICENSE-2.0
\r
15 * Unless required by applicable law or agreed to in writing, software
\r
16 * distributed under the License is distributed on an "AS IS" BASIS,
\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 * See the License for the specific language governing permissions and
\r
19 * limitations under the License.
\r
20 * ============LICENSE_END=========================================================
\r
22 * ECOMP and OpenECOMP are trademarks
\r
23 * and service marks of AT&T Intellectual Property.
\r
26 import {expect} from 'chai';
\r
27 import React from 'react';
\r
28 import {Provider} from 'react-redux';
\r
29 import TestUtils from 'react-dom/lib/ReactTestUtils';
\r
30 import {tierSupportActionTypes} from 'app/tierSupport/TierSupportConstants.js';
\r
31 import reducer from 'app/tierSupport/autoCompleteSearchBar/AutoCompleteSearchBarReducer.js';
\r
32 import {MESSAGE_LEVEL_WARNING, MESSAGE_LEVEL_DANGER} from 'utils/GlobalConstants.js';
\r
34 autoCompleteSearchBarActionTypes,
\r
36 ERROR_INVALID_SEARCH_TERMS} from 'app/tierSupport/autoCompleteSearchBar/AutoCompleteSearchBarConstants.js';
\r
38 ERROR_RETRIEVING_DATA} from 'app/networking/NetworkConstants.js';
\r
40 describe('AutoCompleteSearchBar - Reducer test ', function() {
\r
42 const testSuggestionData = [
\r
43 {_source:{ entityType: 'vserver',searchTags:'testing'}},
\r
44 {_source:{ entityType: 'vserver',searchTags:'someTag'}},
\r
45 {_source:{ entityType: 'vserver',searchTags:'test2'}}];
\r
47 it('AutoCompleteSearchBar reducer - Suggestion not found', function() {
\r
48 const feedbackMsgText = '';
\r
49 const suggestions = [];
\r
50 const action = {type: autoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND};
\r
51 const initialState = {
\r
52 suggestions: suggestions
\r
55 const newState = reducer(initialState, action);
\r
56 expect(newState.suggestions).to.have.deep.property('[0]._source.entityType', 'No Matches Found');
\r
59 it('AutoCompleteSearchBar reducer - Suggestion found', function() {
\r
60 const feedbackMsgText = '';
\r
63 type: autoCompleteSearchBarActionTypes.SUGGESTION_FOUND,
\r
65 suggestions: testSuggestionData
\r
68 const initialState = {
\r
72 const newState = reducer(initialState, action);
\r
73 expect(newState.suggestions).to.have.deep.property('[0]._source.searchTags', 'testing');
\r
74 expect(newState.suggestions).to.have.deep.property('[1]._source.searchTags', 'someTag');
\r
75 expect(newState.suggestions).to.have.deep.property('[2]._source.searchTags', 'test2');
\r
78 it('AutoCompleteSearchBar reducer - Clear Suggestion field', function() {
\r
79 const feedbackMsgText = '';
\r
80 const action = {type: autoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD, value: 'test'};
\r
81 const initialState = {
\r
82 suggestions: testSuggestionData
\r
85 const newState = reducer(initialState, action);
\r
86 expect(newState.suggestions).to.be.empty;
\r
87 expect(newState.value).to.equal('');
\r
90 it('AutoCompleteSearchBar reducer - Clear Suggestions', function() {
\r
91 const feedbackMsgText = '';
\r
92 const action = {type: autoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS, value: 'test'};
\r
93 const initialState = {
\r
94 suggestions: testSuggestionData
\r
97 const newState = reducer(initialState, action);
\r
98 expect(newState.suggestions).to.be.empty;
\r
101 it('AutoCompleteSearchBar reducer - Suggestions changed', function() {
\r
102 const feedbackMsgText = '';
\r
103 const action = {type: autoCompleteSearchBarActionTypes.SUGGESTION_CHANGED, value: 'test'};
\r
104 const initialState = {
\r
105 suggestions: testSuggestionData
\r
108 const newState = reducer(initialState, action);
\r
109 expect(newState.suggestions).to.have.deep.property('[0]._source.searchTags', 'testing');
\r
110 expect(newState.suggestions).to.have.deep.property('[1]._source.searchTags', 'someTag');
\r
111 expect(newState.suggestions).to.have.deep.property('[2]._source.searchTags', 'test2');
\r
114 it('AutoCompleteSearchBar reducer - Network error', function() {
\r
115 const feedbackMsgText = '';
\r
116 const feedbackMsgSeverity = '';
\r
117 const action = {type: tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR, data: {value: 'test', errorMsg: ERROR_RETRIEVING_DATA}};
\r
118 const initialState = {
\r
119 suggestions: testSuggestionData
\r
122 const newState = reducer(initialState, action);
\r
123 expect(newState.suggestions).to.be.empty;
\r
124 expect(newState.feedbackMsgText).to.equal(ERROR_RETRIEVING_DATA);
\r
125 expect(newState.feedbackMsgSeverity).to.equal(MESSAGE_LEVEL_DANGER);
\r
128 it('AutoCompleteSearchBar reducer - TS_NODE_SEARCH_INVALID_TERMS', function(){
\r
129 const feedbackMsgText = ERROR_INVALID_SEARCH_TERMS;
\r
130 const action = {type: tierSupportActionTypes.TS_NODE_SEARCH_INVALID_TERMS, data: {value: 'test', errorMsg: ERROR_INVALID_SEARCH_TERMS}};
\r
131 const initialState = {
\r
132 suggestions: testSuggestionData
\r
134 const newState = reducer(initialState, action);
\r
135 expect(newState.suggestions).to.be.empty;
\r
136 expect(newState.cachedSuggestions).to.be.empty;
\r
137 expect(newState.feedbackMsgText).to.equal(ERROR_INVALID_SEARCH_TERMS);
\r
138 expect(newState.feedbackMsgSeverity).to.equal(MESSAGE_LEVEL_WARNING);
\r