-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Conrad Chan
committed
Sep 8, 2020
1 parent
9ad9480
commit c2c0e20
Showing
4 changed files
with
118 additions
and
15 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,111 @@ | ||
import eventManager from '../../../common/EventManager'; | ||
import { getStatus, getType, handleSetStagedAction, handleResetCreatorAction } from '../staged'; | ||
import { createStore } from '../..'; | ||
import { CreatorItemHighlight, CreatorItemRegion, CreatorState } from '../../creator'; | ||
import { Event } from '../../../@types'; | ||
|
||
jest.mock('../../../common/EventManager'); | ||
|
||
describe('store/eventing/staged', () => { | ||
const getStagedHighlight = (): CreatorItemHighlight => ({ | ||
location: 1, | ||
shapes: [ | ||
{ | ||
type: 'rect', | ||
height: 50, | ||
width: 50, | ||
x: 10, | ||
y: 10, | ||
}, | ||
], | ||
}); | ||
|
||
const getStagedRegion = (): CreatorItemRegion => ({ | ||
location: 1, | ||
shape: { | ||
type: 'rect', | ||
height: 50, | ||
width: 50, | ||
x: 10, | ||
y: 10, | ||
}, | ||
}); | ||
|
||
const getCreatorHighlight = (): CreatorState => | ||
({ | ||
staged: getStagedHighlight(), | ||
} as CreatorState); | ||
|
||
const getCreatorRegion = (): CreatorState => | ||
({ | ||
staged: getStagedRegion(), | ||
} as CreatorState); | ||
|
||
describe('getStatus()', () => { | ||
test.each` | ||
prev | next | expectedStatus | ||
${null} | ${null} | ${null} | ||
${null} | ${'notnull'} | ${'create'} | ||
${'notnull'} | ${null} | ${null} | ||
${'notnull'} | ${'notnull'} | ${'update'} | ||
`( | ||
'should return $expectedStatus if prevStaged=$prev and nextStaged=$next', | ||
({ prev, next, expectedStatus }) => { | ||
expect(getStatus(prev, next)).toBe(expectedStatus); | ||
}, | ||
); | ||
}); | ||
|
||
describe('getType()', () => { | ||
test.each` | ||
staged | expectedType | ||
${null} | ${null} | ||
${getStagedHighlight()} | ${'highlight'} | ||
${getStagedRegion()} | ${'region'} | ||
`('should returned $expectedType if staged=$staged', ({ staged, expectedType }) => { | ||
expect(getType(staged)).toBe(expectedType); | ||
}); | ||
}); | ||
|
||
describe('handleSetStagedAction()', () => { | ||
test.each` | ||
prev | next | ||
${createStore().getState()} | ${createStore().getState()} | ||
${createStore({ creator: getCreatorHighlight() }).getState()} | ${createStore().getState()} | ||
`('should not emit event if status or type is null', ({ prev, next }) => { | ||
handleSetStagedAction(prev, next); | ||
|
||
expect(eventManager.emit).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test.each` | ||
prev | next | type | status | ||
${createStore().getState()} | ${createStore({ creator: getCreatorHighlight() }).getState()} | ${'highlight'} | ${'create'} | ||
${createStore().getState()} | ${createStore({ creator: getCreatorRegion() }).getState()} | ${'region'} | ${'create'} | ||
${createStore({ creator: getCreatorRegion() }).getState()} | ${createStore({ creator: getCreatorRegion() }).getState()} | ${'region'} | ${'update'} | ||
`('should emit event with type=$type and status=$status', ({ prev, next, type, status }) => { | ||
handleSetStagedAction(prev, next); | ||
|
||
expect(eventManager.emit).toHaveBeenCalledWith(Event.CREATOR_STAGED_CHANGE, { type, status }); | ||
}); | ||
}); | ||
|
||
describe('handleResetCreatorAction()', () => { | ||
test('should not emit event if type is null', () => { | ||
const prevState = createStore().getState(); | ||
handleResetCreatorAction(prevState); | ||
|
||
expect(eventManager.emit).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test.each` | ||
prev | type | ||
${createStore({ creator: getCreatorHighlight() }).getState()} | ${'highlight'} | ||
${createStore({ creator: getCreatorRegion() }).getState()} | ${'region'} | ||
`('should emit cancel event if with type=$type', ({ prev, type }) => { | ||
handleResetCreatorAction(prev); | ||
|
||
expect(eventManager.emit).toHaveBeenCalledWith(Event.CREATOR_STAGED_CHANGE, { type, status: 'cancel' }); | ||
}); | ||
}); | ||
}); |
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