Skip to content

Conversation

@andig
Copy link
Contributor

@andig andig commented Aug 25, 2017

Follow-up to #4694 (comment)

@simonbrunel your suggestion seems to work- no regression with the bar tests. Please have a careful look at doughnut and polar tests- I'm not sure, not having experience with those charts, that the value changes are plausible.

@simonbrunel
Copy link
Member

simonbrunel commented Aug 25, 2017

That's right that the doughnut and polar expectations looks weird (0 for innerRadius / outerRadius). Did you try to put a debugger; before the expectations to see what the chart looks like?

While working on the chartjs-plugin-datalabels, I noticed that setting Chart.defaults.global.label: false didn't work with doughnut charts, I need to set Chart.defaults.global.label.display: false so might be the same issue. Also, could be even better to completely turn off the plugins instead:

options: {
  plugins: {
    legend: false,
    title: false
  }
}

@etimberg
Copy link
Member

Yeah, the 0 size looks wrong :/

@andig
Copy link
Contributor Author

andig commented Aug 26, 2017

While working on the chartjs-plugin-datalabels, I noticed that setting Chart.defaults.global.label: false didn't work with doughnut charts, I need to set Chart.defaults.global.label.display: false so might be the same issue. Also, could be even better to completely turn off the plugins instead:

Did just a quick test now (and thanks for the debugger; hint, didn't know about it)- with either global.title = false or global.legend = false even the most simple doughnot test (create arcs) doesn't run.

@andig
Copy link
Contributor Author

andig commented Aug 26, 2017

@simonbrunel should be complete now.

Copy link
Member

@etimberg etimberg left a comment

Choose a reason for hiding this comment

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

I'm guessing the error with the doughnut and polar area charts is due to

target[key] = helpers.clone(sval);
because the defaults for those chart types have legend options. This means that they would still get applied but the global defaults would be wiped out so it would have invalid options

@simonbrunel
Copy link
Member

@etimberg good catch, not sure if it's fixable to allow user to do Chart.defaults.global.legend: false (a workaround is to disable plugins instead).

The last failure was caused by the merge in afterAll: Chart.defaults.global.plugin.legend is initially undefined (so not present in the cloned this._defaults). When merging back the saved defaults, Chart.defaults.global.plugin.legend remained unchanged (false) for other unit tests.

It's not possible to fully change the Chart.defaults because internal code will still use the previous reference, so can't simply do Chart.defaults = this._defaults in afterAll. One solution (a bit tricky) consists to use a custom merger that returns the previous overwritten values:

this._defaults = jasmine.overrideDefaults({
  global: {
    plugins: {
      legend: false,
      title: false
    }
  }
});

/*
this._defaults === {
  global: {
    plugins: {
      legend: undefined,
      title: undefined
    }
  }
}
*/

Manipulating defaults in unit tests is not safe since it impacts all specs. If you prefer to not touch the defaults, then we will need to inject that options for every acquireChart (more repetitive work but maybe cleaner?!).

@andig
Copy link
Contributor Author

andig commented Aug 27, 2017

You've lost me in the discussion but thanks ok since you can perform the additional updates as desired.

@simonbrunel
Copy link
Member

I finally think it's better to not rely on defaults to globally disable plugins / hide scales but instead inject these options while acquiring charts. Altering global defaults is not safe and is error prone since we don't really know what are the current options for every tests.

I'm going to update the PR with these changes.

@simonbrunel
Copy link
Member

@etimberg @andig can you guys have another look over this PR?

@andig
Copy link
Contributor Author

andig commented Aug 27, 2017

I‘m not sure. May of the tests af simply changed order of chart specs now. Axes are often no longer hidden. Although that might not be required it would make the tests easier to update on future changes?

@simonbrunel
Copy link
Member

I didn't understand your first sentence: I simply removed the beforeAll / afterAll and locally disable plugins / hide scale for failing tests only. Tests that don't check (pixel) position actually don't need these tweaks.

@andig
Copy link
Contributor Author

andig commented Aug 27, 2017

I meant these occasions https://github.com/chartjs/Chart.js/pull/4698/files#diff-b4730e5a7a6104600b439e9b30fc34afR826 and following. It may be better going back to the first commit, cleaning these out and force-push?

@simonbrunel
Copy link
Member

I changed it to keep the order consistent between all tests. Not sure what the issue with changing the properties order, but up to you if you want to revert it, I will not have time to iterate more on this PR.

@andig
Copy link
Contributor Author

andig commented Aug 27, 2017

No, fine with me. Just thought you might want to keep the changes minimal and didn‘t notice since th initial change resulted from my commit. No problem with cutting the losses on this one :)

@simonbrunel simonbrunel added this to the Version 2.7 milestone Aug 27, 2017
@simonbrunel simonbrunel merged commit 2f950e2 into chartjs:master Aug 27, 2017
@simonbrunel simonbrunel deleted the test-stability branch August 27, 2017 20:43
yofreke pushed a commit to yofreke/Chart.js that referenced this pull request Dec 30, 2017
exwm pushed a commit to exwm/Chart.js that referenced this pull request Apr 30, 2021
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.

3 participants