From 519d92dde20dfd9ade702ee87b2cb1418a2b8463 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Thu, 5 Nov 2020 16:29:23 -0800 Subject: [PATCH] test(annotation): add tests for new annotation components (#912) * test(annotation): add tests for new annotation components * tests(annotation//LineSubject): fix typo --- packages/visx-annotation/package.json | 3 ++ .../visx-annotation/src/components/Label.tsx | 1 + .../test/CircleSubject.test.tsx | 5 +++ .../visx-annotation/test/Connector.test.tsx | 5 +++ .../test/EditableAnnotation.test.tsx | 17 +++++++- packages/visx-annotation/test/Label.test.tsx | 41 +++++++++++++++++++ .../visx-annotation/test/LineSubject.test.tsx | 5 +++ 7 files changed, 76 insertions(+), 1 deletion(-) diff --git a/packages/visx-annotation/package.json b/packages/visx-annotation/package.json index e89ed451b..73d205ed2 100644 --- a/packages/visx-annotation/package.json +++ b/packages/visx-annotation/package.json @@ -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" } diff --git a/packages/visx-annotation/src/components/Label.tsx b/packages/visx-annotation/src/components/Label.tsx index c414afa99..c9ac33f7b 100644 --- a/packages/visx-annotation/src/components/Label.tsx +++ b/packages/visx-annotation/src/components/Label.tsx @@ -150,6 +150,7 @@ export default function AnnotationLabel({ > {showBackground && ( ', () => { it('should be defined', () => { expect(CircleSubject).toBeDefined(); }); + it('should render a cirlce', () => { + expect(shallow().find('circle')).toHaveLength(1); + }); }); diff --git a/packages/visx-annotation/test/Connector.test.tsx b/packages/visx-annotation/test/Connector.test.tsx index 59b59de13..130d1666d 100644 --- a/packages/visx-annotation/test/Connector.test.tsx +++ b/packages/visx-annotation/test/Connector.test.tsx @@ -1,7 +1,12 @@ +import React from 'react'; +import { shallow } from 'enzyme'; import { Connector } from '../src'; describe('', () => { it('should be defined', () => { expect(Connector).toBeDefined(); }); + it('should render a path', () => { + expect(shallow().find('path')).toHaveLength(1); + }); }); diff --git a/packages/visx-annotation/test/EditableAnnotation.test.tsx b/packages/visx-annotation/test/EditableAnnotation.test.tsx index 9631168c5..b72f49b0c 100644 --- a/packages/visx-annotation/test/EditableAnnotation.test.tsx +++ b/packages/visx-annotation/test/EditableAnnotation.test.tsx @@ -1,7 +1,22 @@ -import { EditableAnnotation } from '../src'; +import React from 'react'; +import { shallow } from 'enzyme'; +import { Annotation, EditableAnnotation } from '../src'; describe('', () => { + function setup() { + return shallow( + +
+ , + ); + } 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); + }); }); diff --git a/packages/visx-annotation/test/Label.test.tsx b/packages/visx-annotation/test/Label.test.tsx index e9b77a73d..966e57819 100644 --- a/packages/visx-annotation/test/Label.test.tsx +++ b/packages/visx-annotation/test/Label.test.tsx @@ -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('