Skip to content

Commit

Permalink
test: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kristw committed Sep 2, 2020
1 parent 7f6acf0 commit 3afb333
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
121 changes: 121 additions & 0 deletions packages/vx-shape/test/utils/D3ShapeFactories.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import { curveBasis, stackOrderDescending, stackOffsetExpand } from 'd3-shape';
import { arc, area, pie, line, radialLine, stack } from '../../src/util/D3ShapeFactories';

describe('D3ShapeFactories', () => {
describe('arc()', () => {
it('innerRadius', () => {
expect(arc({ innerRadius: 1 }).innerRadius()({})).toEqual(1);
});
it('outerRadius', () => {
expect(arc({ outerRadius: 1 }).outerRadius()({})).toEqual(1);
});
it('cornerRadius', () => {
expect(arc({ cornerRadius: 1 }).cornerRadius()({})).toEqual(1);
});
it('startAngle', () => {
expect(arc({ startAngle: 1 }).startAngle()({})).toEqual(1);
});
it('endAngle', () => {
expect(arc({ endAngle: 1 }).endAngle()({})).toEqual(1);
});
it('padAngle', () => {
expect(arc({ padAngle: 1 }).padAngle()({})).toEqual(1);
});
it('padRadius', () => {
expect(arc({ padRadius: 1 }).padRadius()!({})).toEqual(1);
});
});

describe('area()', () => {
it('x', () => {
expect(area({ x: 1 }).x()({}, 0, [])).toEqual(1);
});
it('x0', () => {
expect(area({ x0: 1 }).x0()({}, 0, [])).toEqual(1);
});
it('x1', () => {
expect(area({ x1: 1 }).x1()!({}, 0, [])).toEqual(1);
});
it('y', () => {
expect(area({ y: 1 }).y()({}, 0, [])).toEqual(1);
});
it('y0', () => {
expect(area({ y0: 1 }).y0()({}, 0, [])).toEqual(1);
});
it('y1', () => {
expect(area({ y1: 1 }).y1()!({}, 0, [])).toEqual(1);
});
it('defined', () => {
expect(area({ defined: () => true }).defined()({}, 0, [])).toEqual(true);
});
it('curve', () => {
expect(area({ curve: curveBasis }).curve()).toEqual(curveBasis);
});
});

describe('line()', () => {
it('x', () => {
expect(line({ x: 1 }).x()({}, 0, [])).toEqual(1);
});
it('y', () => {
expect(line({ y: 1 }).y()({}, 0, [])).toEqual(1);
});
it('defined', () => {
expect(line({ defined: () => true }).defined()({}, 0, [])).toEqual(true);
});
it('curve', () => {
expect(line({ curve: curveBasis }).curve()).toEqual(curveBasis);
});
});

describe('pie()', () => {
it('startAngle', () => {
expect(pie({ startAngle: 1 }).startAngle()([])).toEqual(1);
});
it('endAngle', () => {
expect(pie({ endAngle: 1 }).endAngle()([])).toEqual(1);
});
it('padAngle', () => {
expect(pie({ padAngle: 1 }).padAngle()([])).toEqual(1);
});
it('value', () => {
expect(pie({ value: () => 1 }).value()({}, 1, [])).toEqual(1);
});
it('sort', () => {
expect(pie({ sort: () => 1 }).sort()!({}, {})).toEqual(1);
});
it('sortValues', () => {
expect(pie({ sortValues: () => 1 }).sortValues()!(2, 1)).toEqual(1);
});
});

describe('radialLine()', () => {
it('angle', () => {
expect(radialLine({ angle: 1 }).angle()({}, 1, [])).toEqual(1);
});
it('radius', () => {
expect(radialLine({ radius: 1 }).radius()({}, 1, [])).toEqual(1);
});
it('defined', () => {
expect(radialLine({ defined: () => true }).defined()({}, 0, [])).toEqual(true);
});
it('curve', () => {
expect(radialLine({ curve: curveBasis }).curve()).toEqual(curveBasis);
});
});

describe('stack()', () => {
it('keys', () => {
expect(stack({ keys: ['a', 'b', 'c'] }).keys()([])).toEqual(['a', 'b', 'c']);
});
it('value', () => {
expect(stack({ value: () => 1 }).value()({}, '', 1, [])).toEqual(1);
});
it('order', () => {
expect(stack({ order: 'descending' }).order()).toEqual(stackOrderDescending);
});
it('offset', () => {
expect(stack({ offset: 'expand' }).offset()).toEqual(stackOffsetExpand);
});
});
});
15 changes: 15 additions & 0 deletions packages/vx-shape/test/utils/getBandwidth.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { scaleBand, scalePoint, scaleOrdinal } from '@vx/scale';
import getBandwidth from '../../src/util/getBandwidth';

describe('getBandwidth()', () => {
it('returns bandwidth for scales that natively supports', () => {
const scale1 = scaleBand({ domain: ['bacon', 'egg'], range: [0, 100] });
expect(getBandwidth(scale1)).toEqual(50);
const scale2 = scalePoint({ domain: ['bacon', 'egg'], range: [0, 100] });
expect(getBandwidth(scale2)).toEqual(0);
});
it('otherwise compute band from domain and range', () => {
const scale = scaleOrdinal({ domain: ['bacon', 'egg'], range: [0, 100] });
expect(getBandwidth(scale)).toEqual(50);
});
});

0 comments on commit 3afb333

Please sign in to comment.