summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/app/MainScreenWrapperActionHelper.test.js132
-rw-r--r--test/app/configurableViews/ConfigurableViewReducer.test.js32
-rw-r--r--test/app/globalInlineMessageBar/GlobalInlineMessageBarReducer.test.js35
-rw-r--r--test/app/networking/NetworkCalls.test.js51
4 files changed, 229 insertions, 21 deletions
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/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/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);
});
});