From 94d82fd0a5deea03d93885ca1a20127476f62fab Mon Sep 17 00:00:00 2001 From: Vladimir Metnev Date: Mon, 16 Oct 2017 18:26:07 +0300 Subject: [PATCH] fix(reducers): fix reducers layout/links/auth tests fix(reducers): fix reducers layout/links/auth tests --- src/common/reducers/auth/index.test.js | 3 - src/common/reducers/layout/index.test.js | 4 +- src/common/reducers/links/index.test.js | 87 +++++------------------- 3 files changed, 19 insertions(+), 75 deletions(-) diff --git a/src/common/reducers/auth/index.test.js b/src/common/reducers/auth/index.test.js index 6aa4c22d..2d0948d2 100644 --- a/src/common/reducers/auth/index.test.js +++ b/src/common/reducers/auth/index.test.js @@ -56,7 +56,6 @@ describe('AUTH REDUCER', () => { // User is logged out after LOGOUT_AUTH_SUCCESS expect(reducer(loggedInState, logoutSuccess)).toEqual({ ...loggedInState, - token: null, errors: {}, isLoggedIn: false, isLoading: false, @@ -71,7 +70,6 @@ describe('AUTH REDUCER', () => { isLoggedIn: false, isLoaded: true, isLoading: false, - token: null, errors: loginFail.payload.errors }) }) @@ -80,7 +78,6 @@ describe('AUTH REDUCER', () => { // User is logged in and has `token` after LOGIN_AUTH_SUCCESS expect(reducer(initialState, loginSuccess)).toEqual({ ...initialState, - token: loginSuccess.payload.token, isLoaded: true, isLoading: false, isLoggedIn: true diff --git a/src/common/reducers/layout/index.test.js b/src/common/reducers/layout/index.test.js index 3890dc5f..bd0705ab 100644 --- a/src/common/reducers/layout/index.test.js +++ b/src/common/reducers/layout/index.test.js @@ -26,7 +26,7 @@ const windowResize = { } const appInit = { - type: APPLICATION_INIT, + type: UI_WINDOW_RESIZE, payload: { innerWidth: 360 } @@ -45,7 +45,7 @@ describe('LAYOUT REDUCER', () => { }) describe('Mobile properties', () => { - it('should handle APPLICATION_INIT with 360px screen', () => { + it('should handle WINDOW_RESIZE with 360px screen', () => { expect(reducer(initialState, appInit)).toEqual({ ...initialState, isMobile: true, diff --git a/src/common/reducers/links/index.test.js b/src/common/reducers/links/index.test.js index 6707b6a5..6c1b2bc8 100644 --- a/src/common/reducers/links/index.test.js +++ b/src/common/reducers/links/index.test.js @@ -1,13 +1,12 @@ -import {users as reducer, initialState} from 'reducers/users' +import {links as reducer, initialState} from 'reducers/links' import { - GET_USERS_FAIL, - GET_USERS_SUCCESS, - GET_USERS_PENDING -} from 'actions/users' -import {LOCATION_CHANGE} from 'actions/common' + GET_LINKS_SUCCESS, + GET_LINKS_FAIL, + GET_LINKS_PENDING +} from 'actions/links' const fail = { - type: GET_USERS_FAIL, + type: GET_LINKS_FAIL, payload: { errors: { hmm: 'thatsanerror' @@ -15,70 +14,34 @@ const fail = { } } -const sampleUserItem = { - id: 1, - name: 'Leanne Graham', - username: 'Bret', - email: 'Sincere@april.biz', - address: { - street: 'Kulas Light', - suite: 'Apt. 556', - city: 'Gwenborough', - zipcode: '92998-3874', - geo: { - lat: '-37.3159', - lng: '81.1496' - } - }, - phone: '1-770-736-8031 x56442', - website: 'hildegard.org', - company: { - name: 'Romaguera-Crona', - catchPhrase: 'Multi-layered client-server neural-net', - bs: 'harness real-time e-markets' - } +const samplePayloadItem = { + item: 'payload' } const success = { - type: GET_USERS_SUCCESS, - payload: sampleUserItem -} -const pending = { - type: GET_USERS_PENDING -} - -const locationChangeToInboxId = { - type: LOCATION_CHANGE, - payload: { - pathname: '/users/1' - } + type: GET_LINKS_SUCCESS, + payload: samplePayloadItem } -const locationChangeDashboard = { - type: LOCATION_CHANGE, - payload: { - pathname: '/' - } +const pending = { + type: GET_LINKS_PENDING } -describe('USERS REDUCER', () => { +describe('LINKS REDUCER', () => { it('should return the initial state', () => { expect(reducer(undefined, {x: 'string'})).toEqual(initialState) }) - it('should handle GET_USERS_SUCCESS', () => { + it('should handle GET_LINKS_SUCCESS', () => { expect(reducer(initialState, success)).toEqual({ ...initialState, - entities: { - '1': sampleUserItem - }, - count: 1, + entities: samplePayloadItem, isLoaded: true, isLoading: false }) }) - it('should handle GET_USERS_FAIL', () => { + it('should handle GET_LINKS_FAIL', () => { expect(reducer(initialState, fail)).toEqual({ ...initialState, errors: { @@ -89,7 +52,7 @@ describe('USERS REDUCER', () => { }) }) - it('should handle GET_USERS_PENDING', () => { + it('should handle GET_LINKS_PENDING', () => { expect(reducer(initialState, pending)).toEqual({ ...initialState, errors: {}, @@ -97,20 +60,4 @@ describe('USERS REDUCER', () => { isLoading: true }) }) - - it('should return same state if LOCATION_CHANGE navigates to /users/:id', () => { - const customState = { - ...initialState, - hello: 'world' - } - expect(reducer(customState, locationChangeToInboxId)).toEqual(customState) - }) - - it('should handle LOCATION_CHANGE to not /users path', () => { - const customState = { - ...initialState, - hello: 'world' - } - expect(reducer(customState, locationChangeDashboard)).toEqual(initialState) - }) })