Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(xychart): add Annotations tests #948

Merged
merged 2 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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