Initial coomit for AAI-UI(sparky-fe)
[aai/sparky-fe.git] / test / tierSupport / autoCompleteSearchBar / autoCompleteSearchBarReducer.test.js
diff --git a/test/tierSupport/autoCompleteSearchBar/autoCompleteSearchBarReducer.test.js b/test/tierSupport/autoCompleteSearchBar/autoCompleteSearchBarReducer.test.js
new file mode 100644 (file)
index 0000000..f3f1c19
--- /dev/null
@@ -0,0 +1,141 @@
+/*\r
+ * ============LICENSE_START=======================================================\r
+ * SPARKY (AAI UI service)\r
+ * ================================================================================\r
+ * Copyright © 2017 AT&T Intellectual Property.\r
+ * Copyright © 2017 Amdocs\r
+ * All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *      http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ *\r
+ * ECOMP and OpenECOMP are trademarks\r
+ * and service marks of AT&T Intellectual Property.\r
+ */\r
+\r
+import {expect} from 'chai';\r
+import React from 'react';\r
+import {Provider} from 'react-redux';\r
+import TestUtils from 'react-dom/lib/ReactTestUtils';\r
+import {tierSupportActionTypes} from 'app/tierSupport/TierSupportConstants.js';\r
+import reducer from 'app/tierSupport/autoCompleteSearchBar/AutoCompleteSearchBarReducer.js';\r
+import {MESSAGE_LEVEL_WARNING, MESSAGE_LEVEL_DANGER} from 'utils/GlobalConstants.js';\r
+import {\r
+    autoCompleteSearchBarActionTypes,\r
+    NO_MATCHES_FOUND,\r
+    ERROR_INVALID_SEARCH_TERMS} from 'app/tierSupport/autoCompleteSearchBar/AutoCompleteSearchBarConstants.js';\r
+import {\r
+    ERROR_RETRIEVING_DATA} from 'app/networking/NetworkConstants.js';\r
+\r
+describe('AutoCompleteSearchBar - Reducer test ', function() {\r
+\r
+    const testSuggestionData = [\r
+        {_source:{ entityType: 'vserver',searchTags:'testing'}},\r
+        {_source:{ entityType: 'vserver',searchTags:'someTag'}},\r
+        {_source:{ entityType: 'vserver',searchTags:'test2'}}];\r
+\r
+    it('AutoCompleteSearchBar reducer - Suggestion not found', function() {\r
+        const feedbackMsgText = '';\r
+        const suggestions = [];\r
+        const action = {type: autoCompleteSearchBarActionTypes.SUGGESTION_NOT_FOUND};\r
+        const initialState = {\r
+            suggestions: suggestions\r
+        };\r
+\r
+        const newState = reducer(initialState, action);\r
+        expect(newState.suggestions).to.have.deep.property('[0]._source.entityType', 'No Matches Found');\r
+    });\r
+\r
+    it('AutoCompleteSearchBar reducer - Suggestion found', function() {\r
+        const feedbackMsgText = '';\r
+        const action =\r
+            {\r
+                type: autoCompleteSearchBarActionTypes.SUGGESTION_FOUND,\r
+                data: {\r
+                    suggestions: testSuggestionData\r
+                }\r
+            };\r
+        const initialState = {\r
+            suggestions: []\r
+        };\r
+\r
+        const newState = reducer(initialState, action);\r
+        expect(newState.suggestions).to.have.deep.property('[0]._source.searchTags', 'testing');\r
+        expect(newState.suggestions).to.have.deep.property('[1]._source.searchTags', 'someTag');\r
+        expect(newState.suggestions).to.have.deep.property('[2]._source.searchTags', 'test2');\r
+    });\r
+\r
+    it('AutoCompleteSearchBar reducer - Clear Suggestion field', function() {\r
+        const feedbackMsgText = '';\r
+        const action = {type: autoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS_TEXT_FIELD, value: 'test'};\r
+        const initialState = {\r
+            suggestions: testSuggestionData\r
+        };\r
+\r
+        const newState = reducer(initialState, action);\r
+        expect(newState.suggestions).to.be.empty;\r
+        expect(newState.value).to.equal('');\r
+    });\r
+\r
+    it('AutoCompleteSearchBar reducer - Clear Suggestions', function() {\r
+        const feedbackMsgText = '';\r
+        const action = {type: autoCompleteSearchBarActionTypes.CLEAR_SUGGESTIONS, value: 'test'};\r
+        const initialState = {\r
+            suggestions: testSuggestionData\r
+        };\r
+\r
+        const newState = reducer(initialState, action);\r
+        expect(newState.suggestions).to.be.empty;\r
+    });\r
+\r
+    it('AutoCompleteSearchBar reducer - Suggestions changed', function() {\r
+        const feedbackMsgText = '';\r
+        const action = {type: autoCompleteSearchBarActionTypes.SUGGESTION_CHANGED, value: 'test'};\r
+        const initialState = {\r
+            suggestions: testSuggestionData\r
+        };\r
+\r
+        const newState = reducer(initialState, action);\r
+        expect(newState.suggestions).to.have.deep.property('[0]._source.searchTags', 'testing');\r
+        expect(newState.suggestions).to.have.deep.property('[1]._source.searchTags', 'someTag');\r
+        expect(newState.suggestions).to.have.deep.property('[2]._source.searchTags', 'test2');\r
+    });\r
+\r
+    it('AutoCompleteSearchBar reducer - Network error', function() {\r
+        const feedbackMsgText = '';\r
+        const feedbackMsgSeverity = '';\r
+        const action = {type: tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR, data: {value: 'test', errorMsg: ERROR_RETRIEVING_DATA}};\r
+        const initialState = {\r
+            suggestions: testSuggestionData\r
+        };\r
+\r
+        const newState = reducer(initialState, action);\r
+        expect(newState.suggestions).to.be.empty;\r
+        expect(newState.feedbackMsgText).to.equal(ERROR_RETRIEVING_DATA);\r
+        expect(newState.feedbackMsgSeverity).to.equal(MESSAGE_LEVEL_DANGER);\r
+    });\r
+\r
+    it('AutoCompleteSearchBar reducer - TS_NODE_SEARCH_INVALID_TERMS', function(){\r
+        const feedbackMsgText = ERROR_INVALID_SEARCH_TERMS;\r
+        const action = {type: tierSupportActionTypes.TS_NODE_SEARCH_INVALID_TERMS, data: {value: 'test', errorMsg: ERROR_INVALID_SEARCH_TERMS}};\r
+        const initialState = {\r
+            suggestions: testSuggestionData\r
+        };\r
+        const newState = reducer(initialState, action);\r
+        expect(newState.suggestions).to.be.empty;\r
+        expect(newState.cachedSuggestions).to.be.empty;\r
+        expect(newState.feedbackMsgText).to.equal(ERROR_INVALID_SEARCH_TERMS);\r
+        expect(newState.feedbackMsgSeverity).to.equal(MESSAGE_LEVEL_WARNING);\r
+    });\r
+\r
+});\r