You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@echarts.apache.org by su...@apache.org on 2020/10/15 16:48:32 UTC

[incubator-echarts] 01/08: test: fix ut: dataZoom

This is an automated email from the ASF dual-hosted git repository.

sushuang pushed a commit to branch fix-ut
in repository https://gitbox.apache.org/repos/asf/incubator-echarts.git

commit bed2ffcc52e08ea28925866fab1094537179d63f
Author: 100pah <su...@gmail.com>
AuthorDate: Wed Oct 14 17:11:37 2020 +0800

    test: fix ut: dataZoom
---
 test/ut/core/utHelper.ts                       |   4 +-
 test/ut/spec/api/getVisual.test.ts             |   1 +
 test/ut/spec/component/dataZoom/helper.test.ts | 142 ++++++++++++-------------
 3 files changed, 72 insertions(+), 75 deletions(-)

diff --git a/test/ut/core/utHelper.ts b/test/ut/core/utHelper.ts
index dcfdb1b..bfedb65 100755
--- a/test/ut/core/utHelper.ts
+++ b/test/ut/core/utHelper.ts
@@ -112,7 +112,7 @@ export function isValueFinite(val: unknown): boolean {
 export function getGraphicElements(
     chartOrGroup: EChartsType | Group,
     mainType: ComponentMainType,
-    index: number
+    index?: number
 ): Element[] {
     if ((chartOrGroup as Group).type === 'group') {
         return (chartOrGroup as Group).children();
@@ -135,7 +135,7 @@ export function getGraphicElements(
 export function getViewGroup(
     chart: EChartsType,
     mainType: ComponentMainType,
-    index: number
+    index?: number
 ): Group {
     const component = chart.getModel().getComponent(mainType, index);
     return component ? chart[
diff --git a/test/ut/spec/api/getVisual.test.ts b/test/ut/spec/api/getVisual.test.ts
index de3d747..c31d2dd 100755
--- a/test/ut/spec/api/getVisual.test.ts
+++ b/test/ut/spec/api/getVisual.test.ts
@@ -37,6 +37,7 @@ describe('api/getVisual', function () {
     afterEach(function () {
         chart.dispose();
     });
+
     it('scatter', function () {
         chart.setOption({
             xAxis: {},
diff --git a/test/ut/spec/component/dataZoom/helper.test.ts b/test/ut/spec/component/dataZoom/helper.test.ts
index 358f3fb..f51da55 100755
--- a/test/ut/spec/component/dataZoom/helper.test.ts
+++ b/test/ut/spec/component/dataZoom/helper.test.ts
@@ -17,91 +17,87 @@
 * specific language governing permissions and limitations
 * under the License.
 */
-const helper = require('../../../../../lib/component/dataZoom/helper');
-const utHelper = require('../../../core/utHelper');
+
+import { findEffectedDataZooms } from '../../../../../src/component/dataZoom/helper';
+import { createChart } from '../../../core/utHelper';
+import { EChartsType } from '../../../../../src/echarts';
+
+
+
 describe('dataZoom/helper', function () {
 
-    function makeRecords(result) {
-        var o = {};
-        helper.eachAxisDim(function (dimNames) {
-            o[dimNames.name] = {};
-            var r = result[dimNames.name] || [];
-            for (var i = 0; i < r.length; i++) {
-                o[dimNames.name][r[i]] = true;
-            }
+    describe('findLinkedNodes', function () {
+
+        let chart: EChartsType;
+        beforeEach(function () {
+            chart = createChart();
         });
-        return o;
-    }
 
-    describe('findLinkedNodes', function () {
+        afterEach(function () {
+            chart.dispose();
+        });
 
-        function forEachModel(models, callback) {
-            for (var i = 0; i < models.length; i++) {
-                callback(models[i]);
-            }
-        }
-
-        function axisIndicesGetter(model, dimNames) {
-            return model[dimNames.axisIndex];
-        }
-
-        it('findLinkedNodes_base', function (done) {
-            var models = [
-                {xAxisIndex: [1, 2], yAxisIndex: [0]},
-                {xAxisIndex: [3], yAxisIndex: [1]},
-                {xAxisIndex: [5], yAxisIndex: []},
-                {xAxisIndex: [2, 5], yAxisIndex: []}
-            ];
-            var result = helper.createLinkedNodesFinder(
-                utHelper.curry(forEachModel, models),
-                helper.eachAxisDim,
-                axisIndicesGetter
-            )(models[0]);
-            expect(result).toEqual({
-                nodes: [models[0], models[3], models[2]],
-                records: makeRecords({x: [1, 2, 5], y: [0]})
+        it('findLinkedNodes_base', function () {
+            chart.setOption({
+                xAxis: [{}, {}, {}, {}, {}, {}],
+                yAxis: [{}, {}, {}, {}, {}, {}],
+                dataZoom: [
+                    { id: 'dz0', xAxisIndex: [1, 2], yAxisIndex: [0] },
+                    { id: 'dz1', xAxisIndex: [3], yAxisIndex: [1] },
+                    { id: 'dz2', xAxisIndex: [5], yAxisIndex: [] },
+                    { id: 'dz3', xAxisIndex: [2, 5], yAxisIndex: [] }
+                ]
             });
-            done();
+
+            const payload = { type: 'dataZoom', dataZoomIndex: 0 };
+            const dzModels = findEffectedDataZooms(chart.getModel(), payload);
+
+            expect(dzModels.length === 3);
+            expect(dzModels[0] === chart.getModel().getComponent('dataZoom', 0)).toEqual(true);
+            expect(dzModels[1] === chart.getModel().getComponent('dataZoom', 3)).toEqual(true);
+            expect(dzModels[2] === chart.getModel().getComponent('dataZoom', 2)).toEqual(true);
         });
 
-        it('findLinkedNodes_crossXY', function (done) {
-            var models = [
-                {xAxisIndex: [1, 2], yAxisIndex: [0]},
-                {xAxisIndex: [3], yAxisIndex: [3, 0]},
-                {xAxisIndex: [6, 3], yAxisIndex: [9]},
-                {xAxisIndex: [5, 3], yAxisIndex: []},
-                {xAxisIndex: [8], yAxisIndex: [4]}
-            ];
-            var result = helper.createLinkedNodesFinder(
-                utHelper.curry(forEachModel, models),
-                helper.eachAxisDim,
-                axisIndicesGetter
-            )(models[0]);
-            expect(result).toEqual({
-                nodes: [models[0], models[1], models[2], models[3]],
-                records: makeRecords({x: [1, 2, 3, 5, 6], y: [0, 3, 9]})
+        it('findLinkedNodes_crossXY', function () {
+            chart.setOption({
+                xAxis: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
+                yAxis: [{}, {}, {}, {}, {}, {}, {}, {}, {}, {}],
+                dataZoom: [
+                    { id: 'dz0', xAxisIndex: [1, 2], yAxisIndex: [0] },
+                    { id: 'dz1', xAxisIndex: [3], yAxisIndex: [3, 0] },
+                    { id: 'dz2', xAxisIndex: [6, 3], yAxisIndex: [9] },
+                    { id: 'dz3', xAxisIndex: [5, 3], yAxisIndex: [] },
+                    { id: 'dz4', xAxisIndex: [8], yAxisIndex: [4] }
+                ]
             });
-            done();
+
+            const payload = { type: 'dataZoom', dataZoomIndex: 0 };
+            const dzModels = findEffectedDataZooms(chart.getModel(), payload);
+
+            expect(dzModels.length === 4);
+            expect(dzModels[0] === chart.getModel().getComponent('dataZoom', 0)).toEqual(true);
+            expect(dzModels[1] === chart.getModel().getComponent('dataZoom', 1)).toEqual(true);
+            expect(dzModels[2] === chart.getModel().getComponent('dataZoom', 2)).toEqual(true);
+            expect(dzModels[3] === chart.getModel().getComponent('dataZoom', 3)).toEqual(true);
         });
 
-        it('findLinkedNodes_emptySourceModel', function (done) {
-            var models = [
-                {xAxisIndex: [1, 2], yAxisIndex: [0]},
-                {xAxisIndex: [3], yAxisIndex: [3, 0]},
-                {xAxisIndex: [6, 3], yAxisIndex: [9]},
-                {xAxisIndex: [5, 3], yAxisIndex: []},
-                {xAxisIndex: [8], yAxisIndex: [4]}
-            ];
-            var result = helper.createLinkedNodesFinder(
-                utHelper.curry(forEachModel, models),
-                helper.eachAxisDim,
-                axisIndicesGetter
-            )();
-            expect(result).toEqual({
-                nodes: [],
-                records: makeRecords({x: [], y: []})
+        it('findLinkedNodes_emptySourceModel', function () {
+            chart.setOption({
+                xAxis: [{}, {}, {}, {}, {}, {}, {}, {}, {}],
+                yAxis: [{}, {}, {}, {}, {}, {}, {}, {}, {}],
+                dataZoom: [
+                    { id: 'dz0', xAxisIndex: [1, 2], yAxisIndex: [0] },
+                    { id: 'dz1', xAxisIndex: [3], yAxisIndex: [3, 0] },
+                    { id: 'dz2', xAxisIndex: [6, 3], yAxisIndex: [9] },
+                    { id: 'dz3', xAxisIndex: [5, 3], yAxisIndex: [] },
+                    { id: 'dz4', xAxisIndex: [8], yAxisIndex: [4] }
+                ]
             });
-            done();
+
+            const payload = { type: 'other' };
+            const dzModels = findEffectedDataZooms(chart.getModel(), payload);
+
+            expect(dzModels.length === 0);
         });
 
     });


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org