Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw committed Sep 2, 2020
1 parent 510a1c0 commit 76548a0
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 17 deletions.
7 changes: 0 additions & 7 deletions packages/vx-grid/test/Columns.test.tsx

This file was deleted.

21 changes: 20 additions & 1 deletion packages/vx-grid/test/Grid.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import React from 'react';
import { render } from 'enzyme';
import { scaleLinear } from '@vx/scale';
import { Grid } from '../src';

describe('<Grid />', () => {
test('it should be defined', () => {
it('should be defined', () => {
expect(Grid).toBeDefined();
});
it('should create grid lines', () => {
const wrapper = render(
<Grid
xScale={scaleLinear({ range: [0, 100] })}
yScale={scaleLinear({ range: [0, 100] })}
width={400}
height={400}
strokeDasharray="3,3"
strokeOpacity={0.3}
pointerEvents="none"
/>,
);
expect(wrapper.find('.vx-rows')).toHaveLength(1);
expect(wrapper.find('.vx-columns')).toHaveLength(1);
expect(wrapper.find('.vx-line')).toHaveLength(22);
});
});
22 changes: 22 additions & 0 deletions packages/vx-grid/test/GridColumns.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { render } from 'enzyme';
import { scaleLinear } from '@vx/scale';
import { GridColumns } from '../src';

describe('<GridColumns />', () => {
it('should be defined', () => {
expect(GridColumns).toBeDefined();
});
it('should create grid lines', () => {
const wrapper = render(
<GridColumns
scale={scaleLinear({ range: [0, 100] })}
height={400}
strokeDasharray="3,3"
strokeOpacity={0.3}
pointerEvents="none"
/>,
);
expect(wrapper.find('.vx-line')).toHaveLength(11);
});
});
22 changes: 22 additions & 0 deletions packages/vx-grid/test/GridRows.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { render } from 'enzyme';
import { scaleLinear } from '@vx/scale';
import { GridRows } from '../src';

describe('<GridRows />', () => {
it('should be defined', () => {
expect(GridRows).toBeDefined();
});
it('should create grid lines', () => {
const wrapper = render(
<GridRows
scale={scaleLinear({ range: [0, 100] })}
width={400}
strokeDasharray="3,3"
strokeOpacity={0.3}
pointerEvents="none"
/>,
);
expect(wrapper.find('.vx-line')).toHaveLength(11);
});
});
7 changes: 0 additions & 7 deletions packages/vx-grid/test/Rows.test.tsx

This file was deleted.

36 changes: 34 additions & 2 deletions packages/vx-zoom/test/Zoom.test.tsx
Original file line number Diff line number Diff line change
@@ -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(
<Zoom
width={400}
height={400}
scaleXMin={1 / 2}
scaleXMax={4}
scaleYMin={1 / 2}
scaleYMax={4}
transformMatrix={initialTransform}
>
{({ transformMatrix }) => {
const { scaleX, scaleY, translateX, translateY } = transformMatrix;
return <div>{[scaleX, scaleY, translateX, translateY].join(',')}</div>;
}}
</Zoom>,
);

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();
});
});

0 comments on commit 76548a0

Please sign in to comment.