This repository has been archived by the owner on Feb 19, 2023. It is now read-only.
-
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.
feat(#104): added / improved test cases for main redux code
- Loading branch information
Andreas Gasser
committed
Apr 3, 2019
1 parent
1b0473d
commit 39cd305
Showing
5 changed files
with
138 additions
and
19 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import rootReducer from '../rootReducer'; | ||
|
||
import { | ||
appIdle, | ||
appReset, | ||
__testables__ as applicationTestables, | ||
} from '../application'; | ||
import { | ||
__testables__ as authTestables | ||
} from '../auth'; | ||
|
||
const { applicationDidLoad } = applicationTestables; | ||
const { authSetToken } = authTestables; | ||
|
||
describe('root reducer test suite', () => { | ||
let mockedDateNow; | ||
|
||
beforeAll(() => { | ||
const now = Date.now(); | ||
mockedDateNow = jest.spyOn(Date, 'now').mockImplementation(() => now); | ||
}); | ||
|
||
afterAll(() => { | ||
mockedDateNow.restoreMock(); | ||
}); | ||
|
||
const firstLevelKeys = [ | ||
'appTime', | ||
'application', | ||
'auth', | ||
'images', | ||
'labels', | ||
'faces', | ||
'user', | ||
]; | ||
|
||
it('should return root redux tree', () => { | ||
const rootState = rootReducer(undefined, appIdle()); | ||
expect(Object.keys(rootState)).toEqual(firstLevelKeys); | ||
}); | ||
|
||
it('should reset reducer data on APP_RESET', () => { | ||
// fire some actions to reducer | ||
const rootState1 = rootReducer(undefined, appIdle()); | ||
const rootState2 = rootReducer(rootState1, applicationDidLoad()); | ||
const rootState3 = rootReducer(rootState2, authSetToken('invalid token')); | ||
|
||
// check for non empty redux state | ||
expect(rootState3).not.toEqual(rootReducer(undefined, appIdle)); | ||
|
||
// fire reset and check again | ||
expect(rootReducer(rootState3, appReset())) | ||
.toEqual(rootState1); | ||
}); | ||
}); |
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