Skip to content

Conversation

@loicbourgois
Copy link
Contributor

As discussed in #5134, a PR to add tests for scatter charts.
It tests for 3 values of showLines : default value, true, false.

@@ -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() {
    // ...

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.

@simonbrunel
Copy link
Member

simonbrunel commented Jan 14, 2018

To be consistent, we should add the same tests for the line controller, or better we could move these tests in controller.line.tests.js and in controller.scatter.tests.js only check the default options since scatter is a line controller.

@loicbourgois
Copy link
Contributor Author

loicbourgois commented Jan 14, 2018

controller.line.tests.js seems to already have those tests : https://github.com/chartjs/Chart.js/blob/master/test/specs/controller.line.tests.js#L70
But isn't it the other way around, shouldn't we add all the tests present in controller.line.tests.js to controller.scatter.tests.js ?
If the behavior is changed in the controller.scatter.js directly, then tests in contoller.lines.js won't be applied (which is why the tests didn't fail when i pushed for the PR for mixed chart i think).
And the reverse is true too : if contoller.lines.js is changed and its tests are updated, then it would be good to validate that the new correct behavior for lines is also valid for scatter ?

@simonbrunel
Copy link
Member

That would make maintaining those tests more complicated because the code is currently exactly the same, only defaults are different. If we update the behavior of the line controller, we would need to update tests in both files. I would only implement tests that differs from the line controller. If the behavior is changed in scatter as you did in your other PR, then we will add (duplicate?) tests associated to that behavior.

I would simply make sure that showLines is correctly tested in controller.line.tests.js, then add tests in controller.scatter.js for the scatter specific defaults.

@loicbourgois
Copy link
Contributor Author

I removed data, nested the test under 'showLines' and removed duplicated tests.
controller.line.tests.js already tests for true and false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants