Skip to content

Commit

Permalink
test: coverage up (#1889)
Browse files Browse the repository at this point in the history
* test: sunburst hierarchy util

* test: scatter util

* test: sunburst hierarchy partition
  • Loading branch information
hustcc authored Nov 10, 2020
1 parent 825b7f4 commit 2d33fbb
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 5 deletions.
29 changes: 27 additions & 2 deletions __tests__/unit/plots/scatter/regression-line-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('scatter', () => {
});

scatter.render();
await delay(500);
await delay(100);
const geometry = scatter.chart.geometries[0];
const annotation = scatter.chart.annotation();
// @ts-ignore
Expand Down Expand Up @@ -150,7 +150,7 @@ describe('scatter', () => {
});

scatter.render();
await delay(500);
await delay(100);
const { width } = scatter.chart;
const pathGroup = scatter.chart
.getComponents()
Expand All @@ -162,4 +162,29 @@ describe('scatter', () => {

scatter.destroy();
});

it('regressionLine: nonealgorithm', async () => {
const scatter = new Scatter(createDiv('regressionLine*algorithm'), {
data,
width: 400,
height: 300,
appendPadding: 10,
xField: 'x',
yField: 'y',
size: 5,
animation: false,
regressionLine: {},
});

scatter.render();
await delay(100);
const pathGroup = scatter.chart
.getComponents()
.find((item) => item.type === 'annotation')
.component.cfg.group.cfg.children[0].getChildren();
const { path } = pathGroup?.[0]?.cfg?.attrs;
expect(path.length).toBe(2); // linear

scatter.destroy();
});
});
19 changes: 19 additions & 0 deletions __tests__/unit/plots/sunburst/hierarchy/partition-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { partition } from '../../../../../src/plots/sunburst/hierarchy/partition';

describe('hierarchy/partition', () => {
it('partition', () => {
expect(() => {
// @ts-ignore
partition([], {
as: null,
});
}).toThrow(`Invalid as: it must be an array with 2 strings (e.g. [ "x", "y" ])!`);

expect(() => {
partition([], {
// @ts-ignore
as: ['x', 'y', 'z'],
});
}).toThrow(`Invalid as: it must be an array with 2 strings (e.g. [ "x", "y" ])!`);
});
});
83 changes: 83 additions & 0 deletions __tests__/unit/plots/sunburst/hierarchy/util-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { getField, getAllNodes } from '../../../../../src/plots/sunburst/hierarchy/util';

describe('hierarchy/util', () => {
it('getField', () => {
expect(
getField({
field: '',
fields: ['b', 'c'],
})
).toBe('');

expect(
getField({
field: 'a',
fields: ['b', 'c'],
})
).toBe('a');

expect(
getField({
field: ['a'],
fields: ['b', 'c'],
})
).toBe('a');

expect(
getField({
field: [],
fields: ['b', 'c'],
})
).toBe(undefined);

expect(
getField({
field: undefined,
fields: 'b',
})
).toBe('b');

expect(
getField({
field: undefined,
fields: ['b', 'c'],
})
).toBe('b');

expect(
getField(
{
field: null,
fields: [],
},
'c'
)
).toBe('c');

expect(() => {
getField({
field: null,
fields: [],
});
}).toThrow();
});

it('getAllNodes', () => {
expect(getAllNodes(null)).toEqual([]);

expect(getAllNodes({ a: 1 })).toEqual([]);

const nodes = ['a', 'b', 'c'];
expect(
getAllNodes({
each: (loop) => nodes.forEach(loop),
})
).toEqual(nodes);

expect(
getAllNodes({
eachNode: (loop) => nodes.forEach(loop),
})
).toEqual(nodes);
});
});
6 changes: 3 additions & 3 deletions src/plots/scatter/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const REGRESSION_MAP = {
quad: regressionQuad,
};

type renderOptions = {
type RenderOptions = {
view: View;
options: ScatterOptions;
};
Expand Down Expand Up @@ -133,7 +133,7 @@ export function getQuadrantDefaultConfig(xBaseline: number, yBaseline: number) {
return defaultConfig;
}

const splinePath = (data: number[][], config: renderOptions) => {
const splinePath = (data: number[][], config: RenderOptions) => {
const {
view,
options: { xField, yField },
Expand All @@ -146,7 +146,7 @@ const splinePath = (data: number[][], config: renderOptions) => {
return getSplinePath(pathData, false);
};

export const getPath = (config: renderOptions) => {
export const getPath = (config: RenderOptions) => {
const { options } = config;
const { xField, yField, data, regressionLine } = options;
const { type = 'linear', algorithm } = regressionLine;
Expand Down

0 comments on commit 2d33fbb

Please sign in to comment.