Skip to content

Commit

Permalink
test(xychart): add Animated(BarGroup, BarStack, BarSeries, LineSeries…
Browse files Browse the repository at this point in the history
…) tests
  • Loading branch information
williaster committed Oct 15, 2020
1 parent 279bd2f commit e882b46
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 6 deletions.
24 changes: 22 additions & 2 deletions packages/visx-xychart/test/components/BarGroup.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect } from 'react';
import { animated } from 'react-spring';
import { mount } from 'enzyme';
import { BarGroup, BarSeries, DataProvider, useEventEmitter } from '../../src';
import { AnimatedBarGroup, BarGroup, BarSeries, DataProvider, useEventEmitter } from '../../src';
import setupTooltipTest from '../mocks/setupTooltipTest';

const providerProps = {
Expand Down Expand Up @@ -77,7 +78,7 @@ describe('<BarGroup />', () => {

setupTooltipTest(
<>
<BarGroup horizontal>
<BarGroup>
<BarSeries dataKey={series1.key} {...series1} />
<BarSeries dataKey={series2.key} {...series2} />
</BarGroup>
Expand All @@ -87,3 +88,22 @@ describe('<BarGroup />', () => {
);
});
});

describe('<AnimatedBarGroup />', () => {
it('should be defined', () => {
expect(AnimatedBarGroup).toBeDefined();
});
it('should render an animated.rect', () => {
const wrapper = mount(
<DataProvider {...providerProps}>
<svg>
<AnimatedBarGroup>
<BarSeries dataKey={series1.key} {...series1} />
<BarSeries dataKey={series2.key} {...series2} />
</AnimatedBarGroup>
</svg>
</DataProvider>,
);
expect(wrapper.find(animated.rect)).toHaveLength(4);
});
});
19 changes: 18 additions & 1 deletion packages/visx-xychart/test/components/BarSeries.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useContext, useEffect } from 'react';
import { animated } from 'react-spring';
import { mount } from 'enzyme';
import { DataContext, BarSeries, useEventEmitter } from '../../src';
import { DataContext, AnimatedBarSeries, BarSeries, useEventEmitter } from '../../src';
import getDataContext from '../mocks/getDataContext';
import setupTooltipTest from '../mocks/setupTooltipTest';

Expand Down Expand Up @@ -62,3 +63,19 @@ describe('<BarSeries />', () => {
);
});
});

describe('<AnimatedBarSeries />', () => {
it('should be defined', () => {
expect(AnimatedBarSeries).toBeDefined();
});
it('should render an animated.rect', () => {
const wrapper = mount(
<DataContext.Provider value={getDataContext(series)}>
<svg>
<AnimatedBarSeries dataKey={series.key} {...series} />
</svg>
</DataContext.Provider>,
);
expect(wrapper.find(animated.rect)).toHaveLength(series.data.length);
});
});
31 changes: 29 additions & 2 deletions packages/visx-xychart/test/components/BarStack.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import React, { useContext, useEffect } from 'react';
import { mount } from 'enzyme';
import { BarStack, BarSeries, DataProvider, DataContext, useEventEmitter } from '../../src';
import { animated } from 'react-spring';
import {
BarStack,
BarSeries,
DataProvider,
DataContext,
useEventEmitter,
AnimatedBarStack,
} from '../../src';
import setupTooltipTest from '../mocks/setupTooltipTest';

const providerProps = {
Expand Down Expand Up @@ -109,7 +117,7 @@ describe('<BarStack />', () => {

setupTooltipTest(
<>
<BarStack horizontal>
<BarStack>
<BarSeries dataKey={series1.key} {...series1} />
<BarSeries dataKey={series2.key} {...series2} />
</BarStack>
Expand All @@ -119,3 +127,22 @@ describe('<BarStack />', () => {
);
});
});

describe('<AnimatedBarStack />', () => {
it('should be defined', () => {
expect(AnimatedBarStack).toBeDefined();
});
it('should render an animated.rect', () => {
const wrapper = mount(
<DataProvider {...providerProps}>
<svg>
<AnimatedBarStack>
<BarSeries dataKey={series1.key} {...series1} />
<BarSeries dataKey={series2.key} {...series2} />
</AnimatedBarStack>
</svg>
</DataProvider>,
);
expect(wrapper.find(animated.rect)).toHaveLength(4);
});
});
19 changes: 18 additions & 1 deletion packages/visx-xychart/test/components/LineSeries.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { useContext, useEffect } from 'react';
import { animated } from 'react-spring';
import { mount } from 'enzyme';
import { LinePath } from '@visx/shape';
import { DataContext, LineSeries, useEventEmitter } from '../../src';
import { AnimatedLineSeries, DataContext, LineSeries, useEventEmitter } from '../../src';
import getDataContext from '../mocks/getDataContext';
import setupTooltipTest from '../mocks/setupTooltipTest';

Expand Down Expand Up @@ -64,3 +65,19 @@ describe('<LineSeries />', () => {
);
});
});

describe('<AnimatedLineSeries />', () => {
it('should be defined', () => {
expect(AnimatedLineSeries).toBeDefined();
});
it('should render an animated.path', () => {
const wrapper = mount(
<DataContext.Provider value={getDataContext(series)}>
<svg>
<AnimatedLineSeries dataKey={series.key} {...series} />
</svg>
</DataContext.Provider>,
);
expect(wrapper.find(animated.path)).toHaveLength(1);
});
});

0 comments on commit e882b46

Please sign in to comment.