-
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.
refactor: Move deselect and isListening logic (#662)
- Loading branch information
Conrad Chan
authored
Jan 4, 2021
1 parent
d67fef3
commit 2f4a9e1
Showing
13 changed files
with
99 additions
and
74 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 @@ | ||
export default jest.fn().mockReturnValue(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
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,40 @@ | ||
import * as React from 'react'; | ||
import { mount, ReactWrapper } from 'enzyme'; | ||
import { Provider } from 'react-redux'; | ||
import useIsListInteractive from '../useIsListInteractive'; | ||
import { createStore, CreatorStatus } from '../../store'; | ||
|
||
describe('useIsListInteractive', () => { | ||
function TestComponent(): JSX.Element { | ||
const isListening = useIsListInteractive(); | ||
|
||
return <div data-islistening={isListening} data-testid="islistening" />; | ||
} | ||
|
||
const getWrapper = (store = createStore()): ReactWrapper => | ||
mount( | ||
<Provider store={store}> | ||
<TestComponent /> | ||
</Provider>, | ||
); | ||
|
||
test('should be listening by default', () => { | ||
const wrapper = getWrapper(); | ||
|
||
expect(wrapper.find('[data-testid="islistening"]').prop('data-islistening')).toEqual(true); | ||
}); | ||
|
||
test('should not be listening if CreatorStatus is not init', () => { | ||
const store = createStore({ creator: { status: CreatorStatus.started } }); | ||
const wrapper = getWrapper(store); | ||
|
||
expect(wrapper.find('[data-testid="islistening"]').prop('data-islistening')).toEqual(false); | ||
}); | ||
|
||
test('should not be listening if isSelecting is true', () => { | ||
const store = createStore({ highlight: { isSelecting: true } }); | ||
const wrapper = getWrapper(store); | ||
|
||
expect(wrapper.find('[data-testid="islistening"]').prop('data-islistening')).toEqual(false); | ||
}); | ||
}); |
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,10 @@ | ||
import * as ReactRedux from 'react-redux'; | ||
import { getCreatorStatus, getIsSelecting, CreatorStatus } from '../store'; | ||
|
||
// Returns whether rendered annotations should be interactive | ||
export default function useIsListInteractive(): boolean { | ||
const status = ReactRedux.useSelector(getCreatorStatus); | ||
const isSelecting = ReactRedux.useSelector(getIsSelecting); | ||
|
||
return status === CreatorStatus.init && !isSelecting; | ||
} |
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