Skip to content

Commit

Permalink
chore: use jest-electron for unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lessmost committed Nov 12, 2019
1 parent cffdf54 commit a42d508
Show file tree
Hide file tree
Showing 51 changed files with 554 additions and 598 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 0 additions & 46 deletions __tests__/data/radar.js-

This file was deleted.

File renamed without changes.
85 changes: 42 additions & 43 deletions __tests__/unit/area-spec.js → __tests__/unit/area-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Area, StackArea } from '../../src';
import { expect } from 'chai';

const data = [
{
Expand Down Expand Up @@ -314,12 +313,12 @@ describe('Area plot', () => {
const positionField = view.get('elements')[0].get('position').fields;
const axes = view.get('axisController').axes;

expect(areaPlot).to.be.instanceOf(Area);
expect(positionField[0]).to.be.equal('year');
expect(positionField[1]).to.be.equal('value');
expect(axes.length).to.be.equal(2);
expect(areaPlot). toBeInstanceOf(Area);
expect(positionField[0]).toBe('year');
expect(positionField[1]).toBe('value');
expect(axes.length).toBe(2);
areaPlot.destroy();
expect(view.destroyed).to.be.true;
expect(view.destroyed).toBe(true);
});

it('area style', () => {
Expand Down Expand Up @@ -364,10 +363,10 @@ describe('Area plot', () => {
areaPlot.render();
const view = areaPlot.getLayer().view;
const elements = view.get('elements');
expect(elements[0].get('type')).to.be.equal('area');
expect(elements[0].get('style').cfg.strokeStyle).to.be.equal('black');
expect(elements[0].get('type')).toBe('area');
expect(elements[0].get('style').cfg.strokeStyle).toBe('black');
areaPlot.destroy();
expect(view.destroyed).to.be.true;
expect(view.destroyed).toBe(true);
});

it('line shape attr map', () => {
Expand Down Expand Up @@ -399,11 +398,11 @@ describe('Area plot', () => {
areaPlot.render();
const view = areaPlot.getLayer().view;
const elements = view.get('elements');
expect(elements[1].get('type')).to.be.equal('line');
expect(elements[1].get('size').values[0]).to.be.equal(6);
expect(elements[1].get('color').values[0]).to.be.equal('pink');
expect(elements[1].get('type')).toBe('line');
expect(elements[1].get('size').values[0]).toBe(6);
expect(elements[1].get('color').values[0]).toBe('pink');
areaPlot.destroy();
expect(view.destroyed).to.be.true;
expect(view.destroyed).toBe(true);
});

it('line style obj', () => {
Expand Down Expand Up @@ -448,11 +447,11 @@ describe('Area plot', () => {
areaPlot.render();
const view = areaPlot.getLayer().view;
const elements = view.get('elements');
expect(elements[1].get('type')).to.be.equal('line');
expect(elements[1].get('size').values[0]).to.be.equal(6);
expect(elements[1].get('style').cfg.color).to.be.equal('blue');
expect(elements[1].get('type')).toBe('line');
expect(elements[1].get('size').values[0]).toBe(6);
expect(elements[1].get('style').cfg.color).toBe('blue');
areaPlot.destroy();
expect(view.destroyed).to.be.true;
expect(view.destroyed).toBe(true);
});

// it('line style func', () => {
Expand Down Expand Up @@ -498,12 +497,12 @@ describe('Area plot', () => {
// const positionField = areaPlot.plot.get('elements')[0].get('position').fields;
// const axes = areaPlot.plot.get('axisController').axes;

// expect(areaPlot).to.be.instanceOf(Area);
// expect(positionField[0]).to.be.equal('year');
// expect(positionField[1]).to.be.equal('value');
// expect(axes.length).to.be.equal(2);
// expect(areaPlot). toBeInstanceOf(Area);
// expect(positionField[0]).toBe('year');
// expect(positionField[1]).toBe('value');
// expect(axes.length).toBe(2);
// // areaPlot.destroy();
// // expect(areaPlot.plot.destroyed).to.be.true;
// // expect(areaPlot.plot.destroyed).toBe(true);
// });

it('point shape attr map', () => {
Expand Down Expand Up @@ -543,14 +542,14 @@ describe('Area plot', () => {
areaPlot.render();
const view = areaPlot.getLayer().view;
const elements = view.get('elements');
expect(elements[1].get('type')).to.be.equal('line');
expect(elements[1].get('size').values[0]).to.be.equal(6);
expect(elements[1].get('style').cfg.strokeStyle).to.be.equal('blue');
expect(elements[2].get('type')).to.be.equal('point');
expect(elements[2].get('size').values[0]).to.be.equal(8);
expect(elements[2].get('color').values[0]).to.be.equal('yellow');
expect(elements[1].get('type')).toBe('line');
expect(elements[1].get('size').values[0]).toBe(6);
expect(elements[1].get('style').cfg.strokeStyle).toBe('blue');
expect(elements[2].get('type')).toBe('point');
expect(elements[2].get('size').values[0]).toBe(8);
expect(elements[2].get('color').values[0]).toBe('yellow');
areaPlot.destroy();
expect(view.destroyed).to.be.true;
expect(view.destroyed).toBe(true);
});

it.skip('point style obj', () => {
Expand Down Expand Up @@ -596,14 +595,14 @@ describe('Area plot', () => {
});
areaPlot.render();
const elements = areaPlot.getLayer().view.get('elements');
expect(elements[1].get('type')).to.be.equal('line');
expect(elements[1].get('size').values[0]).to.be.equal(6);
expect(elements[1].get('style').cfg.strokeStyle).to.be.equal('blue');
expect(elements[2].get('type')).to.be.equal('point');
expect(elements[2].get('size').values[0]).to.be.equal(8);
expect(elements[2].get('style').cfg.fillStyle).to.be.equal('red');
expect(elements[1].get('type')).toBe('line');
expect(elements[1].get('size').values[0]).toBe(6);
expect(elements[1].get('style').cfg.strokeStyle).toBe('blue');
expect(elements[2].get('type')).toBe('point');
expect(elements[2].get('size').values[0]).toBe(8);
expect(elements[2].get('style').cfg.fillStyle).toBe('red');
areaPlot.destroy();
expect(areaPlot.plot.destroyed).to.be.true;
expect(areaPlot.plot.destroyed).toBe(true);
});

it('area seriesField', () => {
Expand Down Expand Up @@ -651,11 +650,11 @@ describe('Area plot', () => {
areaPlot.render();
const view = areaPlot.getLayer().view;
const elements = view.get('elements');
expect(elements[0].get('type')).to.be.equal('area');
expect(elements[0].get('color').values[0]).to.be.equal('green');
expect(elements[0].get('color').fields[0]).to.be.equal('type');
expect(elements[0].get('type')).toBe('area');
expect(elements[0].get('color').values[0]).toBe('green');
expect(elements[0].get('color').fields[0]).toBe('type');
areaPlot.destroy();
expect(view.destroyed).to.be.true;
expect(view.destroyed).toBe(true);
});
});

Expand Down Expand Up @@ -685,9 +684,9 @@ describe('Area plot', () => {
const legend = plot.get('legendController').legends[0];
const area = plot.get('elements')[0];

expect(legend.get('position')).to.be.equal('top-left');
expect(legend.get('wordSpacing')).to.be.equal(4);
expect(area.get('styleOptions').cfg.opacity).to.be.equal(0.25);
expect(legend.get('position')).toBe('top-left');
expect(legend.get('wordSpacing')).toBe(4);
expect(area.get('styleOptions').cfg.opacity).toBe(0.25);
areaPlot.destroy();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ describe.skip('stackArea label', () => {
// const isTransposed = areaPlot.plot.get('coord').isTransposed;
// const axes = areaPlot.plot.get('axisController').axes;

// expect(areaPlot).to.be.instanceOf(Area);
// expect(positionField[0]).to.be.equal('value');
// expect(positionField[1]).to.be.equal('year');
// expect(isTransposed).to.be.equal(false);
// expect(axes.length).to.be.equal(2);
// expect(areaPlot). toBeInstanceOf(Area);
// expect(positionField[0]).toBe('value');
// expect(positionField[1]).toBe('year');
// expect(isTransposed).toBe(false);
// expect(axes.length).toBe(2);
// areaPlot.destroy();
// expect(areaPlot.plot.destroyed).to.be.true;
// expect(areaPlot.plot.destroyed).toBe(true);
});
});
79 changes: 39 additions & 40 deletions __tests__/unit/bar-spec.js → __tests__/unit/bar-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Bar } from '../../src';
import { expect } from 'chai';

describe('Bar plot', () => {
const canvasDiv = document.createElement('div');
Expand Down Expand Up @@ -71,13 +70,13 @@ describe('Bar plot', () => {
const isTransposed = plot.get('coord').isTransposed;
const axes = plot.get('axisController').axes;

expect(barPlot).to.be.instanceOf(Bar);
expect(positionField[0]).to.be.equal('year');
expect(positionField[1]).to.be.equal('value');
expect(isTransposed).to.be.equal(true);
expect(axes.length).to.be.equal(2);
expect(barPlot).toBeInstanceOf(Bar);
expect(positionField[0]).toBe('year');
expect(positionField[1]).toBe('value');
expect(isTransposed).toBe(true);
expect(axes.length).toBe(2);
barPlot.destroy();
expect(plot.destroyed).to.be.true;
expect(plot.destroyed).toBe(true);
});

it.skip('柱子样式配置', () => {
Expand All @@ -103,11 +102,11 @@ describe('Bar plot', () => {
});
barPlot.render();
const barEle = barPlot.plot.get('elements')[0];
expect(barEle.get('color').values[0]).to.be.equal('red');
expect(barEle.get('style').cfg.stroke).to.be.equal('black');
expect(barEle.get('size').values[0]).to.be.equal(20);
expect(barEle.get('color').values[0]).toBe('red');
expect(barEle.get('style').cfg.stroke).toBe('black');
expect(barEle.get('size').values[0]).toBe(20);
barPlot.destroy();
expect(barPlot.plot.destroyed).to.be.true;
expect(barPlot.plot.destroyed).toBe(true);
});

it.skip('每个柱子颜色不一样', () => {
Expand All @@ -128,10 +127,10 @@ describe('Bar plot', () => {
});
barPlot.render();
const barEle = barPlot.plot.get('elements')[0];
expect(barEle.get('color').values[0]).to.be.equal('red');
expect(barEle.get('color').values[1]).to.be.equal('blue');
expect(barEle.get('color').values[0]).toBe('red');
expect(barEle.get('color').values[1]).toBe('blue');
barPlot.destroy();
expect(barPlot.plot.destroyed).to.be.true;
expect(barPlot.plot.destroyed).toBe(true);
});

it('隐藏两个坐标轴', () => {
Expand All @@ -152,9 +151,9 @@ describe('Bar plot', () => {
barPlot.render();
const plot = barPlot.getLayer().view;
const axes = plot.get('axisController').axes;
expect(axes.length).to.be.equal(0);
expect(axes.length).toBe(0);
barPlot.destroy();
expect(plot.destroyed).to.be.true;
expect(plot.destroyed).toBe(true);
});

it('x轴 样式', () => {
Expand Down Expand Up @@ -203,20 +202,20 @@ describe('Bar plot', () => {
barPlot.render();
const plot = barPlot.getLayer().view;
const axes = plot.get('axisController').axes;
expect(axes.length).to.be.equal(1);
expect(axes.length).toBe(1);
const axis = axes[0];
expect(axis.get('title').text).to.be.include('xxxx');
expect(axis.get('title').textStyle.fill).to.be.equal('red');
expect(axis.get('title').text).toInclude('xxxx');
expect(axis.get('title').textStyle.fill).toBe('red');
const labels = axis.get('labelItems');
expect(labels[0].text).to.be.include('abc');
expect(labels[0].text).toInclude('abc');
// style
const line = axis.get('line');
const tickLine = axis.get('tickLine');
expect(line.stroke).to.be.equal('red');
expect(tickLine.stroke).to.be.equal('red');
expect(labels[0].textStyle.fill).to.be.equal('red');
expect(line.stroke).toBe('red');
expect(tickLine.stroke).toBe('red');
expect(labels[0].textStyle.fill).toBe('red');
barPlot.destroy();
expect(plot.destroyed).to.be.true;
expect(plot.destroyed).toBe(true);
});

it('x轴 隐藏 grid line tick label', () => {
Expand Down Expand Up @@ -249,15 +248,15 @@ describe('Bar plot', () => {
barPlot.render();
const plot = barPlot.getLayer().view;
const axes = plot.get('axisController').axes;
expect(axes.length).to.be.equal(1);
expect(axes.length).toBe(1);
const axis = axes[0];
// style
const line = axis.get('line');
const tickLine = axis.get('tickLine');
expect(line).to.be.equal(null);
expect(tickLine).to.be.equal(null);
expect(line).toBe(null);
expect(tickLine).toBe(null);
barPlot.destroy();
expect(plot.destroyed).to.be.true;
expect(plot.destroyed).toBe(true);
});

it('y轴 样式', () => {
Expand Down Expand Up @@ -309,20 +308,20 @@ describe('Bar plot', () => {
barPlot.render();
const plot = barPlot.getLayer().view;
const axes = plot.get('axisController').axes;
expect(axes.length).to.be.equal(1);
expect(axes.length).toBe(1);
const axis = axes[0];
const labels = axis.get('labelItems');
expect(axis.get('title').text).to.be.include('year');
expect(axis.get('title').textStyle.fill).to.be.equal('red');
expect(labels[0].text).to.be.include('abc');
expect(axis.get('title').text).toInclude('year');
expect(axis.get('title').textStyle.fill).toBe('red');
expect(labels[0].text).toInclude('abc');
// style
const line = axis.get('line');
const tickLine = axis.get('tickLine');
expect(line.stroke).to.be.equal('red');
expect(tickLine.stroke).to.be.equal('red');
expect(labels[0].textStyle.fill).to.be.equal('red');
expect(line.stroke).toBe('red');
expect(tickLine.stroke).toBe('red');
expect(labels[0].textStyle.fill).toBe('red');
barPlot.destroy();
expect(plot.destroyed).to.be.true;
expect(plot.destroyed).toBe(true);
});

it('y轴 隐藏 grid line tick label', () => {
Expand Down Expand Up @@ -354,14 +353,14 @@ describe('Bar plot', () => {
barPlot.render();
const plot = barPlot.getLayer().view;
const axes = plot.get('axisController').axes;
expect(axes.length).to.be.equal(1);
expect(axes.length).toBe(1);
const axis = axes[0];
// style
const line = axis.get('line');
const tickLine = axis.get('tickLine');
expect(line).to.be.equal(null);
expect(tickLine).to.be.equal(null);
expect(line).toBe(null);
expect(tickLine).toBe(null);
barPlot.destroy();
expect(plot.destroyed).to.be.true;
expect(plot.destroyed).toBe(true);
});
});
Loading

0 comments on commit a42d508

Please sign in to comment.