Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests related to showLines for controller.scatter #5150

Merged
merged 6 commits into from Jan 16, 2018
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
115 changes: 115 additions & 0 deletions test/specs/controller.scatter.test.js
@@ -0,0 +1,115 @@
describe('Chart.controllers.scatter', function() {

it('should not draw a line if the options showLines is not set', function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you nest all these tests under showLines option:

describe('Chart.controllers.scatter', function() {
  describe('showLines option', function() {
    it('should not draw a line if undefined', function() {
    // ...
    it('should not draw a line if false', function() {
    // ...
    it('should draw a line if true', function() {
    // ...

var chart = window.acquireChart({
type: 'scatter',
data: {
datasets: [{
data: [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need so much data, maybe one is enough data: [{x: 10, y: 15}] since we are not verifying how the line is drawing but only if the method is called. That would make all tests shorter.

{x: 10, y: 15},
{x: 0, y: -8},
{x: -50, y: -6},
{x: 12, y: -4},
{x: -9, y: 8}
],
label: 'dataset1'
}],
},
options: {}
});

var meta = chart.getDatasetMeta(0);
spyOn(meta.dataset, 'draw');
spyOn(meta.data[0], 'draw');
spyOn(meta.data[1], 'draw');
spyOn(meta.data[2], 'draw');
spyOn(meta.data[3], 'draw');
spyOn(meta.data[4], 'draw');

chart.update();

expect(meta.dataset.draw.calls.count()).toBe(0);
expect(meta.data[0].draw.calls.count()).toBe(1);
expect(meta.data[1].draw.calls.count()).toBe(1);
expect(meta.data[2].draw.calls.count()).toBe(1);
expect(meta.data[3].draw.calls.count()).toBe(1);
expect(meta.data[4].draw.calls.count()).toBe(1);
});

it('should not draw a line if the options showLines set to false', function() {
var chart = window.acquireChart({
type: 'scatter',
data: {
datasets: [{
data: [
{x: 10, y: 15},
{x: 0, y: -8},
{x: -50, y: -6},
{x: 12, y: -4},
{x: -9, y: 8}
],
label: 'dataset1'
}],
},
options: {
showLines: false
}
});

var meta = chart.getDatasetMeta(0);
spyOn(meta.dataset, 'draw');
spyOn(meta.data[0], 'draw');
spyOn(meta.data[1], 'draw');
spyOn(meta.data[2], 'draw');
spyOn(meta.data[3], 'draw');
spyOn(meta.data[4], 'draw');

chart.update();

expect(meta.dataset.draw.calls.count()).toBe(0);
expect(meta.data[0].draw.calls.count()).toBe(1);
expect(meta.data[1].draw.calls.count()).toBe(1);
expect(meta.data[2].draw.calls.count()).toBe(1);
expect(meta.data[3].draw.calls.count()).toBe(1);
expect(meta.data[4].draw.calls.count()).toBe(1);
});

it('should draw a line if the options showLines is set to true', function() {
var chart = window.acquireChart({
type: 'scatter',
data: {
datasets: [{
data: [
{x: 10, y: 15},
{x: 0, y: -8},
{x: -50, y: -6},
{x: 12, y: -4},
{x: -9, y: 8}
],
label: 'dataset1'
}],
},
options: {
showLines: true
}
});

var meta = chart.getDatasetMeta(0);
spyOn(meta.dataset, 'draw');
spyOn(meta.data[0], 'draw');
spyOn(meta.data[1], 'draw');
spyOn(meta.data[2], 'draw');
spyOn(meta.data[3], 'draw');
spyOn(meta.data[4], 'draw');

chart.update();

expect(meta.dataset.draw.calls.count()).toBe(1);
expect(meta.data[0].draw.calls.count()).toBe(1);
expect(meta.data[1].draw.calls.count()).toBe(1);
expect(meta.data[2].draw.calls.count()).toBe(1);
expect(meta.data[3].draw.calls.count()).toBe(1);
expect(meta.data[4].draw.calls.count()).toBe(1);
});

});