forked from magento/pwa-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds unit tests to app reducer (magento#921)
* Adds unit tests to app reducer * Updates tests to be less fragile
- Loading branch information
1 parent
40314b3
commit 8ade70b
Showing
4 changed files
with
87 additions
and
12 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
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import reducer from '../app'; | ||
|
||
const state = { | ||
drawer: null, | ||
hasBeenOffline: false, | ||
isOnline: true, | ||
overlay: false, | ||
pending: {}, | ||
query: '', | ||
searchOpen: false | ||
}; | ||
|
||
test('toggleDrawer sets the overlay flag and the drawer to the action payload', () => { | ||
const action = { | ||
payload: 'cart', | ||
type: 'APP/TOGGLE_DRAWER' | ||
}; | ||
|
||
const result = reducer(state, action); | ||
|
||
expect(result).toHaveProperty('drawer', action.payload); | ||
expect(result).toHaveProperty('overlay', true); | ||
}); | ||
|
||
describe('toggleSearch', () => { | ||
test('toggleSearch flips the searchOpen flag to true', () => { | ||
const action = { | ||
type: 'APP/TOGGLE_SEARCH' | ||
}; | ||
|
||
const result = reducer(state, action); | ||
|
||
expect(result).toHaveProperty('searchOpen', true); | ||
}); | ||
|
||
test('toggleSearch flips the searchOpen flag to false', () => { | ||
const action = { | ||
type: 'APP/TOGGLE_SEARCH' | ||
}; | ||
|
||
const testState = { | ||
...state, | ||
searchOpen: true | ||
}; | ||
|
||
const result = reducer(testState, action); | ||
|
||
expect(result).toHaveProperty('searchOpen', false); | ||
}); | ||
}); | ||
|
||
test('executeSearch sets the query to the action payload', () => { | ||
const action = { | ||
payload: 'unit test', | ||
type: 'APP/EXECUTE_SEARCH' | ||
}; | ||
|
||
const result = reducer(state, action); | ||
|
||
expect(result).toHaveProperty('query', 'unit test'); | ||
}); | ||
|
||
test('setOnline sets the isOnline flag to true', () => { | ||
const action = { | ||
type: 'APP/SET_ONLINE' | ||
}; | ||
|
||
const result = reducer(state, action); | ||
|
||
expect(result).toHaveProperty('isOnline', true); | ||
}); | ||
|
||
test('setOffline sets the isOnline and hasBeenOffline flags appropriately', () => { | ||
const action = { | ||
type: 'APP/SET_OFFLINE' | ||
}; | ||
|
||
const result = reducer(state, action); | ||
|
||
expect(result).toHaveProperty('isOnline', false); | ||
expect(result).toHaveProperty('hasBeenOffline', true); | ||
}); |
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