]> git.ipfire.org Git - thirdparty/Chart.js.git/commitdiff
Improve test coverage (#8087)
authorJukka Kurkela <jukka.kurkela@gmail.com>
Mon, 23 Nov 2020 19:06:16 +0000 (21:06 +0200)
committerGitHub <noreply@github.com>
Mon, 23 Nov 2020 19:06:16 +0000 (21:06 +0200)
* Remove usage of currentStyle (IE only)

* Nothing is registered in root scope anymore

* Add some more tests for animations

* Add some more tests to defaults

src/core/core.typedRegistry.js
src/helpers/helpers.dom.js
test/specs/core.animations.tests.js
test/specs/core.defaults.tests.js [new file with mode: 0644]

index d7435a2638b0288aef195e7deef86f3b3a52283c..0f80b2df42b54a3ecb87bacc294c8044ceb50bca 100644 (file)
@@ -70,8 +70,6 @@ export default class TypedRegistry {
 
                if (scope && id in defaults[scope]) {
                        delete defaults[scope][id];
-               } else if (id in defaults) {
-                       delete defaults[id];
                }
        }
 }
index 50c2654d997c3310a104a44108d1ed3c8bdf8892..9eacb10614422002656820fdb34e646f60f50918 100644 (file)
@@ -34,9 +34,7 @@ function parseMaxStyle(styleValue, node, parentProperty) {
 const getComputedStyle = (element) => window.getComputedStyle(element, null);
 
 export function getStyle(el, property) {
-       return el.currentStyle ?
-               el.currentStyle[property] :
-               getComputedStyle(el).getPropertyValue(property);
+       return getComputedStyle(el).getPropertyValue(property);
 }
 
 const positions = ['top', 'right', 'bottom', 'left'];
index 92cd0e276e2b4dfedce1f77ce7175c77646b7d8a..8e76788dc4e35bb6d9d04f27b8a8d1c4c9e6fb1b 100644 (file)
@@ -44,6 +44,23 @@ describe('Chart.animations', function() {
                })).toBeUndefined();
        });
 
+       it('should assing options directly, if target does not have previous options', function() {
+               const chart = {};
+               const anims = new Chart.Animations(chart, {option: {duration: 200}});
+               const target = {};
+               expect(anims.update(target, {options: {option: 1}})).toBeUndefined();
+       });
+
+       it('should clone the target options, if those are shared and new options are not', function() {
+               const chart = {};
+               const anims = new Chart.Animations(chart, {option: {duration: 200}});
+               const options = {option: 0, $shared: true};
+               const target = {options};
+               expect(anims.update(target, {options: {option: 1}})).toBeTrue();
+               expect(target.options.$shared).not.toBeTrue();
+               expect(target.options !== options).toBeTrue();
+       });
+
        it('should assign shared options to target after animations complete', function(done) {
                const chart = {
                        draw: function() {},
diff --git a/test/specs/core.defaults.tests.js b/test/specs/core.defaults.tests.js
new file mode 100644 (file)
index 0000000..9c1a715
--- /dev/null
@@ -0,0 +1,38 @@
+describe('Chart.defaults', function() {
+       describe('.set', function() {
+               it('Should set defaults directly to root when scope is not provided', function() {
+                       expect(Chart.defaults.test).toBeUndefined();
+                       Chart.defaults.set({test: true});
+                       expect(Chart.defaults.test).toEqual(true);
+                       delete Chart.defaults.test;
+               });
+
+               it('Should create scope when it does not exist', function() {
+                       expect(Chart.defaults.test).toBeUndefined();
+                       Chart.defaults.set('test', {value: true});
+                       expect(Chart.defaults.test.value).toEqual(true);
+                       delete Chart.defaults.test;
+               });
+       });
+
+       describe('.route', function() {
+               it('Should read the source, but not change it', function() {
+                       expect(Chart.defaults.testscope).toBeUndefined();
+
+                       Chart.defaults.set('testscope', {test: true});
+                       Chart.defaults.route('testscope', 'test2', 'testscope', 'test');
+
+                       expect(Chart.defaults.testscope.test).toEqual(true);
+                       expect(Chart.defaults.testscope.test2).toEqual(true);
+
+                       Chart.defaults.set('testscope', {test2: false});
+                       expect(Chart.defaults.testscope.test).toEqual(true);
+                       expect(Chart.defaults.testscope.test2).toEqual(false);
+
+                       Chart.defaults.set('testscope', {test2: undefined});
+                       expect(Chart.defaults.testscope.test2).toEqual(true);
+
+                       delete Chart.defaults.testscope;
+               });
+       });
+});