summaryrefslogtreecommitdiffstats
path: root/test/generic-components/notifications/NotificationReducer.test.js
diff options
context:
space:
mode:
authorJames Forsyth <jf2512@att.com>2018-09-25 12:46:32 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-25 12:46:32 +0000
commit71b5923e74bd75f8fbfd610d23f94fdc013513da (patch)
treed72042a5a92aa0fc505b31bda067d7e19bca7696 /test/generic-components/notifications/NotificationReducer.test.js
parent63ebf4328b260219308587a040fc5a2ab6b5b9d8 (diff)
parent7eed2ed1366bece336b0d2e28ac8b3d4526964df (diff)
Merge "Add tests to notifications module"
Diffstat (limited to 'test/generic-components/notifications/NotificationReducer.test.js')
-rw-r--r--test/generic-components/notifications/NotificationReducer.test.js197
1 files changed, 197 insertions, 0 deletions
diff --git a/test/generic-components/notifications/NotificationReducer.test.js b/test/generic-components/notifications/NotificationReducer.test.js
new file mode 100644
index 0000000..40d6b05
--- /dev/null
+++ b/test/generic-components/notifications/NotificationReducer.test.js
@@ -0,0 +1,197 @@
+import NotificationReducer from 'generic-components/notifications/NotificationReducer';
+import NotificationConstants from "generic-components/notifications/NotificationConstants";
+
+
+describe('NotificationReducer', () => {
+ const defaultState = {
+ type: 'default',
+ title: 'some default title',
+ msg: 'some default message',
+ timeout: 1
+ };
+
+ it('Should return default state when action type is not supported', () => {
+ // given
+ const unsupportedAction = {
+ type: undefined
+ };
+
+ // when
+ const actualState = NotificationReducer(defaultState, unsupportedAction);
+
+ // then
+ expect(actualState).toEqual(defaultState);
+ });
+
+ it('Should return state with type default when action type is info', () => {
+ // given
+ const expectedState = {
+ type: 'default',
+ title: 'some title',
+ msg: 'some message',
+ timeout: 5
+ };
+
+ const infoAction = {
+ type: NotificationConstants.NOTIFY_INFO,
+ data: {
+ title: "some title",
+ msg: "some message",
+ timeout: 5
+ }
+ };
+
+ // when
+ const actualState = NotificationReducer(defaultState, infoAction);
+
+ // then
+ expect(actualState).toEqual(expectedState);
+ });
+
+
+ it('Should return status with type success when action type is success', () => {
+ // given
+ const expectedState = {
+ type: 'success',
+ title: 'some title',
+ msg: 'some message',
+ timeout: 2
+ };
+
+ const infoAction = {
+ type: NotificationConstants.NOTIFY_SUCCESS,
+ data: {
+ title: "some title",
+ msg: "some message",
+ timeout: 2
+ }
+ };
+
+ // when
+ const actualState = NotificationReducer(defaultState, infoAction);
+
+ // then
+ expect(actualState).toEqual(expectedState);
+ });
+
+ it('Should return status with type success when action type is success', () => {
+ // given
+ const expectedState = {
+ type: 'success',
+ title: 'some title',
+ msg: 'some message',
+ timeout: 2
+ };
+
+ const infoAction = {
+ type: NotificationConstants.NOTIFY_SUCCESS,
+ data: {
+ title: "some title",
+ msg: "some message",
+ timeout: 2
+ }
+ };
+
+ // when
+ const actualState = NotificationReducer(defaultState, infoAction);
+
+ // then
+ expect(actualState).toEqual(expectedState);
+ });
+
+ it('Should return status with type error when action type is error', () => {
+ // given
+ const expectedState = {
+ type: 'error',
+ title: 'some title',
+ msg: 'some message',
+ timeout: 2
+ };
+
+ const infoAction = {
+ type: NotificationConstants.NOTIFY_ERROR,
+ data: {
+ title: "some title",
+ msg: "some message",
+ timeout: 2
+ }
+ };
+
+ // when
+ const actualState = NotificationReducer(defaultState, infoAction);
+
+ // then
+ expect(actualState).toEqual(expectedState);
+ });
+
+ it('Should return status with type error when action type is error', () => {
+ // given
+ const expectedState = {
+ type: 'error',
+ title: 'some title',
+ msg: 'some message',
+ timeout: 2
+ };
+
+ const infoAction = {
+ type: NotificationConstants.NOTIFY_ERROR,
+ data: {
+ title: "some title",
+ msg: "some message",
+ timeout: 2
+ }
+ };
+
+ // when
+ const actualState = NotificationReducer(defaultState, infoAction);
+
+ // then
+ expect(actualState).toEqual(expectedState);
+ });
+
+ it('Should return status with type warning when action type is warning', () => {
+ // given
+ const expectedState = {
+ type: 'warning',
+ title: 'some title',
+ msg: 'some message',
+ timeout: 2
+ };
+
+ const infoAction = {
+ type: NotificationConstants.NOTIFY_WARNING,
+ data: {
+ title: "some title",
+ msg: "some message",
+ timeout: 2
+ }
+ };
+
+ // when
+ const actualState = NotificationReducer(defaultState, infoAction);
+
+ // then
+ expect(actualState).toEqual(expectedState);
+ });
+
+ it('Should return null when action type is close', () => {
+ // given
+ const expectedState = null;
+
+ const infoAction = {
+ type: NotificationConstants.NOTIFY_CLOSE,
+ data: {
+ title: "some title",
+ msg: "some message",
+ timeout: 2
+ }
+ };
+
+ // when
+ const actualState = NotificationReducer(defaultState, infoAction);
+
+ // then
+ expect(actualState).toEqual(expectedState);
+ });
+
+});