-
Notifications
You must be signed in to change notification settings - Fork 28
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
Showing
5 changed files
with
93 additions
and
7 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
62 changes: 62 additions & 0 deletions
62
packages/polaris-viz/src/hooks/tests/useWatchActiveSeries.test.tsx
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,62 @@ | ||
import {mount} from '@shopify/react-testing'; | ||
import {COLOR_VISION_SINGLE_ITEM} from '@shopify/polaris-viz-core'; | ||
|
||
import { | ||
useWatchActiveSeries, | ||
setActiveSeriesListener, | ||
} from '../useWatchActiveSeries'; | ||
import {getEventName} from '../ColorVisionA11y'; | ||
|
||
describe('useWatchActiveSeries()', () => { | ||
describe('useWatchActiveSeries()', () => { | ||
it('attaches event listener to window when id is passed', () => { | ||
const addEventListenerSpy = jest.spyOn(window, 'addEventListener'); | ||
|
||
function MockComponent() { | ||
useWatchActiveSeries('id', () => {}); | ||
|
||
return null; | ||
} | ||
|
||
mount(<MockComponent />); | ||
|
||
expect(addEventListenerSpy).toHaveBeenCalledWith( | ||
'id:color-vision-event:singleItem', | ||
expect.any(Function), | ||
); | ||
}); | ||
|
||
it('removes event listener from window when component is unmounted', () => { | ||
const removeEventListenerSpy = jest.spyOn(window, 'removeEventListener'); | ||
|
||
function MockComponent() { | ||
useWatchActiveSeries('id', () => {}); | ||
|
||
return null; | ||
} | ||
|
||
const component = mount(<MockComponent />); | ||
|
||
component.unmount(); | ||
|
||
expect(removeEventListenerSpy).toHaveBeenCalledWith( | ||
'id:color-vision-event:singleItem', | ||
expect.any(Function), | ||
); | ||
}); | ||
}); | ||
|
||
describe('setActiveSeriesListener()', () => { | ||
it('generates an event name using the given ID', () => { | ||
const id = getEventName('someChartId', COLOR_VISION_SINGLE_ITEM); | ||
const addEventListenerSpy = jest.spyOn(window, 'addEventListener'); | ||
|
||
setActiveSeriesListener('someChartId', () => {}); | ||
|
||
expect(addEventListenerSpy).toHaveBeenCalledWith( | ||
id, | ||
expect.any(Function), | ||
); | ||
}); | ||
}); | ||
}); |
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