Skip to content

Commit

Permalink
test(xychart): add Annotations tests (#948)
Browse files Browse the repository at this point in the history
* test(xychart/AnnotationLabel): add test

* test(xychart): add Annotation tests
  • Loading branch information
williaster authored Dec 2, 2020
1 parent f5b7f84 commit b6a455e
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 2 deletions.
62 changes: 62 additions & 0 deletions packages/visx-xychart/test/components/Annotation.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';
import { mount } from 'enzyme';
import {
Annotation as VxAnnotation,
EditableAnnotation as VxEditableAnnotation,
} from '@visx/annotation';
import { DataContext, Annotation, AnimatedAnnotation } from '../../src';
import getDataContext from '../mocks/getDataContext';

const series = { key: 'visx', data: [{}], xAccessor: () => 4, yAccessor: () => 7 };

function setup(children: React.ReactNode) {
return mount(
<DataContext.Provider value={getDataContext(series)}>
<svg>{children}</svg>
</DataContext.Provider>,
);
}

describe('<Annotation />', () => {
it('should be defined', () => {
expect(Annotation).toBeDefined();
});
it('should render a VxAnnotation', () => {
const wrapper = setup(
<Annotation dataKey={series.key} datum={{}}>
{'test'}
</Annotation>,
);
expect(wrapper.find(VxAnnotation)).toHaveLength(1);
});
it('should render a VxEditableAnnotation when editable=true', () => {
const wrapper = setup(
<Annotation editable dataKey={series.key} datum={{}}>
{'test'}
</Annotation>,
);
expect(wrapper.find(VxEditableAnnotation)).toHaveLength(1);
});
});

describe('<AnimatedAnnotation />', () => {
it('should be defined', () => {
expect(AnimatedAnnotation).toBeDefined();
});
it('should render a VxAnnotation', () => {
const wrapper = setup(
<AnimatedAnnotation dataKey={series.key} datum={{}}>
{'test'}
</AnimatedAnnotation>,
);
expect(wrapper.find(VxAnnotation)).toHaveLength(1);
});
it('should render a VxEditableAnnotation when editable=true', () => {
const wrapper = setup(
<AnimatedAnnotation editable dataKey={series.key} datum={{}}>
{'test'}
</AnimatedAnnotation>,
);
expect(wrapper.find(VxEditableAnnotation)).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { shallow } from 'enzyme';
import { CircleSubject as VxAnnotationCircleSubject } from '@visx/annotation';
import { AnnotationCircleSubject } from '../../src';

describe('<AnnotationCircleSubject />', () => {
it('should be defined', () => {
expect(AnnotationCircleSubject).toBeDefined();
});
it('should render a VxAnnotationCircleSubject', () => {
const wrapper = shallow(<AnnotationCircleSubject />);
expect(wrapper.find(VxAnnotationCircleSubject)).toHaveLength(1);
});
});
14 changes: 14 additions & 0 deletions packages/visx-xychart/test/components/AnnotationConnector.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Connector as VxAnnotationConnector } from '@visx/annotation';
import { AnnotationConnector } from '../../src';

describe('<AnnotationConnector />', () => {
it('should be defined', () => {
expect(AnnotationConnector).toBeDefined();
});
it('should render a VxAnnotationConnector', () => {
const wrapper = shallow(<AnnotationConnector />);
expect(wrapper.find(VxAnnotationConnector)).toHaveLength(1);
});
});
14 changes: 14 additions & 0 deletions packages/visx-xychart/test/components/AnnotationLabel.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Label as VxAnnotationLabel } from '@visx/annotation';
import { AnnotationLabel } from '../../src';

describe('<AnnotationLabel />', () => {
it('should be defined', () => {
expect(AnnotationLabel).toBeDefined();
});
it('should render a VxAnnotationLabel', () => {
const wrapper = shallow(<AnnotationLabel />);
expect(wrapper.find(VxAnnotationLabel)).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { shallow } from 'enzyme';
import { LineSubject as VxAnnotationLineSubject } from '@visx/annotation';
import { AnnotationLineSubject } from '../../src';

describe('<AnnotationLineSubject />', () => {
it('should be defined', () => {
expect(AnnotationLineSubject).toBeDefined();
});
it('should render a VxAnnotationLineSubject', () => {
const wrapper = shallow(<AnnotationLineSubject />);
expect(wrapper.find(VxAnnotationLineSubject)).toHaveLength(1);
});
});
2 changes: 1 addition & 1 deletion packages/visx-xychart/test/components/Axis.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React from 'react';
import { shallow, mount } from 'enzyme';
import VxAnimatedAxis from '@visx/react-spring/lib/axis/AnimatedAxis';
import VxAxis from '@visx/axis/lib/axis/Axis';
Expand Down
2 changes: 1 addition & 1 deletion packages/visx-xychart/test/mocks/getDataContext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { scaleLinear, scaleOrdinal } from '@visx/scale';
import { DataContextType, lightTheme } from '../../lib';
import { DataContextType, lightTheme } from '../../src';
import DataRegistry from '../../lib/classes/DataRegistry';

const width = 10;
Expand Down

0 comments on commit b6a455e

Please sign in to comment.