summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/app/tierSupport/TierSupportActions.test.js504
1 files changed, 347 insertions, 157 deletions
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
+ };
+ }
+});