summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/app/tierSupport/TierSupportActions.js6
-rw-r--r--test/app/configurableViews/ConfigurableViewReducer.test.js32
-rw-r--r--test/app/tierSupport/TierSupportActions.test.js504
-rw-r--r--test/generic-components/graph/ForceDirectedGraph.test.js11
-rw-r--r--test/generic-components/graph/Link.test.js11
-rw-r--r--test/generic-components/graph/Node.test.js11
-rw-r--r--test/generic-components/inlineMessage/InlineMessage.test.js11
-rw-r--r--test/generic-components/paginatedTable/PaginatedTable.test.js11
-rw-r--r--test/generic-components/titledContainer/TitledContainer.test.js11
9 files changed, 448 insertions, 160 deletions
diff --git a/src/app/tierSupport/TierSupportActions.js b/src/app/tierSupport/TierSupportActions.js
index 08e4e30..69370fa 100644
--- a/src/app/tierSupport/TierSupportActions.js
+++ b/src/app/tierSupport/TierSupportActions.js
@@ -183,8 +183,10 @@ export function querySelectedNodeElement(
}
return dispatch => {
- dispatch(setBusyFeedback());
- dispatch(fetchSelectedNodeElement(selectedNodeFetchRequest));
+ return Promise.all([
+ dispatch(setBusyFeedback()),
+ dispatch(fetchSelectedNodeElement(selectedNodeFetchRequest))
+ ]);
};
}
diff --git a/test/app/configurableViews/ConfigurableViewReducer.test.js b/test/app/configurableViews/ConfigurableViewReducer.test.js
index 0c5c46e..53e8b89 100644
--- a/test/app/configurableViews/ConfigurableViewReducer.test.js
+++ b/test/app/configurableViews/ConfigurableViewReducer.test.js
@@ -4,6 +4,7 @@ import {
import ConfigurableViewReducer from 'app/configurableViews/ConfigurableViewReducer.js'
describe('ConfigurableViewsReducerTests', () => {
it('Action Type: CONFIGURABLE_VIEWS_CONFIG_RECEIVED', () => {
+ // Given
const data = {
viewId: 'someViewId',
viewName: 'Some View Name',
@@ -14,13 +15,18 @@ describe('ConfigurableViewsReducerTests', () => {
data: data
};
let state = {};
+
+ // When
state = ConfigurableViewReducer(state, action);
+
+ // Then
expect(state).toEqual({
configurableViewsConfig: data
});
});
it('Action Type: CUSTOM_COMPONENTS_RECEIVED', () => {
+ // Given
const data = {
componentName: 'someComponentName',
componentData: {
@@ -33,22 +39,46 @@ describe('ConfigurableViewsReducerTests', () => {
data: data
};
let state = {};
+
+ // When
state = ConfigurableViewReducer(state, action);
+
+ // Then
expect(state).toEqual({
customComponents: data
});
});
it('Action Type: CUSTOM_ROUTES', () => {
+ // Given
const data = 'some/custom/route';
const action = {
type: configurableViewsActionTypes.CUSTOM_ROUTES,
data: data
};
let state = {};
+
+ // When
state = ConfigurableViewReducer(state, action);
+
+ // Then
expect(state).toEqual({
customRoutes: data
});
});
-})
+
+ it('Action Type: unknown', () => {
+ // Given
+ const action = {
+ type: "TestUnknownType",
+ data: "TestData"
+ };
+ let state = {};
+
+ // When
+ state = ConfigurableViewReducer(state, action);
+
+ // Then
+ expect(state).toEqual(state);
+ });
+});
diff --git a/test/app/tierSupport/TierSupportActions.test.js b/test/app/tierSupport/TierSupportActions.test.js
index 62485ee..30d3fe9 100644
--- a/test/app/tierSupport/TierSupportActions.test.js
+++ b/test/app/tierSupport/TierSupportActions.test.js
@@ -5,173 +5,363 @@ import {
splitPaneResize,
onNodeMenuChange,
clearVIData,
- setNotificationText
-} from 'app/tierSupport/TierSupportActions.js';
+ setNotificationText,
+ fetchSelectedNodeElement,
+ querySelectedNodeElement
+}
+from 'app/tierSupport/TierSupportActions';
+import {tierSupportActionTypes} from 'app/tierSupport/TierSupportConstants';
+import {MESSAGE_LEVEL_WARNING} from 'utils/GlobalConstants';
+import {globalInlineMessageBarActionTypes} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants';
import {
- tierSupportActionTypes
-} from 'app/tierSupport/TierSupportConstants.js';
-import {
- MESSAGE_LEVEL_WARNING
-} from 'utils/GlobalConstants.js';
-import {
- globalInlineMessageBarActionTypes
-} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants.js';
+ NO_RESULTS_FOUND,
+ ERROR_RETRIEVING_DATA
+} from 'app/networking/NetworkConstants';
+import networkCall from 'app/networking/NetworkCalls';
+
+const mockStore = configureStore([thunk]);
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
- }]);
+ let store;
+
+ beforeEach(() => {
+ store = mockStore({ tierSupportReducer: {} });
});
- 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
- }]);
+ describe('onNodeDetailsChange', () => {
+ it('emits TS_GRAPH_NODE_SELECTED with payload', () => {
+ // Given
+ const newDetails = {
+ testDetails: 'Test Details',
+ };
+ const expectedActions = [{
+ type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
+ data: newDetails
+ }];
+
+ // When
+ store.dispatch(onNodeDetailsChange(newDetails));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
});
- 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
- }]);
+ describe('splitPaneResize', () => {
+ it('emits SPLIT_PANE_RESIZE action with payload', () => {
+ // Given
+ const initialLoad = {
+ test: 'message'
+ };
+ const expectedActions = [{
+ type: tierSupportActionTypes.SPLIT_PANE_RESIZE,
+ data: initialLoad
+ }];
+
+ // When
+ store.dispatch(splitPaneResize(initialLoad));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
});
- 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
- }]);
+ describe('onNodeMenuChange', () => {
+ it('emits TS_GRAPH_NODE_MENU_SELECTED action with payload', () => {
+ // Given
+ const selectedMenu = {
+ test: 'menuData'
+ };
+ const expectedActions = [{
+ type: tierSupportActionTypes.TS_GRAPH_NODE_MENU_SELECTED,
+ data: selectedMenu
+ }];
+
+ // When
+ store.dispatch(onNodeMenuChange(selectedMenu));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
});
- //
- // 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
- }
- }]);
+
+ describe('clearVIData', () => {
+ it('emits TIER_SUPPORT_CLEAR_DATA action', () => {
+ // Given
+ const expectedActions = [{
+ type: tierSupportActionTypes.TIER_SUPPORT_CLEAR_DATA
+ }];
+
+ // When
+ store.dispatch(clearVIData());
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
});
- 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
- }]);
+ describe('fetchSelectedNodeElement', () => {
+ it('emits actions with proper error message when 204 code returned', async () => {
+ // Given
+ const promise = () => getPromiseWithStatusCode(204);
+ const expectedActions = [
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK,
+ },
+ {
+ type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
+ data: {errorMsg: NO_RESULTS_FOUND}
+ }
+ ];
+
+ // When
+ await store.dispatch(fetchSelectedNodeElement(promise));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+
+ it('emits actions with proper error message when 3XX code returned', async () => {
+ // Given
+ const promise = () => getPromiseWithStatusCode(301);
+ const expectedActions = [
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK,
+ },
+ {
+ type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
+ data: {errorMsg: NO_RESULTS_FOUND}
+ }
+ ];
+
+ // When
+ await store.dispatch(fetchSelectedNodeElement(promise));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+
+ it('emits actions with proper error message when 5XX code returned', async () => {
+ // Given
+ const promise = () => getPromiseWithStatusCode(501);
+ const expectedActions = [
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK,
+ },
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_NETWORK_ERROR,
+ data: {value: ERROR_RETRIEVING_DATA, errorMsg: ERROR_RETRIEVING_DATA}
+ }
+ ];
+
+ // When
+ await store.dispatch(fetchSelectedNodeElement(promise));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+
+ it('emits actions with payload when 200 code returned and nodes not empty', async () => {
+ // Given
+ const {nodes, node1} = prepareTestNodes();
+ const promise = () => getNodesPromise(nodes);
+ const expectedActions = [
+ {
+ type: tierSupportActionTypes.TS_NODE_SEARCH_RESULTS,
+ data: {"nodes": nodes}
+ },
+ {
+ type: tierSupportActionTypes.TS_GRAPH_NODE_SELECTED,
+ data: node1
+ },
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK
+ }
+ ];
+
+ // When
+ await store.dispatch(fetchSelectedNodeElement(promise));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+
+ it('emits actions with payload when 200 code returned and nodes empty', async () => {
+ // Given
+ const promise = () => getNodesPromise([]);
+ const expectedActions = [
+ {
+ type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
+ data: {errorMsg: NO_RESULTS_FOUND}
+ },
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK
+ }
+ ];
+
+ // When
+ await store.dispatch(fetchSelectedNodeElement(promise));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
});
-})
+
+ describe('querySelectedNodeElement', () => {
+ const searchHash = "testHash";
+
+ it('emits actions when fetchRequest defined ', async () => {
+ // Given
+ const promise = () => getNodesPromise([]);
+ const expectedAction = [
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_ACTIVATE_BUSY_FEEDBACK,
+ },
+ {
+ type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
+ data: {errorMsg: NO_RESULTS_FOUND}
+ },
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK
+ }
+ ];
+
+ // When
+ await store.dispatch(querySelectedNodeElement(searchHash, promise));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedAction);
+ });
+
+ it('builds request and emits actions when fetchRequest undefined ', async () => {
+ // Given
+ const stringifySpy = jest.spyOn(JSON, 'stringify');
+ const promise = getNodesPromise([]);
+ networkCall.fetchRequestObj = jest.fn(() => promise);
+ const expectedStringifyInput = {
+ hashId: searchHash
+ };
+ const expectedFetchRequestBody = "{\"hashId\":\"testHash\"}";
+ const expectedAction = [
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_ACTIVATE_BUSY_FEEDBACK,
+ },
+ {
+ type: tierSupportActionTypes.TS_NODE_SEARCH_NO_RESULTS,
+ data: {errorMsg: NO_RESULTS_FOUND}
+ },
+ {
+ type: tierSupportActionTypes.TIER_SUPPORT_DISABLE_BUSY_FEEDBACK
+ }
+ ];
+
+ // When
+ await store.dispatch(querySelectedNodeElement(searchHash, undefined));
+
+ // Then
+ expect(stringifySpy).toHaveBeenCalledWith(expectedStringifyInput);
+ expect(networkCall.fetchRequestObj).toHaveBeenCalledWith(
+ expect.anything(),
+ expect.anything(),
+ expect.anything(),
+ expectedFetchRequestBody
+ );
+ expect(store.getActions()).toEqual(expectedAction);
+ });
+ });
+
+ describe('setNotificationText', () => {
+ const msgSeverity = MESSAGE_LEVEL_WARNING;
+
+ it('emits SET_GLOBAL_MESSAGE action with payload when msgText is not blank ', () => {
+ // Given
+ const msgText = 'some test text';
+ const expectedActions = [{
+ type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE,
+ data: {
+ msgText: msgText,
+ msgSeverity: msgSeverity
+ }
+ }];
+
+ // When
+ store.dispatch(setNotificationText(msgText, msgSeverity));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+
+ it('emits CLEAR_GLOBAL_MESSAGE when msgText is blank ', () => {
+ // Given
+ const msgText = '';
+ const expectedActions = [{
+ type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE
+ }];
+
+ // When
+ store.dispatch(setNotificationText(msgText, msgSeverity));
+
+ // Then
+ expect(store.getActions()).toEqual(expectedActions);
+ });
+ });
+
+ function getPromiseWithStatusCode(statusCode) {
+ return new Promise(function(resolve) {
+ resolve({status: statusCode});
+ });
+ }
+
+ function getNodesPromise(nodes) {
+ return new Promise(function (resolve) {
+ resolve({
+ status: 200,
+ json: () => {
+ return {
+ nodes: nodes
+ };
+ }
+ });
+ });
+ }
+
+ function prepareTestNodes() {
+ const node1 = prepareSelectedClassTestNode();
+ const node2 = prepareOtherClassTestNode();
+ return {
+ nodes: [node1, node2],
+ node1,
+ node2
+ }
+ }
+
+ function prepareOtherClassTestNode() {
+ return {
+ id: '3899453d98c5b670952765974876e55ef954e0f8a930b1c',
+ itemType: 'generic-vnf',
+ nodeMeta: {
+ className: 'someOtherClassName',
+ nodeLabel1: 'Artic',
+ nodeValidated: false,
+ nodeLocation: 'bottom'
+ },
+ rootNode: false,
+ index: 1
+ };
+ }
+
+ function prepareSelectedClassTestNode() {
+ return {
+ id: '7352312c7bfa814c3071a803d98c5b670952765974876e55ef954e0f8a930b1c',
+ itemType: 'complex',
+ nodeMeta: {
+ className: 'selectedSearchedNodeClass',
+ nodeLabel1: 'Artic',
+ nodeValidated: false,
+ nodeLocation: 'bottom'
+ },
+ rootNode: false,
+ index: 2
+ };
+ }
+});
diff --git a/test/generic-components/graph/ForceDirectedGraph.test.js b/test/generic-components/graph/ForceDirectedGraph.test.js
new file mode 100644
index 0000000..d73a6cc
--- /dev/null
+++ b/test/generic-components/graph/ForceDirectedGraph.test.js
@@ -0,0 +1,11 @@
+import React from 'react';
+import ForceDirectedGraph from 'generic-components/graph/ForceDirectedGraph.jsx';
+import {shallow} from 'enzyme';
+
+describe('ForceDirectedGraph component', () => {
+ it('should be rendered', () => {
+ const component = shallow(<ForceDirectedGraph dataOverlayButtons="Test"/>);
+
+ expect(component).toHaveLength(1);
+ });
+});
diff --git a/test/generic-components/graph/Link.test.js b/test/generic-components/graph/Link.test.js
new file mode 100644
index 0000000..c030ef3
--- /dev/null
+++ b/test/generic-components/graph/Link.test.js
@@ -0,0 +1,11 @@
+import React from 'react';
+import Link from 'generic-components/graph/Link.jsx';
+import {shallow} from 'enzyme';
+
+describe('Link component', () => {
+ it('should be rendered', () => {
+ const component = shallow(<Link/>);
+
+ expect(component).toHaveLength(1);
+ });
+});
diff --git a/test/generic-components/graph/Node.test.js b/test/generic-components/graph/Node.test.js
new file mode 100644
index 0000000..ed0c84e
--- /dev/null
+++ b/test/generic-components/graph/Node.test.js
@@ -0,0 +1,11 @@
+import React from 'react';
+import Node from 'generic-components/graph/Node.jsx';
+import {shallow} from 'enzyme';
+
+describe('Node component', () => {
+ it('should be rendered', () => {
+ const component = shallow(<Node/>);
+
+ expect(component).toHaveLength(1);
+ });
+});
diff --git a/test/generic-components/inlineMessage/InlineMessage.test.js b/test/generic-components/inlineMessage/InlineMessage.test.js
new file mode 100644
index 0000000..42c28a4
--- /dev/null
+++ b/test/generic-components/inlineMessage/InlineMessage.test.js
@@ -0,0 +1,11 @@
+import React from 'react';
+import InlineMessage from 'generic-components/InlineMessage/InlineMessage.jsx';
+import {shallow} from 'enzyme';
+
+describe('InlineMessage component', () => {
+ it('should be rendered', () => {
+ const component = shallow(<InlineMessage/>);
+
+ expect(component).toHaveLength(1);
+ });
+});
diff --git a/test/generic-components/paginatedTable/PaginatedTable.test.js b/test/generic-components/paginatedTable/PaginatedTable.test.js
new file mode 100644
index 0000000..d3a32b5
--- /dev/null
+++ b/test/generic-components/paginatedTable/PaginatedTable.test.js
@@ -0,0 +1,11 @@
+import React from 'react';
+import PaginatedTable from 'generic-components/paginatedTable/PaginatedTable.jsx';
+import {shallow} from 'enzyme';
+
+describe('PaginatedTable component', () => {
+ it('should be rendered', () => {
+ const component = shallow(<PaginatedTable tableHeaders={{}}/>);
+
+ expect(component).toHaveLength(1);
+ });
+});
diff --git a/test/generic-components/titledContainer/TitledContainer.test.js b/test/generic-components/titledContainer/TitledContainer.test.js
new file mode 100644
index 0000000..a0290b2
--- /dev/null
+++ b/test/generic-components/titledContainer/TitledContainer.test.js
@@ -0,0 +1,11 @@
+import React from 'react';
+import TitledContainer from 'generic-components/titledContainer/TitledContainer.jsx';
+import {shallow} from 'enzyme';
+
+describe('TitledContainer component', () => {
+ it('should be rendered', () => {
+ const component = shallow(<TitledContainer/>);
+
+ expect(component).toHaveLength(1);
+ });
+});