Skip to content

Commit

Permalink
test: 提升histogram的测试覆盖率 (#1841)
Browse files Browse the repository at this point in the history
  • Loading branch information
arcsin1 authored Nov 3, 2020
1 parent 63412f0 commit 0ad37a6
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
50 changes: 50 additions & 0 deletions __tests__/unit/plots/histogram/axis-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,31 @@ describe('Histogram: axis', () => {
expect(histogram.chart.options.axes.range.label.style.fill).toBe('red');
});

it('xAxis*false', () => {
const histogram = new Histogram(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data: histogramData,
binField: 'value',
binWidth: 2,
xAxis: false,
});

histogram.render();

// @ts-ignore
expect(histogram.chart.options.axes.count).toEqual({
nice: true,
label: {
autoHide: true,
autoRotate: false,
},
});
// @ts-ignore
expect(histogram.chart.options.axes.range).toEqual(false);
});

it('yAxis', () => {
const histogram = new Histogram(createDiv(), {
width: 400,
Expand All @@ -61,4 +86,29 @@ describe('Histogram: axis', () => {
// @ts-ignore
expect(histogram.chart.options.axes.count.label.style.fill).toBe('red');
});

it('yAxis*false', () => {
const histogram = new Histogram(createDiv(), {
width: 400,
height: 300,
appendPadding: 10,
data: histogramData,
binField: 'value',
binWidth: 2,
yAxis: false,
});

histogram.render();

// @ts-ignore
expect(histogram.chart.options.axes.count).toEqual(false);
// @ts-ignore
expect(histogram.chart.options.axes.range).toEqual({
nice: true,
label: {
autoHide: true,
autoRotate: true,
},
});
});
});
29 changes: 28 additions & 1 deletion __tests__/unit/plots/histogram/index-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ describe('histogram', () => {
const geometry = histogram.chart.geometries[0];
const shapeOrigin = geometry.getShapes()[0].get('origin').data;
expect(shapeOrigin.range[1] - shapeOrigin.range[0]).toBe(2);

const elements = geometry.elements;
expect(elements[0].shape.attr('stroke')).toBe('#FFFFFF');
expect(histogram.chart.getController('legend').visible).toEqual(true);
// @ts-ignore
expect(histogram.chart.getController('legend').components.length).toEqual(0);
// @ts-ignore
expect(histogram.chart.options.axes.count).toEqual({
nice: true,
label: {
autoHide: true,
autoRotate: false,
},
});
// @ts-ignore
expect(histogram.chart.options.axes.range).toEqual({
nice: true,
label: {
autoHide: true,
autoRotate: true,
},
});
});

it('binNumber', () => {
Expand Down Expand Up @@ -82,13 +104,14 @@ describe('histogram', () => {
});

it('stackField: 层叠直方图', () => {
const histogram = new Histogram(createDiv(), {
const histogram = new Histogram(createDiv('legend * true * stackField'), {
width: 400,
height: 300,
appendPadding: 10,
data: histogramStackData,
binField: 'value',
binWidth: 4,
legend: true,
stackField: 'type',
});

Expand All @@ -101,6 +124,10 @@ describe('histogram', () => {
xField: 'range',
yField: 'count',
});
//@ts-ignore
expect(histogram.chart.getController('legend').components[0].extra.scale.field).toEqual('type');
//@ts-ignore
expect(histogram.chart.getController('legend').components.length).toEqual(1);
});

it('stackField with color', () => {
Expand Down

0 comments on commit 0ad37a6

Please sign in to comment.