-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
6 changed files
with
172 additions
and
34 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,4 @@ | ||
import React from 'react'; | ||
|
||
const ChartContext = React.createContext(); | ||
export default ChartContext; |
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,7 @@ | ||
import styled from 'styled-components'; | ||
|
||
const StyledDatasetContainer = styled.div` | ||
display: none; | ||
`; | ||
|
||
export default StyledDatasetContainer; |
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,78 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import Dataset from '..'; | ||
|
||
const context = { | ||
registerDataset: jest.fn(), | ||
unregisterDataset: jest.fn(), | ||
updateDataset: jest.fn(), | ||
}; | ||
|
||
describe('<Dataset />', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
React.useContext = jest.fn().mockReturnValue(context); | ||
}); | ||
|
||
it('should call registerDataset with dataset props', () => { | ||
mount( | ||
<Dataset | ||
title="Dataset 1" | ||
values={[1, 2, 3]} | ||
backgroundColor="#ccc" | ||
borderColor="#000" | ||
stack="stack-1" | ||
type="line" | ||
/>, | ||
); | ||
expect(context.registerDataset).toHaveBeenCalledWith(expect.any(String), { | ||
label: 'Dataset 1', | ||
data: [1, 2, 3], | ||
backgroundColor: '#ccc', | ||
borderColor: '#000', | ||
stack: 'stack-1', | ||
type: 'line', | ||
fill: false, | ||
}); | ||
}); | ||
|
||
it('should call unregisterDataset when unmounted', () => { | ||
const wrapper = mount( | ||
<Dataset | ||
title="Dataset 1" | ||
values={[1, 2, 3]} | ||
backgroundColor="#ccc" | ||
borderColor="#000" | ||
stack="stack-1" | ||
type="line" | ||
/>, | ||
); | ||
wrapper.unmount(); | ||
expect(context.unregisterDataset).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should call updateDataset when props changes', () => { | ||
const wrapper = mount( | ||
<Dataset | ||
title="Dataset 1" | ||
values={[1, 2, 3]} | ||
backgroundColor="#ccc" | ||
borderColor="#000" | ||
stack="stack-1" | ||
type="line" | ||
/>, | ||
); | ||
wrapper.setProps({ | ||
values: [4, 5, 6], | ||
}); | ||
expect(context.updateDataset).toHaveBeenCalledWith(expect.any(String), { | ||
label: 'Dataset 1', | ||
data: [4, 5, 6], | ||
backgroundColor: '#ccc', | ||
borderColor: '#000', | ||
stack: 'stack-1', | ||
type: 'line', | ||
fill: 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