From f6eadc1f87e27d42f9b3628072eef28d0921e6fc Mon Sep 17 00:00:00 2001 From: anajavi Date: Thu, 8 Aug 2024 16:28:05 +0300 Subject: [PATCH] Replace withSeriestype shallow tests (#387) --- .../components/WithSeriesType/index.spec.js | 88 ++++++++++++++----- 1 file changed, 68 insertions(+), 20 deletions(-) diff --git a/packages/react-jsx-highcharts/test/components/WithSeriesType/index.spec.js b/packages/react-jsx-highcharts/test/components/WithSeriesType/index.spec.js index f4a00aa3..19ac2623 100644 --- a/packages/react-jsx-highcharts/test/components/WithSeriesType/index.spec.js +++ b/packages/react-jsx-highcharts/test/components/WithSeriesType/index.spec.js @@ -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 ( + + + + + {children} + + + ); + }; }); it('should create Series component', () => { const SeriesComponent = withSeriesType('line'); - renderer.render(); - const result = renderer.getRenderOutput(); + render( + + + + + + ); - expect(result.type).toEqual(Series); + expect(seriesRef.current.object).toBeDefined(); }); - it(`should set type attribute `, () => { - const SeriesComponent = withSeriesType('line'); - renderer.render(); - const result = renderer.getRenderOutput(); + it(`should set type attribute for the series`, () => { + const SeriesComponent = withSeriesType('column'); + render( + + + + + + ); - 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(); - const result = renderer.getRenderOutput(); + const data = [1, 2, 3, 4]; + render( + + + + + + ); - 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(); - const result = renderer.getRenderOutput(); + const SeriesComponent = withSeriesType('line', { visible: false }); + const data = [1, 2, 3, 4]; + render( + + + + + + ); - expect(result.props).toHaveProperty('requiresAxis', false); + expect(seriesRef.current.object.visible).toBe(false); }); });