Updating versions of Sparky FE files
[aai/sparky-fe.git] / test / tierSupport / autoCompleteSearchBar / autoCompleteSearchBarReducer.test.js
1 /*\r
2  * ============LICENSE_START=======================================================\r
3  * org.onap.aai\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
11  *\r
12  *       http://www.apache.org/licenses/LICENSE-2.0\r
13  *\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
20  *\r
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  */\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/test-utils';\r
27 import {tierSupportActionTypes} from 'app/tierSupport/TierSupportConstants.js';\r
28 import reducer from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.js';\r
29 import {MESSAGE_LEVEL_WARNING, MESSAGE_LEVEL_DANGER} from 'utils/GlobalConstants.js';\r
30 import {\r
31     autoCompleteSearchBarActionTypes,\r
32     NO_MATCHES_FOUND,\r
33     ERROR_INVALID_SEARCH_TERMS} from 'generic-components/autoCompleteSearchBar/AutoCompleteSearchBarConstants.js';\r
34 import {\r
35     ERROR_RETRIEVING_DATA} from 'app/networking/NetworkConstants.js';\r
36 \r
37 describe('AutoCompleteSearchBar - Reducer test ', function() {\r
38 \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
43 \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
50         };\r
51 \r
52         const newState = reducer(initialState, action);\r
53         expect(newState.suggestions).to.have.deep.property('[0]._source.entityType', 'No Matches Found');\r
54     });\r
55 \r
56     it('AutoCompleteSearchBar reducer - Suggestion found', function() {\r
57         const feedbackMsgText = '';\r
58         const action =\r
59             {\r
60                 type: autoCompleteSearchBarActionTypes.SUGGESTION_FOUND,\r
61                 data: {\r
62                     suggestions: testSuggestionData\r
63                 }\r
64             };\r
65         const initialState = {\r
66             suggestions: []\r
67         };\r
68 \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
73     });\r
74 \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
80         };\r
81 \r
82         const newState = reducer(initialState, action);\r
83         expect(newState.suggestions).to.be.empty;\r
84         expect(newState.value).to.equal('');\r
85     });\r
86 \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
92         };\r
93 \r
94         const newState = reducer(initialState, action);\r
95         expect(newState.suggestions).to.be.empty;\r
96     });\r
97 \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
103         };\r
104 \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
109     });\r
110 \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
117         };\r
118 \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
123     });\r
124 \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
130         };\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
136     });\r
137 \r
138 });\r

© 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