Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expand test coverage and CI reporting
- Loading branch information
Showing
9 changed files
with
281 additions
and
32 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
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
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
189 changes: 189 additions & 0 deletions
189
packages/redux-pauseable-store/tests/getStateMultiple.ts
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,189 @@ | ||
/* eslint-env jest */ | ||
// import '@testing-library/jest-dom/extend-expect'; | ||
import { Store } from 'redux'; | ||
|
||
import { createDevHelperStore, incrementAction } from 'react-hibernate-dev-helpers'; | ||
|
||
import { createPauseableStore, PauseableStoreInstance } from '../src'; | ||
|
||
describe('getState with a chain of multiple parent stores', () => { | ||
let rootStore: Store; | ||
let grandparentStore: PauseableStoreInstance; | ||
let parentStore: PauseableStoreInstance; | ||
beforeEach(() => { | ||
rootStore = createDevHelperStore(); | ||
grandparentStore = createPauseableStore(rootStore); | ||
parentStore = createPauseableStore(grandparentStore); | ||
}); | ||
|
||
it('creates a pauseableStore', () => { | ||
const myStore = createPauseableStore(parentStore); | ||
|
||
expect(myStore.getState()).toEqual({ | ||
count: 0, | ||
}); | ||
}); | ||
|
||
it('updates when not paused', () => { | ||
const myStore = createPauseableStore(parentStore); | ||
|
||
rootStore.dispatch(incrementAction()); | ||
expect(myStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
|
||
rootStore.dispatch(incrementAction()); | ||
expect(myStore.getState()).toEqual({ | ||
count: 2, | ||
}); | ||
}); | ||
|
||
it('does not update when paused', () => { | ||
const myStore = createPauseableStore(rootStore, { | ||
isPaused: true, | ||
}); | ||
|
||
rootStore.dispatch(incrementAction()); | ||
expect(myStore.getState()).toEqual({ | ||
count: 0, | ||
}); | ||
|
||
rootStore.dispatch(incrementAction()); | ||
expect(myStore.getState()).toEqual({ | ||
count: 0, | ||
}); | ||
}); | ||
|
||
it('stops updates at grandparent when grandparent paused', () => { | ||
const myStore = createPauseableStore(parentStore); | ||
|
||
rootStore.dispatch(incrementAction()); | ||
expect(myStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
|
||
grandparentStore.setPaused(true); | ||
|
||
rootStore.dispatch(incrementAction()); | ||
rootStore.dispatch(incrementAction()); | ||
|
||
expect(rootStore.getState()).toEqual({ | ||
count: 3, | ||
}); | ||
expect(grandparentStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
expect(parentStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
expect(myStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
}); | ||
|
||
it('stops updates at parent when parent paused', () => { | ||
const myStore = createPauseableStore(parentStore); | ||
|
||
rootStore.dispatch(incrementAction()); | ||
expect(myStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
|
||
parentStore.setPaused(true); | ||
|
||
rootStore.dispatch(incrementAction()); | ||
rootStore.dispatch(incrementAction()); | ||
|
||
expect(rootStore.getState()).toEqual({ | ||
count: 3, | ||
}); | ||
expect(grandparentStore.getState()).toEqual({ | ||
count: 3, | ||
}); | ||
expect(parentStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
expect(myStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
}); | ||
|
||
it('receives latest state properly when ancestors pause and unpause', () => { | ||
const myStore = createPauseableStore(parentStore); | ||
|
||
rootStore.dispatch(incrementAction()); | ||
expect(myStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
|
||
parentStore.setPaused(true); | ||
rootStore.dispatch(incrementAction()); | ||
|
||
expect(rootStore.getState()).toEqual({ | ||
count: 2, | ||
}); | ||
expect(grandparentStore.getState()).toEqual({ | ||
count: 2, | ||
}); | ||
expect(parentStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
expect(myStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
|
||
grandparentStore.setPaused(true); | ||
rootStore.dispatch(incrementAction()); | ||
|
||
expect(rootStore.getState()).toEqual({ | ||
count: 3, | ||
}); | ||
expect(grandparentStore.getState()).toEqual({ | ||
count: 2, | ||
}); | ||
expect(parentStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
expect(myStore.getState()).toEqual({ | ||
count: 1, | ||
}); | ||
|
||
parentStore.setPaused(false); | ||
rootStore.dispatch(incrementAction()); | ||
|
||
expect(rootStore.getState()).toEqual({ | ||
count: 4, | ||
}); | ||
expect(grandparentStore.getState()).toEqual({ | ||
count: 2, | ||
}); | ||
expect(parentStore.getState()).toEqual({ | ||
count: 2, | ||
}); | ||
expect(myStore.getState()).toEqual({ | ||
count: 2, | ||
}); | ||
|
||
myStore.setPaused(true); | ||
grandparentStore.setPaused(false); | ||
rootStore.dispatch(incrementAction()); | ||
|
||
expect(rootStore.getState()).toEqual({ | ||
count: 5, | ||
}); | ||
expect(grandparentStore.getState()).toEqual({ | ||
count: 5, | ||
}); | ||
expect(parentStore.getState()).toEqual({ | ||
count: 5, | ||
}); | ||
expect(myStore.getState()).toEqual({ | ||
count: 2, | ||
}); | ||
|
||
myStore.setPaused(false); | ||
expect(myStore.getState()).toEqual({ | ||
count: 5, | ||
}); | ||
}); | ||
}); |