From 76548a0a088aabd8f8ff006808825982c2f569bc Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Tue, 1 Sep 2020 17:34:16 -0700 Subject: [PATCH] test: add unit tests --- packages/vx-grid/test/Columns.test.tsx | 7 ----- packages/vx-grid/test/Grid.test.tsx | 21 ++++++++++++- packages/vx-grid/test/GridColumns.test.tsx | 22 +++++++++++++ packages/vx-grid/test/GridRows.test.tsx | 22 +++++++++++++ packages/vx-grid/test/Rows.test.tsx | 7 ----- packages/vx-zoom/test/Zoom.test.tsx | 36 ++++++++++++++++++++-- 6 files changed, 98 insertions(+), 17 deletions(-) delete mode 100644 packages/vx-grid/test/Columns.test.tsx create mode 100644 packages/vx-grid/test/GridColumns.test.tsx create mode 100644 packages/vx-grid/test/GridRows.test.tsx delete mode 100644 packages/vx-grid/test/Rows.test.tsx diff --git a/packages/vx-grid/test/Columns.test.tsx b/packages/vx-grid/test/Columns.test.tsx deleted file mode 100644 index e0301619e..000000000 --- a/packages/vx-grid/test/Columns.test.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import { GridColumns } from '../src'; - -describe('', () => { - test('it should be defined', () => { - expect(GridColumns).toBeDefined(); - }); -}); diff --git a/packages/vx-grid/test/Grid.test.tsx b/packages/vx-grid/test/Grid.test.tsx index e3a3879fc..fc0760886 100644 --- a/packages/vx-grid/test/Grid.test.tsx +++ b/packages/vx-grid/test/Grid.test.tsx @@ -1,7 +1,26 @@ +import React from 'react'; +import { render } from 'enzyme'; +import { scaleLinear } from '@vx/scale'; import { Grid } from '../src'; describe('', () => { - test('it should be defined', () => { + it('should be defined', () => { expect(Grid).toBeDefined(); }); + it('should create grid lines', () => { + const wrapper = render( + , + ); + expect(wrapper.find('.vx-rows')).toHaveLength(1); + expect(wrapper.find('.vx-columns')).toHaveLength(1); + expect(wrapper.find('.vx-line')).toHaveLength(22); + }); }); diff --git a/packages/vx-grid/test/GridColumns.test.tsx b/packages/vx-grid/test/GridColumns.test.tsx new file mode 100644 index 000000000..6c12a4376 --- /dev/null +++ b/packages/vx-grid/test/GridColumns.test.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { render } from 'enzyme'; +import { scaleLinear } from '@vx/scale'; +import { GridColumns } from '../src'; + +describe('', () => { + it('should be defined', () => { + expect(GridColumns).toBeDefined(); + }); + it('should create grid lines', () => { + const wrapper = render( + , + ); + expect(wrapper.find('.vx-line')).toHaveLength(11); + }); +}); diff --git a/packages/vx-grid/test/GridRows.test.tsx b/packages/vx-grid/test/GridRows.test.tsx new file mode 100644 index 000000000..3afbcbd44 --- /dev/null +++ b/packages/vx-grid/test/GridRows.test.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { render } from 'enzyme'; +import { scaleLinear } from '@vx/scale'; +import { GridRows } from '../src'; + +describe('', () => { + it('should be defined', () => { + expect(GridRows).toBeDefined(); + }); + it('should create grid lines', () => { + const wrapper = render( + , + ); + expect(wrapper.find('.vx-line')).toHaveLength(11); + }); +}); diff --git a/packages/vx-grid/test/Rows.test.tsx b/packages/vx-grid/test/Rows.test.tsx deleted file mode 100644 index b037ee4ad..000000000 --- a/packages/vx-grid/test/Rows.test.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import { GridRows } from '../src'; - -describe('', () => { - test('it should be defined', () => { - expect(GridRows).toBeDefined(); - }); -}); diff --git a/packages/vx-zoom/test/Zoom.test.tsx b/packages/vx-zoom/test/Zoom.test.tsx index ee6fbb521..db6ca4e3c 100644 --- a/packages/vx-zoom/test/Zoom.test.tsx +++ b/packages/vx-zoom/test/Zoom.test.tsx @@ -1,13 +1,45 @@ +import React from 'react'; +import { render } from 'enzyme'; import { Zoom, inverseMatrix } from '../src'; describe('Zoom', () => { - test('it should be defined', () => { + it('should be defined', () => { expect(Zoom).toBeDefined(); }); + it('should render the children and pass zoom params', () => { + const initialTransform = { + scaleX: 1.27, + scaleY: 1.27, + translateX: -211.62, + translateY: 162.59, + skewX: 0, + skewY: 0, + }; + + const wrapper = render( + + {({ transformMatrix }) => { + const { scaleX, scaleY, translateX, translateY } = transformMatrix; + return
{[scaleX, scaleY, translateX, translateY].join(',')}
; + }} +
, + ); + + expect(wrapper.find('div')).toHaveLength(1); + expect(wrapper.find('div').text()).toEqual('1.27,1.27,-211.62,162.59'); + }); }); describe('inverseMatrix', () => { - test('it should be defined', () => { + it('should be defined', () => { expect(inverseMatrix).toBeDefined(); }); });