diff options
author | Steven Thomas <steve.thomas@amdocs.com> | 2018-09-13 16:22:40 -0400 |
---|---|---|
committer | Steven Thomas <steve.thomas@amdocs.com> | 2018-09-13 16:23:05 -0400 |
commit | 96319fec0d2af2be5802a56d6b05a3ada939c8df (patch) | |
tree | 630e87f62fbbebcded761bf3e67d0f3eb5b78598 /test | |
parent | d1975c8134f0401b0ccebf3719eda129d53dac14 (diff) |
increasing test coverage to 20 percent
Issue-ID: AAI-1599
Change-Id: I345e38d4319e52b56de0a33d7065e02617cc2103
Signed-off-by: Steven Thomas <steve.thomas@amdocs.com>
Diffstat (limited to 'test')
18 files changed, 1236 insertions, 3 deletions
diff --git a/test/autoCompleteSearchBar/AutoCompleteSearchBar.test.js b/test/autoCompleteSearchBar/AutoCompleteSearchBar.test.js new file mode 100644 index 0000000..7ba3d11 --- /dev/null +++ b/test/autoCompleteSearchBar/AutoCompleteSearchBar.test.js @@ -0,0 +1,40 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import {Provider} from 'react-redux' +import configureStore from 'redux-mock-store'; + +import AutoCompleteSearchBar from 'generic-components/autoCompleteSearchBar/AutoCompleteSearchBar.jsx'; + +describe('AutoCompleteSearchBarTests', () => { + const suggestions = [ + { + text: 'Apple' + }, + { + text: 'Orange' + }, + { + text: 'Banana' + } + ]; + const initialState = { + globalAutoCompleteSearchBarReducer: { + value: '', + suggestions: [], + cachedSuggestions: [], + suggestionName: '' + } + }; + const mockStore = configureStore(); + let store, wrapper; + + beforeEach( () => { + store = mockStore(initialState); + wrapper = shallow(<Provider store={store}><AutoCompleteSearchBar /></Provider>); + }) + + it('render search bar - visible', () => { + expect(wrapper).toHaveLength(1); // ensure the message bar is mounted + expect(wrapper.find(AutoCompleteSearchBar)).toHaveLength(1); // ensure the InlineMessage is mounted + }); +}) diff --git a/test/configurableViews/ConfigurableViewActions.test.js b/test/configurableViews/ConfigurableViewActions.test.js new file mode 100644 index 0000000..9d7bc9e --- /dev/null +++ b/test/configurableViews/ConfigurableViewActions.test.js @@ -0,0 +1,208 @@ +import configureStore from 'redux-mock-store'; +import thunk from 'redux-thunk' +import fetchMock from 'fetch-mock'; +import { + configurableViewsActionTypes +} from 'app/configurableViews/ConfigurableViewConstants.js'; +import { + newCustomComponentsEvent, + setCustomRoutes, + getConfigurableViewConfigs +} from 'app/configurableViews/ConfigurableViewActions.js' + + +describe('ConfigurableViewActionTests', () => { + const sampleConfig = { + "id": "aggregateReport", + "title": "Aggregate Report", + "iconURL": "resources/images/sampleAggReportIcon.svg", + "iconHoverURL": "resources/images/sampleAggReportIconHover.svg", + "viewType": "ConfigurableCardView", + "layout": { + "draggable": true, + "resizable": true, + "rowHeight": 100, + "cardMargin": [ + 20, + 20 + ], + "cardPadding": [ + 20, + 20 + ], + "breakpoints": [ + { + "id": "lg", + "col": 12, + "width": 1400 + }, + { + "id": "md", + "col": 8, + "width": 1200 + }, + { + "id": "sm", + "col": 6, + "width": 1024 + } + ] + }, + "components": [ + { + "id": "visualization1", + "title": "Total VNFs", + "queryData": { + "eventId": "visualization1", + "api": "/get-component-data", + "method": "POST", + "headers": { + "accept": "application/json" + }, + "componentDataDescriptor": { + "index": "aggregate_generic-vnf_index", + "queryType": "aggregation", + "query": { + "filter": {}, + "queries": [], + "aggregations": [ + { + "name": "prov-status", + "aggregation": { + "group-by": { + "field": "prov-status", + "size": 0 + } + } + }, + { + "name": "orchestration-status", + "aggregation": { + "group-by": { + "field": "orchestration-status", + "size": 0 + } + } + }, + { + "name": "nf-type", + "aggregation": { + "group-by": { + "field": "nf-type", + "size": 0 + } + } + }, + { + "name": "nf-role", + "aggregation": { + "group-by": { + "field": "nf-role", + "size": 0 + } + } + } + ] + }, + "responseTransformation": { + "type": "count", + "spec": { + "countType": "total", + "countResponseLabel": "display" + } + } + } + }, + "containerData": { + "containerType": "NetworkQueryCard", + "visualizationType": "text", + "visualizationProp": { + "display": "", + "style": { + "textAlign": "center", + "fontSize": "50px", + "fontWeight": "bold", + "paddingTop": "50px" + } + }, + "breakpoints": { + "lg": { + "w": 2, + "h": 2, + "x": 0, + "y": 0 + }, + "md": { + "w": 2, + "h": 2, + "x": 0, + "y": 0 + }, + "sm": { + "w": 6, + "h": 2, + "x": 0, + "y": 0 + } + } + } + } + ] + }; + + it('newCustomComponentsEvent', () => { + const components = [ + { + compId: 'someId', + compName: 'Some Name' + } + ]; + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({}); + store.dispatch(newCustomComponentsEvent(components)); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: configurableViewsActionTypes.CUSTOM_COMPONENTS_RECEIVED, + data: components + }]); + }); + + it('setCustomRoutes', () => { + const routes = [ + { + routeName: 'Some Custom Route', + path: 'some/route/path' + } + ]; + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({}); + store.dispatch(setCustomRoutes(routes)); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: configurableViewsActionTypes.CUSTOM_ROUTES, + data: routes + }]); + }); + + it('getConfigurableViewConfigs', () => { + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({}); + const expectedActions = [ + { + type: configurableViewsActionTypes.CONFIGURABLE_VIEWS_CONFIG_RECEIVED, + data: sampleConfig + } + ]; + fetchMock.mock('*', sampleConfig); + + return store.dispatch(getConfigurableViewConfigs()) + .then( () => { + const actions = store.getActions(); + expect(actions).toEqual(expectedActions); + fetchMock.restore(); + }); + }); +}) diff --git a/test/configurableViews/ConfigurableViewReducer.test.js b/test/configurableViews/ConfigurableViewReducer.test.js new file mode 100644 index 0000000..0c5c46e --- /dev/null +++ b/test/configurableViews/ConfigurableViewReducer.test.js @@ -0,0 +1,54 @@ +import { + configurableViewsActionTypes +} from 'app/configurableViews/ConfigurableViewConstants.js'; +import ConfigurableViewReducer from 'app/configurableViews/ConfigurableViewReducer.js' +describe('ConfigurableViewsReducerTests', () => { + it('Action Type: CONFIGURABLE_VIEWS_CONFIG_RECEIVED', () => { + const data = { + viewId: 'someViewId', + viewName: 'Some View Name', + viewRoute: 'some/view/route' + }; + const action = { + type: configurableViewsActionTypes.CONFIGURABLE_VIEWS_CONFIG_RECEIVED, + data: data + }; + let state = {}; + state = ConfigurableViewReducer(state, action); + expect(state).toEqual({ + configurableViewsConfig: data + }); + }); + + it('Action Type: CUSTOM_COMPONENTS_RECEIVED', () => { + const data = { + componentName: 'someComponentName', + componentData: { + blah: 'blah', + filler: 'filler' + } + }; + const action = { + type: configurableViewsActionTypes.CUSTOM_COMPONENTS_RECEIVED, + data: data + }; + let state = {}; + state = ConfigurableViewReducer(state, action); + expect(state).toEqual({ + customComponents: data + }); + }); + + it('Action Type: CUSTOM_ROUTES', () => { + const data = 'some/custom/route'; + const action = { + type: configurableViewsActionTypes.CUSTOM_ROUTES, + data: data + }; + let state = {}; + state = ConfigurableViewReducer(state, action); + expect(state).toEqual({ + customRoutes: data + }); + }); +}) diff --git a/test/fileMock.js b/test/fileMock.js new file mode 100644 index 0000000..86059f3 --- /dev/null +++ b/test/fileMock.js @@ -0,0 +1 @@ +module.exports = 'test-file-stub'; diff --git a/test/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBar.test.js b/test/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBar.test.js new file mode 100644 index 0000000..25676b7 --- /dev/null +++ b/test/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBar.test.js @@ -0,0 +1,35 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import {Provider} from 'react-redux' +import configureStore from 'redux-mock-store'; + +import GlobalAutoCompleteSearchBar from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBar.jsx' +import AutoCompleteSearchBar from 'generic-components/autoCompleteSearchBar/AutoCompleteSearchBar.jsx'; +import { + globalAutoCompleteSearchBarActionTypes +} from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js'; + +describe('GlobalAutoCompleteSearchBarTests', () => { + const initValue = 'some random search text'; + const initialState = { + globalAutoCompleteSearchBarReducer: { + value: initValue + } + }; + const mockStore = configureStore(); + let store, wrapper; + + beforeEach( () => { + store = mockStore(initialState); + wrapper = mount(<Provider store={store}><GlobalAutoCompleteSearchBar /></Provider>); + }) + + it('render search bar - visible', () => { + expect(wrapper).toHaveLength(1); // ensure the message bar is mounted + expect(wrapper.find(AutoCompleteSearchBar)).toHaveLength(1); // ensure the InlineMessage is mounted + }); + + it('props assigned properly', () => { + expect(wrapper.find(AutoCompleteSearchBar).props().value).toEqual(initValue); // check that the props match + }) +}) diff --git a/test/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.test.js b/test/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.test.js new file mode 100644 index 0000000..1078df6 --- /dev/null +++ b/test/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarReducer.test.js @@ -0,0 +1,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 + }); + }); +}) diff --git a/test/globalInlineMessageBar/GlobalInlineMessageBar.test.js b/test/globalInlineMessageBar/GlobalInlineMessageBar.test.js new file mode 100644 index 0000000..9dc2a28 --- /dev/null +++ b/test/globalInlineMessageBar/GlobalInlineMessageBar.test.js @@ -0,0 +1,37 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import {Provider} from 'react-redux' +import configureStore from 'redux-mock-store'; + +import GlobalInlineMessageBar from 'app/globalInlineMessageBar/GlobalInlineMessageBar.jsx' +import { + MESSAGE_LEVEL_WARNING +} from 'utils/GlobalConstants.js' +import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx'; + +describe('GlobalInlineMessageBarTests', () => { + const errMsg = 'some random message'; + const initialState = { + globalInlineMessageBar: { + feedbackMsgText: errMsg, + feedbackMsgSeverity: MESSAGE_LEVEL_WARNING + } + }; + const mockStore = configureStore(); + let store, wrapper; + + beforeEach( () => { + store = mockStore(initialState); + wrapper = mount(<Provider store={store}><GlobalInlineMessageBar /></Provider>); + }) + + it('render message bar - visible', () => { + expect(wrapper).toHaveLength(1); // ensure the message bar is mounted + expect(wrapper.find(InlineMessage)).toHaveLength(1); // ensure the InlineMessage is mounted + }); + + it('props assigned properly', () => { + expect(wrapper.find(InlineMessage).props().level).toEqual(MESSAGE_LEVEL_WARNING); // check that the props match + expect(wrapper.find(InlineMessage).props().messageTxt).toEqual(errMsg); // check that the props match + }) +}) diff --git a/test/globalInlineMessageBar/GlobalInlineMessageBarAction.test.js b/test/globalInlineMessageBar/GlobalInlineMessageBarAction.test.js new file mode 100644 index 0000000..4def5ac --- /dev/null +++ b/test/globalInlineMessageBar/GlobalInlineMessageBarAction.test.js @@ -0,0 +1,42 @@ +import configureStore from 'redux-mock-store'; +import thunk from 'redux-thunk'; + +import { + getSetGlobalMessageEvent, + getClearGlobalMessageEvent +} from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions.js'; +import { + globalInlineMessageBarActionTypes +} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants.js'; +import { + MESSAGE_LEVEL_WARNING +} from 'utils/GlobalConstants.js' + +describe('GlobalInlineMessageBarActionTests', () => { + it('getSetGlobalMessageEvent', () => { + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({}); + const msgText = 'some test msg'; + store.dispatch(getSetGlobalMessageEvent(msgText, MESSAGE_LEVEL_WARNING)); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE, + data: { + msgText: msgText, + msgSeverity: MESSAGE_LEVEL_WARNING + } + }]); + }); + + it('getClearGlobalMessageEvent', () => { + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({}); + store.dispatch(getClearGlobalMessageEvent()); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE + }]); + }); +}) diff --git a/test/globalInlineMessageBar/GlobalInlineMessageBarReducer.test.js b/test/globalInlineMessageBar/GlobalInlineMessageBarReducer.test.js new file mode 100644 index 0000000..62389b4 --- /dev/null +++ b/test/globalInlineMessageBar/GlobalInlineMessageBarReducer.test.js @@ -0,0 +1,40 @@ +import GlobalInlineMessageBarReducer from 'app/globalInlineMessageBar/GlobalInlineMessageBarReducer.js'; +import { + globalInlineMessageBarActionTypes +} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants.js'; +import { + MESSAGE_LEVEL_WARNING +} from 'utils/GlobalConstants.js' + +describe('GlobalInlineMessageBarReducerTests', () => { + it('Action Type: SET_GLOBAL_MESSAGE', () => { + const action = { + type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE, + data: { + msgText: 'some error message here', + msgSeverity: MESSAGE_LEVEL_WARNING + } + }; + let state = {}; + state = GlobalInlineMessageBarReducer(state, action); + expect(state).toEqual({ + feedbackMsgText: action.data.msgText, + feedbackMsgSeverity: action.data.msgSeverity + }); + }); + + it('Action Type: CLEAR_GLOBAL_MESSAGE', () => { + const action = { + type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE + }; + let state = { + feedbackMsgText: 'some error message here', + feedbackMsgSeverity: MESSAGE_LEVEL_WARNING + }; + state = GlobalInlineMessageBarReducer(state, action); + expect(state).toEqual({ + feedbackMsgText: '', + feedbackMsgSeverity: '' + }); + }); +}) diff --git a/test/input/SelectInput.test.js b/test/input/SelectInput.test.js new file mode 100644 index 0000000..a669361 --- /dev/null +++ b/test/input/SelectInput.test.js @@ -0,0 +1,13 @@ +import React from 'react'; +import { mount } from 'enzyme'; +import Select from 'react-select'; + +import SelectInput from 'generic-components/input/SelectInput.jsx'; + +describe('SelectInput Tests', () => { + it('render select input - visible', () => { + const select = mount( <SelectInput /> ); + expect(select).toHaveLength(1); // ensure the message bar is mounted + expect(select.find(Select)).toHaveLength(1); // ensure the InlineMessage is mounted + }); +}) diff --git a/test/input/ToggleInput.test.js b/test/input/ToggleInput.test.js new file mode 100644 index 0000000..80f0345 --- /dev/null +++ b/test/input/ToggleInput.test.js @@ -0,0 +1,12 @@ +import React from 'react'; +import { mount } from 'enzyme'; + +import ToggleInput from 'generic-components/input/ToggleInput.jsx'; + +describe('ToggleInput Tests', () => { + it('render toggle input - visible', () => { + const toggle = mount( <ToggleInput /> ); + expect(toggle).toHaveLength(1); // ensure the message bar is mounted + expect(toggle.find('input')).toHaveLength(1); // ensure the InlineMessage is mounted + }); +}) diff --git a/test/setupTests.js b/test/setupTests.js new file mode 100644 index 0000000..2318628 --- /dev/null +++ b/test/setupTests.js @@ -0,0 +1,5 @@ +import { configure } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; +import 'jest-enzyme'; + +configure({ adapter: new Adapter() }); diff --git a/test/styleMock.js b/test/styleMock.js new file mode 100644 index 0000000..f053ebf --- /dev/null +++ b/test/styleMock.js @@ -0,0 +1 @@ +module.exports = {}; diff --git a/test/tierSupport/TierSupportActions.test.js b/test/tierSupport/TierSupportActions.test.js new file mode 100644 index 0000000..62485ee --- /dev/null +++ b/test/tierSupport/TierSupportActions.test.js @@ -0,0 +1,177 @@ +import configureStore from 'redux-mock-store'; +import thunk from 'redux-thunk' +import { + onNodeDetailsChange, + splitPaneResize, + onNodeMenuChange, + clearVIData, + setNotificationText +} from 'app/tierSupport/TierSupportActions.js'; +import { + tierSupportActionTypes +} from 'app/tierSupport/TierSupportConstants.js'; +import { + MESSAGE_LEVEL_WARNING +} from 'utils/GlobalConstants.js'; +import { + globalInlineMessageBarActionTypes +} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants.js'; + +describe('TierSupportActionTests', () => { + it('onNodeDetailsChange', () => { + const newDetails = { + id: '7352312c7bfa814c3071a803d98c5b670952765974876e55ef954e0f8a930b1c', + itemType: 'complex', + nodeMeta: { + nodeLabel1: 'Artic', + nodeValidated: false, + nodeLocation: 'bottom' + }, + rootNode: false, + index: 2, + }; + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({ tierSupportReducer: {} }); + store.dispatch(onNodeDetailsChange(newDetails)); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED, + data: newDetails + }]); + }); + + it('splitPaneResize', () => { + const initialLoad = { + test: 'message' + }; + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({ tierSupportReducer: {} }); + store.dispatch(splitPaneResize(initialLoad)); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: tierSupportActionTypes.SPLIT_PANE_RESIZE, + data: initialLoad + }]); + }); + + it('onNodeMenuChange', () => { + const selectedMenu = { + test: 'menuData' + }; + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({ tierSupportReducer: {} }); + store.dispatch(onNodeMenuChange(selectedMenu)); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: tierSupportActionTypes.TS_GRAPH_NODE_MENU_SELECTED, + data: selectedMenu + }]); + }); + + it('clearVIData', () => { + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({ tierSupportReducer: {} }); + store.dispatch(clearVIData()); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA + }]); + }); + // + // it('fetchSelectedNodeElement - no results', () => { + // const middlewares = [thunk]; + // const mockStore = configureStore(middlewares); + // const store = mockStore({ tierSupportReducer: {} }); + // const nodes = [ + // { + // id: '7352312c7bfa814c3071a803d98c5b670952765974876e55ef954e0f8a930b1c', + // itemType: 'complex', + // nodeMeta: { + // className: 'selectedSearchedNodeClass', + // nodeLabel1: 'Artic', + // nodeValidated: false, + // nodeLocation: 'bottom' + // }, + // rootNode: false, + // index: 2 + // }, + // { + // id: '3899453d98c5b670952765974876e55ef954e0f8a930b1c', + // itemType: 'generic-vnf', + // nodeMeta: { + // className: 'someOtherClassName', + // nodeLabel1: 'Artic', + // nodeValidated: false, + // nodeLocation: 'bottom' + // }, + // rootNode: false, + // index: 1 + // } + // ]; + // const expectedActions = [ + // { + // type: tierSupportActionTypes.TS_NODE_SEARCH_RESULTS, + // data: { + // nodes: nodes + // } + // }, + // { + // type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED, + // data: nodes[0] + // } + // ]; + // + // console.log(nodes); + // + // let fetchRequestCallback = () => { + // const results = { + // nodes: nodes + // }; + // let init = { status: 200 }; + // let myBlob = new Blob(); + // let response = new Response(); + // return new Promise((resolve, reject) => { + // resolve(response); + // }); + // }; + // return store.dispatch(fetchSelectedNodeElement(fetchRequestCallback)) + // .then( () => { + // const actions = store.getActions(); + // expect(actions).toEqual(expectedActions); + // }); + // }); + + it('setNotificationText', () => { + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({ tierSupportReducer: {} }); + const msgText = 'some test text'; + const msgSeverity = MESSAGE_LEVEL_WARNING; + store.dispatch(setNotificationText(msgText, msgSeverity)); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE, + data: { + msgText: msgText, + msgSeverity: msgSeverity + } + }]); + }); + + it('Clear notification text with setNotificationText', () => { + const middlewares = [thunk]; + const mockStore = configureStore(middlewares); + const store = mockStore({ tierSupportReducer: {} }); + const msgText = ''; + const msgSeverity = MESSAGE_LEVEL_WARNING; + store.dispatch(setNotificationText(msgText, msgSeverity)); + const actions = store.getActions(); + expect(actions).toEqual([{ + type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE + }]); + }); +}) diff --git a/test/tierSupport/TierSupportReducer.test.js b/test/tierSupport/TierSupportReducer.test.js new file mode 100644 index 0000000..9825a06 --- /dev/null +++ b/test/tierSupport/TierSupportReducer.test.js @@ -0,0 +1,206 @@ +import TierSupportReducer from 'app/tierSupport/TierSupportReducer.js'; +import ForceDirectedGraph from 'generic-components/graph/ForceDirectedGraph.jsx'; +import { + tierSupportActionTypes, + TSUI_GRAPH_MENU_NODE_DETAILS +} from 'app/tierSupport/TierSupportConstants.js'; +import { + MESSAGE_LEVEL_WARNING, + MESSAGE_LEVEL_DANGER +} from 'utils/GlobalConstants.js'; +import { + globalAutoCompleteSearchBarActionTypes +} from 'app/globalAutoCompleteSearchBar/GlobalAutoCompleteSearchBarConstants.js'; + +describe('TierSupportReducerTests', () => { + it('Action Type: TS_NODE_SEARCH_RESULTS', () => { + ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests + const action = { + type: tierSupportActionTypes.TS_NODE_SEARCH_RESULTS, + data: { + nodes: [ + { + nodeMeta: { + searchTarget: true + }, + itemProperties: 'someProperty' + } + ], + links: ['link', 'information'], + graphMeta: { graph: 'meta' } + } + }; + let graphData = ForceDirectedGraph.generateNewProps(action.data.nodes, action.data.links, + action.data.graphMeta); + ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous statement + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + forceDirectedGraphRawData: graphData, + feedbackMsgText: '', + feedbackMsgSeverity: '' + }); + }); + + it('Action Type: TS_GRAPH_NODE_MENU_SELECTED', () => { + const action = { + type: tierSupportActionTypes.TS_GRAPH_NODE_MENU_SELECTED, + data: { + attr1: 'someValue', + attr2: 'someOterValue' + } + }; + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + graphNodeSelectedMenu: action.data + }); + }); + + it('Action Type: TS_NODE_SEARCH_NO_RESULTS', () => { + ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests + let emptyNodesAndLinksNoResults = { + graphCounter: 1, + graphMeta: {}, + linkDataArray: [], + nodeDataArray: [] + }; + const action = { + type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS, + data: { + errorMsg: 'some error message' + } + }; + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + forceDirectedGraphRawData: emptyNodesAndLinksNoResults, + graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS, + feedbackMsgText: action.data.errorMsg, + feedbackMsgSeverity: MESSAGE_LEVEL_WARNING + }); + }); + + it('Action Type: TIER_SUPPORT_NETWORK_ERROR', () => { + ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests + let emptyNodesAndLinksNoResults = { + graphCounter: 1, + graphMeta: {}, + linkDataArray: [], + nodeDataArray: [] + }; + const action = { + type: tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR, + data: { + errorMsg: 'some error message' + } + }; + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + forceDirectedGraphRawData: emptyNodesAndLinksNoResults, + graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS, + feedbackMsgText: action.data.errorMsg, + feedbackMsgSeverity: MESSAGE_LEVEL_DANGER + }); + }); + + it('Action Type: TIER_SUPPORT_CLEAR_DATA', () => { + ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests + let emptyNodesAndLinksNoResults = { + graphCounter: 1, + graphMeta: {}, + linkDataArray: [], + nodeDataArray: [] + }; + const action = { + type: tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA + }; + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + forceDirectedGraphRawData: emptyNodesAndLinksNoResults, + graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS, + feedbackMsgText: '', + feedbackMsgSeverity: '' + }); + }); + + it('Action Type: TS_GRAPH_NODE_SELECTED', () => { + const action = { + type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED, + data: 'some action data' + }; + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + nodeData: action.data + }); + }); + + it('Action Type: TIER_SUPPORT_ACTIVATE_BUSY_FEEDBACK', () => { + const action = { + type: tierSupportActionTypes.TIER_SUPPORT_ACTIVATE_BUSY_FEEDBACK, + }; + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + enableBusyFeedback: true + }); + }); + + it('Action Type: TIER_SUPPORT_DISABLE_BUSY_FEEDBACK', () => { + const action = { + type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK, + }; + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + enableBusyFeedback: false + }); + }); + + it('Action Type: SEARCH_WARNING_EVENT', () => { + ForceDirectedGraph.graphCounter = 0; // ensuring counter is at zero after previous tests + let emptyNodesAndLinksNoResults = { + graphCounter: 1, + graphMeta: {}, + linkDataArray: [], + nodeDataArray: [] + }; + const action = { + type: globalAutoCompleteSearchBarActionTypes.SEARCH_WARNING_EVENT, + data: { + errorMsg: 'some warning msg' + } + }; + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + forceDirectedGraphRawData: emptyNodesAndLinksNoResults, + graphNodeSelectedMenu: TSUI_GRAPH_MENU_NODE_DETAILS + }); + }); + + it('Action Type: TS_OVERLAY_NETWORK_CALLBACK_RESPONSE_RECEIVED', () => { + const action = { + type: tierSupportActionTypes.TS_OVERLAY_NETWORK_CALLBACK_RESPONSE_RECEIVED, + data: { + curData: { + attr1: 'value1', + attr2: 'value2' + }, + paramName: 'attr2', + overlayData: 'someValue2' + } + }; + let state = {}; + state = TierSupportReducer(state, action); + expect(state.tierSupportReducer).toEqual({ + nodeData: { + attr1: 'value1', + attr2: 'someValue2' + } + }); + }); +}) diff --git a/test/utils/KeyMirror.test.js b/test/utils/KeyMirror.test.js new file mode 100644 index 0000000..22f6ff5 --- /dev/null +++ b/test/utils/KeyMirror.test.js @@ -0,0 +1,79 @@ +import keyMirror from 'utils/KeyMirror.js'; + +describe('KeyMirror', () => { + it('valid key mirror with nulls', () => { + const obj = { + TIER_SUPPORT: null, + INVENTORY: null, + VNF_SEARCH: null + } + const mirror = keyMirror(obj); + + for (let key in obj) { + expect(mirror).toHaveProperty(key); + expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(Symbol(key))); + } + }); + + it('valid key mirror with undefined', () => { + const obj = { + TIER_SUPPORT: undefined, + INVENTORY: undefined, + VNF_SEARCH: undefined + } + const mirror = keyMirror(obj); + + for (let key in obj) { + expect(mirror).toHaveProperty(key); + expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(Symbol(key))); + } + }); + + it('valid key mirror with values', () => { + let preMirrorList = { + TIER_SUPPORT: 'tier support', + INVENTORY: 'inventory', + VNF_SEARCH: 'vnf search' + }; + const mirror = keyMirror(preMirrorList); + + for (let key in preMirrorList) { + expect(mirror).toHaveProperty(key); + expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(preMirrorList[key])); + } + }); + + it('valid key mirror with objects', () => { + let preMirrorList = { + TIER_SUPPORT: { + name: 'tier support' + }, + INVENTORY: { + name: 'inventory' + }, + VNF_SEARCH: { + name: 'vnf search' + } + }; + const mirror = keyMirror(preMirrorList); + + for (let key in preMirrorList) { + expect(mirror).toHaveProperty(key); + expect(JSON.stringify(mirror[key])).toBe(JSON.stringify(preMirrorList[key])); + } + }); + + it('invalid key mirror', () => { + let preMirrorList = [ + 'tier support', + 'inventory', + 'vnf search' + ] + const mirror = () => { + keyMirror(preMirrorList); + } + + expect(mirror).toThrow(Error); + expect(mirror).toThrowError('keyMirror(...): Argument must be an object.'); + }); +}) diff --git a/test/utils/Routes.test.js b/test/utils/Routes.test.js new file mode 100644 index 0000000..12d318c --- /dev/null +++ b/test/utils/Routes.test.js @@ -0,0 +1,129 @@ +import { + buildRouteObjWithHash, + decryptParamsForView, + buildRouteObjWithFilters, + changeUrlAddress +} from 'utils/Routes.js'; +import { + encrypt +} from 'utils/Crypto.js'; + +describe('Routes', () => { + it('build route with hash', () => { + const expectedResult = { + route: '/vnfSearch', + hashId: 'someCrazyHashHere' + }; + + const result = buildRouteObjWithHash(expectedResult.route, expectedResult.hashId); + + expect(JSON.stringify(result)).toBe(JSON.stringify(expectedResult)); + }); + + it('decrypt params for view', () => { + const stringToEncrypt = 'someCrazyStringHere'; + const encryptedString = encrypt(stringToEncrypt); + const result = decryptParamsForView(encryptedString); + + expect(JSON.stringify(result)).toBe(JSON.stringify({})); + }); + + it('decrypt params for view with obj', () => { + const objToEncrypt = [{id: 'someCrazyParamHere'}, {id: 'anotherCrazyParam'}]; + const encryptedObj = encrypt(JSON.stringify(objToEncrypt)); + const result = decryptParamsForView(encryptedObj); + + expect(JSON.stringify(result)).toBe(JSON.stringify(objToEncrypt)); + }); + + it('build routes with filters', () => { + const objToEncrypt = [{id: 'someCrazyParamHere'}, {id: 'anotherCrazyParam'}]; + const encryptedObj = encrypt(JSON.stringify(objToEncrypt)); + const result = decryptParamsForView(encryptedObj); + + expect(JSON.stringify(result)).toBe(JSON.stringify(objToEncrypt)); + const filterObj = { + filter1: 'value1', + filter2: undefined, + filter3: 'anotherValue' + }; + const routePath = '/vnfSearch'; + const expectedResults = { + route: routePath, + filterValues: [ + { + filterId: 'filter1', + filterValue: 'value1' + }, + { + filterId: 'filter2', + filterValue: '' + }, + { + filterId: 'filter3', + filterValue: 'anotherValue' + } + ] + } + + const routeWithFilters = buildRouteObjWithFilters(routePath, filterObj); + + expect(JSON.stringify(routeWithFilters)).toBe(JSON.stringify(expectedResults)); + }); + + it('change URL address for well known paths', () => { + const pathObj = { + route: 'schema', + filterValues: [ + { + filterId: 'filter1', + filterValue: 'value1' + }, + { + filterId: 'filter2', + filterValue: undefined + }, + { + filterId: 'filter3', + filterValue: 'anotherValue' + } + ] + }; + let historyObj = []; + const filterList = [ + 'filter1=value1', + 'filter2=', + 'filter3=anotherValue' + ]; + const toGo = '/' + pathObj.route + '/' + filterList.toString(); + const expectedResult = [ + toGo, + { + lastRoute: pathObj.route + } + ]; + + changeUrlAddress(pathObj, historyObj); + + expect(JSON.stringify(historyObj)).toBe(JSON.stringify(expectedResult)); + }); + + it('change URL address for well known paths with hash id', () => { + const pathObj = { + route: 'schema', + hashId: 'someCrazyHashIdHere' + }; + let historyObj = []; + const toGo = '/' + pathObj.route + '/' + pathObj.hashId; + const expectedResult = [ + toGo, + { + lastRoute: pathObj.route + } + ]; + + changeUrlAddress(pathObj, historyObj); + + expect(JSON.stringify(historyObj)).toBe(JSON.stringify(expectedResult)); + }); +}) diff --git a/test/utils/SpinnerContainer.test.js b/test/utils/SpinnerContainer.test.js index 90c7cf5..f9c01e2 100644 --- a/test/utils/SpinnerContainer.test.js +++ b/test/utils/SpinnerContainer.test.js @@ -17,8 +17,8 @@ describe('SpinnerContainer', () => { expect(spinner.find(ClipLoader)).toHaveLength(1); // ensure the ClipLoader is mounted expect(spinner.find(ClipLoader).props().color).toEqual(COLOR_BLUE); // ensure spinner is blue expect(spinner.find(ClipLoader).props().loading).toEqual(true); // ensure spinner is showing - expect(spinner.find('div.spinner-content')).toHaveLength(1); // ensure the children are grayed out - expect(spinner.find('div.spinner-content').children()).toHaveLength(2); // ensure number of children is accurate + expect(spinner.find('div.spin-content')).toHaveLength(1); // ensure the children are grayed out + expect(spinner.find('div.spin-content').children()).toHaveLength(2); // ensure number of children is accurate }); it('render spinner - not visible', () => { @@ -30,6 +30,6 @@ describe('SpinnerContainer', () => { expect(spinner.props().loading).toEqual(false); expect(spinner.find(ClipLoader)).toHaveLength(1); expect(spinner.find(ClipLoader).props().loading).toEqual(false); // ensure spinner is not showing - expect(spinner.find('div.spinner-content')).toHaveLength(0); + expect(spinner.find('div.spin-content')).toHaveLength(0); }); }) |