Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
fix(reducers): fix reducers layout/links/auth tests
Browse files Browse the repository at this point in the history
fix(reducers): fix reducers layout/links/auth tests
  • Loading branch information
Metnew committed Oct 16, 2017
1 parent e39d11d commit 94d82fd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 75 deletions.
3 changes: 0 additions & 3 deletions src/common/reducers/auth/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -71,7 +70,6 @@ describe('AUTH REDUCER', () => {
isLoggedIn: false,
isLoaded: true,
isLoading: false,
token: null,
errors: loginFail.payload.errors
})
})
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/common/reducers/layout/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const windowResize = {
}

const appInit = {
type: APPLICATION_INIT,
type: UI_WINDOW_RESIZE,
payload: {
innerWidth: 360
}
Expand All @@ -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,
Expand Down
87 changes: 17 additions & 70 deletions src/common/reducers/links/index.test.js
Original file line number Diff line number Diff line change
@@ -1,84 +1,47 @@
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'
}
}
}

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: {
Expand All @@ -89,28 +52,12 @@ describe('USERS REDUCER', () => {
})
})

it('should handle GET_USERS_PENDING', () => {
it('should handle GET_LINKS_PENDING', () => {
expect(reducer(initialState, pending)).toEqual({
...initialState,
errors: {},
isLoaded: false,
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)
})
})

0 comments on commit 94d82fd

Please sign in to comment.