This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reducer-layout): update layout reducer and test
- Loading branch information
Showing
2 changed files
with
42 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,60 @@ | ||
import {layout as reducer, initialState} from 'reducers/layout' | ||
import { | ||
UI_CLOSE_SIDEBAR, | ||
UI_OPEN_SIDEBAR, | ||
UI_WINDOW_RESIZE | ||
} from 'actions/layout' | ||
import {UI_TOGGLE_SIDEBAR, UI_WINDOW_RESIZE} from 'actions/layout' | ||
import {LOCATION_CHANGE} from 'actions/common' | ||
|
||
const closeSidebar = { | ||
type: UI_CLOSE_SIDEBAR | ||
} | ||
|
||
const openSidebar = { | ||
type: UI_OPEN_SIDEBAR | ||
const toggleSidebar = { | ||
type: UI_TOGGLE_SIDEBAR | ||
} | ||
|
||
const locationChange = { | ||
type: LOCATION_CHANGE | ||
} | ||
|
||
const windowResize = { | ||
type: UI_WINDOW_RESIZE, | ||
payload: { | ||
innerWidth: 1280 | ||
} | ||
} | ||
|
||
const appInit = { | ||
type: UI_WINDOW_RESIZE, | ||
payload: { | ||
innerWidth: 360 | ||
} | ||
} | ||
const windowResize = (innerWidth) => ({type: UI_WINDOW_RESIZE, payload: {innerWidth}}) | ||
|
||
describe('LAYOUT REDUCER', () => { | ||
it('should return the initial state', () => { | ||
expect(reducer(undefined, {x: 'string'})).toEqual(initialState) | ||
}) | ||
|
||
it('should handle UI_OPEN_SIDEBAR', () => { | ||
expect(reducer(initialState, openSidebar)).toEqual({ | ||
...initialState, | ||
it('should handle UI_TOGGLE_SIDEBAR', () => { | ||
expect( | ||
reducer({innerWidth: 480, sidebarOpened: false}, toggleSidebar) | ||
).toEqual({ | ||
innerWidth: 480, | ||
sidebarOpened: true | ||
}) | ||
}) | ||
|
||
describe('Mobile properties', () => { | ||
describe('Mobile properties WINDOW_RESIZE', () => { | ||
it('should handle WINDOW_RESIZE with 360px screen', () => { | ||
expect(reducer(initialState, appInit)).toEqual({ | ||
...initialState, | ||
isMobile: true, | ||
isMobileXS: true, | ||
isMobileSM: false | ||
expect(reducer(initialState, windowResize(360))).toEqual({ | ||
sidebarOpened: false, | ||
innerWidth: 360 | ||
}) | ||
}) | ||
|
||
it('should handle WINDOW_RESIZE with 1280px screen', () => { | ||
expect(reducer(initialState, windowResize)).toEqual({ | ||
...initialState, | ||
isMobile: false, | ||
isMobileXS: false, | ||
isMobileSM: false | ||
expect(reducer(initialState, windowResize(1280))).toEqual({ | ||
sidebarOpened: true, | ||
innerWidth: 1280 | ||
}) | ||
}) | ||
}) | ||
|
||
it('should handle UI_CLOSE_SIDEBAR', () => { | ||
expect(reducer(initialState, closeSidebar)).toEqual({ | ||
...initialState, | ||
sidebarOpened: false | ||
describe('LOCATION_CHANGE', () => { | ||
it('should close sidebar on mobile after LOCATION_CHANGE', () => { | ||
expect(reducer({sidebarOpened: true, innerWidth: 360}, locationChange)).toEqual({ | ||
innerWidth: 360, | ||
sidebarOpened: false | ||
}) | ||
}) | ||
}) | ||
|
||
it('should handle LOCATION_CHANGE', () => { | ||
expect(reducer(initialState, locationChange)).toEqual({ | ||
...initialState, | ||
sidebarOpened: false | ||
it('should NOT close sidebar on desktop after LOCATION_CHANGE', () => { | ||
expect(reducer({sidebarOpened: true, innerWidth: 993}, locationChange)).toEqual({ | ||
innerWidth: 993, | ||
sidebarOpened: true | ||
}) | ||
}) | ||
}) | ||
}) |