-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace withSeriestype shallow tests (#387)
- Loading branch information
Showing
1 changed file
with
68 additions
and
20 deletions.
There are no files selected for viewing
88 changes: 68 additions & 20 deletions
88
packages/react-jsx-highcharts/test/components/WithSeriesType/index.spec.js
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 |
---|---|---|
@@ -1,45 +1,93 @@ | ||
import * as React from 'react'; | ||
import ShallowRenderer from 'react-shallow-renderer'; | ||
import Highcharts from 'highcharts'; | ||
import addAccessibility from 'highcharts/modules/accessibility'; | ||
|
||
import { render } from '@testing-library/react'; | ||
|
||
import { | ||
HighchartsChart, | ||
Chart, | ||
YAxis, | ||
XAxis, | ||
HighchartsProvider | ||
} from '../../../src'; | ||
|
||
import withSeriesType from '../../../src/components/WithSeriesType'; | ||
import Series from '../../../src/components/Series'; | ||
|
||
describe('withSeriesType', () => { | ||
let renderer; | ||
import ContextSpy from '../../ContextSpy'; | ||
|
||
addAccessibility(Highcharts); | ||
|
||
describe('withSeriesType', () => { | ||
let ChartComponent; | ||
let seriesRef; | ||
beforeEach(() => { | ||
renderer = new ShallowRenderer(); | ||
seriesRef = {}; | ||
|
||
ChartComponent = ({ children }) => { | ||
return ( | ||
<HighchartsProvider Highcharts={Highcharts}> | ||
<HighchartsChart> | ||
<Chart zoomType="x" /> | ||
<XAxis></XAxis> | ||
<YAxis>{children}</YAxis> | ||
</HighchartsChart> | ||
</HighchartsProvider> | ||
); | ||
}; | ||
}); | ||
|
||
it('should create Series component', () => { | ||
const SeriesComponent = withSeriesType('line'); | ||
renderer.render(<SeriesComponent />); | ||
const result = renderer.getRenderOutput(); | ||
render( | ||
<ChartComponent> | ||
<SeriesComponent> | ||
<ContextSpy seriesRef={seriesRef} /> | ||
</SeriesComponent> | ||
</ChartComponent> | ||
); | ||
|
||
expect(result.type).toEqual(Series); | ||
expect(seriesRef.current.object).toBeDefined(); | ||
}); | ||
|
||
it(`should set type attribute <Series type="line" />`, () => { | ||
const SeriesComponent = withSeriesType('line'); | ||
renderer.render(<SeriesComponent />); | ||
const result = renderer.getRenderOutput(); | ||
it(`should set type attribute for the series`, () => { | ||
const SeriesComponent = withSeriesType('column'); | ||
render( | ||
<ChartComponent> | ||
<SeriesComponent> | ||
<ContextSpy seriesRef={seriesRef} /> | ||
</SeriesComponent> | ||
</ChartComponent> | ||
); | ||
|
||
expect(result.props).toHaveProperty('type', 'line'); | ||
expect(seriesRef.current.object.type).toBe('column'); | ||
}); | ||
|
||
it(`the created component should pass additional props through to Series`, () => { | ||
const SeriesComponent = withSeriesType('line'); | ||
renderer.render(<SeriesComponent data={[1, 2, 3, 4]} />); | ||
const result = renderer.getRenderOutput(); | ||
const data = [1, 2, 3, 4]; | ||
render( | ||
<ChartComponent> | ||
<SeriesComponent data={data}> | ||
<ContextSpy seriesRef={seriesRef} /> | ||
</SeriesComponent> | ||
</ChartComponent> | ||
); | ||
|
||
expect(result.props).toHaveProperty('data', [1, 2, 3, 4]); | ||
expect(seriesRef.current.object.userOptions.data).toBe(data); | ||
}); | ||
|
||
it(`should pass additionalProps to Series`, () => { | ||
const SeriesComponent = withSeriesType('line', { requiresAxis: false }); | ||
renderer.render(<SeriesComponent />); | ||
const result = renderer.getRenderOutput(); | ||
const SeriesComponent = withSeriesType('line', { visible: false }); | ||
const data = [1, 2, 3, 4]; | ||
render( | ||
<ChartComponent> | ||
<SeriesComponent data={data}> | ||
<ContextSpy seriesRef={seriesRef} /> | ||
</SeriesComponent> | ||
</ChartComponent> | ||
); | ||
|
||
expect(result.props).toHaveProperty('requiresAxis', false); | ||
expect(seriesRef.current.object.visible).toBe(false); | ||
}); | ||
}); |