Skip to content

Commit

Permalink
test(annotation): add tests for new annotation components
Browse files Browse the repository at this point in the history
  • Loading branch information
williaster committed Nov 3, 2020
1 parent ea1fc3e commit 91893fd
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/visx-annotation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"prop-types": "^15.5.10",
"react-use-measure": "2.0.1"
},
"devDependencies": {
"resize-observer-polyfill": "^1.5.1"
},
"publishConfig": {
"access": "public"
}
Expand Down
1 change: 1 addition & 0 deletions packages/visx-annotation/src/components/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ export default function AnnotationLabel({
>
{showBackground && (
<rect
className="visx-annotationlabel-background"
fill={backgroundFill}
x={0}
y={0}
Expand Down
5 changes: 5 additions & 0 deletions packages/visx-annotation/test/CircleSubject.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react';
import { shallow } from 'enzyme';
import { CircleSubject } from '../src';

describe('<CircleSubject />', () => {
it('should be defined', () => {
expect(CircleSubject).toBeDefined();
});
it('should render a cirlce', () => {
expect(shallow(<CircleSubject />).find('circle')).toHaveLength(1);
});
});
5 changes: 5 additions & 0 deletions packages/visx-annotation/test/Connector.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Connector } from '../src';

describe('<Connector />', () => {
it('should be defined', () => {
expect(Connector).toBeDefined();
});
it('should render a path', () => {
expect(shallow(<Connector />).find('path')).toHaveLength(1);
});
});
17 changes: 16 additions & 1 deletion packages/visx-annotation/test/EditableAnnotation.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { EditableAnnotation } from '../src';
import React from 'react';
import { shallow } from 'enzyme';
import { Annotation, EditableAnnotation } from '../src';

describe('<EditableAnnotation />', () => {
function setup() {
return shallow(
<EditableAnnotation width={100} height={100}>
<div />
</EditableAnnotation>,
);
}
it('should be defined', () => {
expect(EditableAnnotation).toBeDefined();
});
it('should render two resize handles', () => {
expect(setup().find('circle')).toHaveLength(2);
});
it('should render an Annotation', () => {
expect(setup().find(Annotation)).toHaveLength(1);
});
});
41 changes: 41 additions & 0 deletions packages/visx-annotation/test/Label.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
import React from 'react';
import ResizeObserver from 'resize-observer-polyfill';
import Text from '@visx/text/lib/Text';
import { shallow } from 'enzyme';
import { Label } from '../src';

describe('<Label />', () => {
it('should be defined', () => {
expect(Label).toBeDefined();
});
it('should render title Text', () => {
expect(
shallow(<Label title="title test" resizeObserverPolyfill={ResizeObserver} />)
.find(Text)
.dive()
.text(),
).toBe('title test');
});
it('should render subtitle Text', () => {
expect(
shallow(
<Label
title="title test"
subtitle="subtitle test"
resizeObserverPolyfill={ResizeObserver}
/>,
)
.find(Text)
.at(1)
.dive()
.text(),
).toBe('subtitle test');
});
it('should render a background', () => {
expect(
shallow(
<Label title="title test" showBackground resizeObserverPolyfill={ResizeObserver} />,
).find('rect'),
).toHaveLength(1);
});
it('should render an anchor line', () => {
expect(
shallow(
<Label title="title test" showAnchorLine resizeObserverPolyfill={ResizeObserver} />,
).find('line'),
).toHaveLength(1);
});
});
5 changes: 5 additions & 0 deletions packages/visx-annotation/test/LineSubject.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react';
import { shallow } from 'enzyme';
import { LineSubject } from '../src';

describe('<LineSubject />', () => {
it('should be defined', () => {
expect(LineSubject).toBeDefined();
});
it('should a line', () => {
expect(shallow(<LineSubject min={0} max={100} />).find('line')).toHaveLength(1);
});
});

0 comments on commit 91893fd

Please sign in to comment.