From: James Forsyth Date: Thu, 15 Aug 2019 13:55:13 +0000 (+0000) Subject: Merge "ConfigurableViewReducer test" X-Git-Tag: 6.0.0-ONAP~3 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fsparky-fe.git;a=commitdiff_plain;h=a2b37b8015cfaf44bf5714770ec8fb456424ec14;hp=117972dc1b72e33b15c4b1c04788bb46014d96c9 Merge "ConfigurableViewReducer test" --- diff --git a/package.json b/package.json index 2b8334a..ef4d259 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "redux": "^3.3.1", "redux-form": "^6.2.1", "redux-thunk": "^2.1.0", + "sinon": "^7.3.1", "topojson": "^2.2.0", "uuid-js": "^0.7.5", "validator": "^4.3.0", diff --git a/pom.xml b/pom.xml index 422b04f..725d77f 100644 --- a/pom.xml +++ b/pom.xml @@ -23,10 +23,15 @@ 4.0.0 + + org.onap.oparent + oparent + 2.0.0 + org.onap.aai sparky-fe war - 1.4.0-SNAPSHOT + 1.5.1-SNAPSHOT aai-sparky-fe http://maven.apache.org @@ -88,6 +93,14 @@ npm generate-resources + + + install -ddd + + gulp build @@ -104,15 +117,8 @@ - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.7 - true - - ${nexusproxy} - 176c31dfe190a - ecomp-staging - + org.apache.maven.plugins + maven-deploy-plugin diff --git a/test/app/MainScreenWrapperActionHelper.test.js b/test/app/MainScreenWrapperActionHelper.test.js new file mode 100644 index 0000000..011010e --- /dev/null +++ b/test/app/MainScreenWrapperActionHelper.test.js @@ -0,0 +1,132 @@ +import configureStore from 'redux-mock-store'; +import thunk from 'redux-thunk' +import { + windowResize, + showMainMenu, + extensibleViewMessageCallback, + clearExtensibleViewData, + setSecondaryTitle +} from 'app/MainScreenWrapperActionHelper'; +import { + getSetGlobalMessageEvent, + getClearGlobalMessageEvent +} from 'app/globalInlineMessageBar/GlobalInlineMessageBarActions'; +import { + globalInlineMessageBarActionTypes +} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants'; +import {aaiActionTypes} from 'app/MainScreenWrapperConstants'; + +const mockStore = configureStore([thunk]); + +describe('MainScreenWrapperActionHelper', () => { + let store; + + beforeEach(() => { + store = mockStore({ tierSupportReducer: {} }); + }); + + describe('windowResize', () => { + it('emits action', () => { + // Given + const expectedActions = [{ + type: aaiActionTypes.AAI_WINDOW_RESIZE + }]; + + // When + store.dispatch(windowResize()); + + // Then + expect(store.getActions()).toEqual(expectedActions); + }); + }); + + describe('showMainMenu', () => { + it('emits action with payload', () => { + // Given + const input = "testInput"; + const expectedActions = [{ + type: aaiActionTypes.AAI_SHOW_MENU, + data: { + showMenu: input + } + }]; + + // When + store.dispatch(showMainMenu(input)); + + // Then + expect(store.getActions()).toEqual(expectedActions); + }); + }); + + describe('extensibleViewMessageCallback', () => { + const msgSeverity = "msgSeverity"; + + it('emits action with payload when msgText is not blank', () => { + // Given + const msgText = "msgText"; + const expectedActions = [{ + type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE, + data: { + msgText: msgText, + msgSeverity: msgSeverity + } + }]; + + // When + store.dispatch(extensibleViewMessageCallback(msgText, msgSeverity)); + + // Then + expect(store.getActions()).toEqual(expectedActions); + }); + + it('emits action when msgText is blank', () => { + // Given + const msgText = ""; + const expectedActions = [{ + type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE + + }]; + + // When + store.dispatch(extensibleViewMessageCallback(msgText, msgSeverity)); + + // Then + expect(store.getActions()).toEqual(expectedActions); + }); + }); + + describe('clearExtensibleViewData', () => { + it('emits action with payload', () => { + // Given + const expectedActions = [{ + type: aaiActionTypes.EXTENSIBLE_VIEW_NETWORK_CALLBACK_CLEAR_DATA, + data: {} + }]; + + // When + store.dispatch(clearExtensibleViewData()); + + // Then + expect(store.getActions()).toEqual(expectedActions); + }); + }); + + describe('setSecondaryTitle', () => { + it('emits action with payload', () => { + // Given + const title = "testTitle"; + const expectedActions = [{ + type: aaiActionTypes.SET_SECONDARY_TITLE, + data: title + }]; + + // When + store.dispatch(setSecondaryTitle(title)); + + // Then + expect(store.getActions()).toEqual(expectedActions); + }); + }); + +}); diff --git a/test/app/globalInlineMessageBar/GlobalInlineMessageBarReducer.test.js b/test/app/globalInlineMessageBar/GlobalInlineMessageBarReducer.test.js index 62389b4..bbcb7c1 100644 --- a/test/app/globalInlineMessageBar/GlobalInlineMessageBarReducer.test.js +++ b/test/app/globalInlineMessageBar/GlobalInlineMessageBarReducer.test.js @@ -1,13 +1,14 @@ -import GlobalInlineMessageBarReducer from 'app/globalInlineMessageBar/GlobalInlineMessageBarReducer.js'; +import GlobalInlineMessageBarReducer from 'app/globalInlineMessageBar/GlobalInlineMessageBarReducer'; import { globalInlineMessageBarActionTypes -} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants.js'; +} from 'app/globalInlineMessageBar/GlobalInlineMessageBarConstants'; import { MESSAGE_LEVEL_WARNING -} from 'utils/GlobalConstants.js' +} from 'utils/GlobalConstants' describe('GlobalInlineMessageBarReducerTests', () => { it('Action Type: SET_GLOBAL_MESSAGE', () => { + // Given const action = { type: globalInlineMessageBarActionTypes.SET_GLOBAL_MESSAGE, data: { @@ -16,7 +17,11 @@ describe('GlobalInlineMessageBarReducerTests', () => { } }; let state = {}; + + // When state = GlobalInlineMessageBarReducer(state, action); + + // Then expect(state).toEqual({ feedbackMsgText: action.data.msgText, feedbackMsgSeverity: action.data.msgSeverity @@ -24,6 +29,7 @@ describe('GlobalInlineMessageBarReducerTests', () => { }); it('Action Type: CLEAR_GLOBAL_MESSAGE', () => { + // Given const action = { type: globalInlineMessageBarActionTypes.CLEAR_GLOBAL_MESSAGE }; @@ -31,10 +37,31 @@ describe('GlobalInlineMessageBarReducerTests', () => { feedbackMsgText: 'some error message here', feedbackMsgSeverity: MESSAGE_LEVEL_WARNING }; + + // When state = GlobalInlineMessageBarReducer(state, action); + + // Then expect(state).toEqual({ feedbackMsgText: '', feedbackMsgSeverity: '' }); }); -}) + + it('Action Type: unknown', () => { + // Given + const action = { + type: "TestUnknownType" + }; + const initialState = { + feedbackMsgText: 'some error message here', + feedbackMsgSeverity: MESSAGE_LEVEL_WARNING + }; + + // When + const newState = GlobalInlineMessageBarReducer(initialState, action); + + // Then + expect(newState).toEqual(initialState); + }); +}); diff --git a/test/app/networking/NetworkCalls.test.js b/test/app/networking/NetworkCalls.test.js index 373fbac..a3b6176 100644 --- a/test/app/networking/NetworkCalls.test.js +++ b/test/app/networking/NetworkCalls.test.js @@ -90,34 +90,53 @@ describe("Network Utils", () => { describe('#getRequest', () => { it("should fetch any request", () => { - const json = suite.sandbox.stub(); - const fetchPromise = Promise.resolve({json}); - global.fetch = suite.sandbox.stub(); - - global.fetch - .withArgs('URL', { - credentials: 'same-origin', - method: 'GET' - }) - .returns(fetchPromise); - - NetworkCalls.getRequest("URL", "GET"); - - return fetchPromise.then(() => { - sinon.assert.calledOnce(json); - }); + // given + global.fetch = suite.sandbox.stub(); + const json = suite.sandbox.stub(); + const url = "localhost"; + + global.fetch + .withArgs(url, { + credentials: 'same-origin', + method: 'GET' + }) + .returns(json); + + // when + const request = NetworkCalls.getRequest(url, "GET"); + + //then + expect(request).toBe(json) + sinon.assert.calledOnce(global.fetch); }); }); describe('#genericRequest', () => { it('should fetch any generic request', () => { + // given global.fetch = suite.sandbox.stub(); const then = suite.sandbox.stub(); fetch.returns({then}); + + // when NetworkCalls.genericRequest("localhost", "/relativeUrl", "GET"); + // then expect(then.firstCall.args[0]({json: () => "d"})).toEqual("d"); + sinon.assert.calledOnce(fetch); + }); + it('should fetch any generic request - non relative', () => { + // given + global.fetch = suite.sandbox.stub(); + const then = suite.sandbox.stub(); + fetch.returns({then}); + + // when + NetworkCalls.genericRequest("localhost", false, "GET"); + + // then + expect(then.firstCall.args[0]({json: () => "d"})).toEqual("d"); sinon.assert.calledOnce(fetch); }); }); diff --git a/version.properties b/version.properties index 66827fd..4814eb2 100644 --- a/version.properties +++ b/version.properties @@ -4,8 +4,8 @@ # because they are used in Jenkins, whose plug-in doesn't support major_version=1 -minor_version=4 -patch_version=0 +minor_version=5 +patch_version=1 base_version=${major_version}.${minor_version}.${patch_version}