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/14 08:10:16 UTC
[incubator-echarts] 06/08: fix: fix ut and fix getViusal bug
brought by some of the 5.0 refactor.
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 9f69525f98828e87bde25118cac6412c48676220
Author: 100pah <su...@gmail.com>
AuthorDate: Wed Oct 14 00:50:16 2020 +0800
fix: fix ut and fix getViusal bug brought by some of the 5.0 refactor.
---
package.json | 7 +++--
src/util/model.ts | 17 +++++++++--
test/ut/.eslintrc.yaml | 2 +-
test/ut/core/utHelper.ts | 9 +++---
test/ut/spec/api/converter.test.ts | 61 +++++++++++++++++++++++++++-----------
test/ut/spec/api/getVisual.test.ts | 48 +++++++++++-------------------
test/ut/tsconfig.json | 1 +
7 files changed, 87 insertions(+), 58 deletions(-)
diff --git a/package.json b/package.json
index ac87f3e..dc5d55f 100644
--- a/package.json
+++ b/package.json
@@ -27,7 +27,7 @@
"help": "node build/build.js --help",
"test:visual": "node test/runTest/server.js",
"test:visual:report": "node test/runTest/genReport.js",
- "test": "node build/build.js --prepublish && jest --config test/ut/jest.config.js",
+ "test": "jest --config test/ut/jest.config.js",
"test:single": "jest --config test/ut/jest.config.js --coverage=false -t",
"mktest": "node test/build/mktest.js",
"mktest:help": "node test/build/mktest.js -h",
@@ -42,9 +42,10 @@
"@babel/core": "7.3.4",
"@babel/types": "^7.10.5",
"@microsoft/api-extractor": "7.7.2",
+ "@types/jest": "^26.0.14",
+ "@types/jsdom": "^16.2.4",
"@typescript-eslint/eslint-plugin": "^2.15.0",
"@typescript-eslint/parser": "^2.18.0",
- "husky": "^4.2.5",
"canvas": "^2.6.0",
"chalk": "^3.0.0",
"chokidar": "^3.4.0",
@@ -54,6 +55,7 @@
"fs-extra": "0.26.7",
"glob": "7.0.0",
"globby": "11.0.0",
+ "husky": "^4.2.5",
"jest": "^24.9.0",
"jest-canvas-mock": "^2.2.0",
"jsdom": "^15.2.1",
@@ -71,6 +73,7 @@
"serve-handler": "6.1.1",
"slugify": "1.3.4",
"socket.io": "2.2.0",
+ "ts-jest": "^26.4.1",
"typescript": "3.8.3",
"uglify-js": "^3.10.0"
}
diff --git a/src/util/model.ts b/src/util/model.ts
index 972373f..35af503 100644
--- a/src/util/model.ts
+++ b/src/util/model.ts
@@ -795,7 +795,12 @@ export type ParsedModelFinder = ParsedModelFinderKnown & {
export function parseFinder(
ecModel: GlobalModel,
finderInput: ModelFinder,
- opt?: {defaultMainType?: ComponentMainType, includeMainTypes?: ComponentMainType[]}
+ opt?: {
+ // If no main type specified, use this main type.
+ defaultMainType?: ComponentMainType,
+ // If pervided, types out of this list will be ignored.
+ includeMainTypes?: ComponentMainType[]
+ }
): ParsedModelFinder {
let finder: ModelFinderObject;
if (isString(finderInput)) {
@@ -807,9 +812,9 @@ export function parseFinder(
finder = finderInput;
}
- const defaultMainType = opt ? opt.defaultMainType : null;
const queryOptionMap = createHashMap<QueryReferringUserOption, ComponentMainType>();
const result = {} as ParsedModelFinder;
+ let mainTypeSpecified = false;
each(finder, function (value, key) {
// Exclude 'dataIndex' and other illgal keys.
@@ -825,16 +830,22 @@ export function parseFinder(
if (
!mainType
|| !queryType
- || (mainType !== defaultMainType && value == null)
|| (opt && opt.includeMainTypes && indexOf(opt.includeMainTypes, mainType) < 0)
) {
return;
}
+ mainTypeSpecified = mainTypeSpecified || !!mainType;
+
const queryOption = queryOptionMap.get(mainType) || queryOptionMap.set(mainType, {});
queryOption[queryType] = value as any;
});
+ const defaultMainType = opt ? opt.defaultMainType : null;
+ if (!mainTypeSpecified && defaultMainType) {
+ queryOptionMap.set(defaultMainType, {});
+ }
+
queryOptionMap.each(function (queryOption, mainType) {
const queryResult = queryReferringComponents(
ecModel,
diff --git a/test/ut/.eslintrc.yaml b/test/ut/.eslintrc.yaml
index eadd55a..d906da2 100644
--- a/test/ut/.eslintrc.yaml
+++ b/test/ut/.eslintrc.yaml
@@ -19,7 +19,7 @@ parserOptions:
project: "test/ut/tsconfig.json"
plugins: ["@typescript-eslint"]
env:
- browser: false
+ browser: true
node: true
es6: false
globals:
diff --git a/test/ut/core/utHelper.ts b/test/ut/core/utHelper.ts
index 509438c..38eadad 100755
--- a/test/ut/core/utHelper.ts
+++ b/test/ut/core/utHelper.ts
@@ -31,12 +31,13 @@ import Group from 'zrender/src/graphic/Group';
import Element from 'zrender/src/Element';
-export function createChart(params: {
+export function createChart(params?: {
width?: number,
height?: number,
theme?: Parameters<typeof init>[1],
opts?: Parameters<typeof init>[2]
}): EChartsType {
+ params = params || {};
const el = document.createElement('div');
el.style.cssText = [
'visibility:hidden',
@@ -61,7 +62,7 @@ export function g(id: string): HTMLElement {
}
export function removeEl(el: HTMLElement): void {
- const parent = utHelper.parentEl(el);
+ const parent = parentEl(el);
parent && parent.removeChild(el);
}
@@ -119,9 +120,9 @@ export function getGraphicElements(
return (chartOrGroup as Group).children();
}
else {
- const viewGroup = utHelper.getViewGroup(chartOrGroup, mainType, index);
+ const viewGroup = getViewGroup(chartOrGroup, mainType, index);
if (viewGroup) {
- const list = [viewGroup];
+ const list: Element[] = [viewGroup];
viewGroup.traverse(function (el: Element) {
list.push(el);
});
diff --git a/test/ut/spec/api/converter.test.ts b/test/ut/spec/api/converter.test.ts
index 4183ab3..0e7def4 100755
--- a/test/ut/spec/api/converter.test.ts
+++ b/test/ut/spec/api/converter.test.ts
@@ -1,4 +1,3 @@
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -21,19 +20,23 @@
import { EChartsType, registerMap } from '../../../../src/echarts';
import { GeoJSON } from '../../../../src/coord/geo/geoTypes';
+import { createChart } from '../../core/utHelper';
describe('api/converter', function () {
const DELTA = 1E-3;
- function pointEquals(p1, p2) {
+ function pointEquals(p1: number | number[], p2: number | number[]): boolean {
if (p1 instanceof Array && p2 instanceof Array) {
return Math.abs(p1[0] - p2[0]) < DELTA && Math.abs(p1[1] - p2[1]) < DELTA;
}
- else {
+ else if (typeof p1 === 'number' && typeof p2 === 'number') {
return Math.abs(p1 - p2) < DELTA;
}
+ else {
+ throw Error('Iillegal p1 or p2');
+ }
}
const testGeoJson1: GeoJSON = {
@@ -112,7 +115,7 @@ describe('api/converter', function () {
let chart: EChartsType;
beforeEach(function () {
- chart = utHelper.createChart();
+ chart = createChart();
});
afterEach(function () {
@@ -328,17 +331,33 @@ describe('api/converter', function () {
const width = chart.getWidth();
const height = chart.getHeight();
- expect(pointEquals(chart.convertToPixel({seriesIndex: 1}, [-500, 6000]), [10, height - 40])).toEqual(true);
- expect(pointEquals(chart.convertFromPixel({seriesIndex: 1}, [10, height - 40]), [-500, 6000])).toEqual(true);
-
- expect(pointEquals(chart.convertToPixel({seriesId: 'i1'}, [300, 900]), [width - 20, height - 40])).toEqual(true);
- expect(pointEquals(chart.convertFromPixel({seriesId: 'i1'}, [width - 20, height - 40]), [300, 900])).toEqual(true);
-
- expect(pointEquals(chart.convertToPixel({xAxisIndex: 2, yAxisId: 'y1'}, [300, 900]), [width - 20, height - 40])).toEqual(true);
- expect(pointEquals(chart.convertFromPixel({xAxisIndex: 2, yAxisId: 'y1'}, [width - 20, height - 40]), [300, 900])).toEqual(true);
-
- expect(pointEquals(chart.convertToPixel({gridId: 'g1'}, [300, 900]), [width - 20, height - 40])).toEqual(true);
- expect(pointEquals(chart.convertFromPixel({gridId: 'g1'}, [width - 20, height - 40]), [300, 900])).toEqual(true);
+ expect(
+ pointEquals(chart.convertToPixel({seriesIndex: 1}, [-500, 6000]), [10, height - 40])
+ ).toEqual(true);
+ expect(
+ pointEquals(chart.convertFromPixel({seriesIndex: 1}, [10, height - 40]), [-500, 6000])
+ ).toEqual(true);
+
+ expect(
+ pointEquals(chart.convertToPixel({seriesId: 'i1'}, [300, 900]), [width - 20, height - 40])
+ ).toEqual(true);
+ expect(
+ pointEquals(chart.convertFromPixel({seriesId: 'i1'}, [width - 20, height - 40]), [300, 900])
+ ).toEqual(true);
+
+ expect(
+ pointEquals(chart.convertToPixel({xAxisIndex: 2, yAxisId: 'y1'}, [300, 900]), [width - 20, height - 40])
+ ).toEqual(true);
+ expect(
+ pointEquals(chart.convertFromPixel({xAxisIndex: 2, yAxisId: 'y1'}, [width - 20, height - 40]), [300, 900])
+ ).toEqual(true);
+
+ expect(
+ pointEquals(chart.convertToPixel({gridId: 'g1'}, [300, 900]), [width - 20, height - 40])
+ ).toEqual(true);
+ expect(
+ pointEquals(chart.convertFromPixel({gridId: 'g1'}, [width - 20, height - 40]), [300, 900])
+ ).toEqual(true);
expect(pointEquals(chart.convertToPixel({xAxisId: 'x0'}, 3000), width / 2)).toEqual(true);
expect(pointEquals(chart.convertFromPixel({xAxisId: 'x0'}, width / 2), 3000)).toEqual(true);
@@ -392,8 +411,16 @@ describe('api/converter', function () {
const width = chart.getWidth();
const height = chart.getHeight();
- expect(pointEquals(chart.convertToPixel({seriesIndex: 0}, [2000, 3500]), [10 + (width - 30) / 2, 30 + (height - 70) / 2])).toEqual(true);
- expect(pointEquals(chart.convertFromPixel({seriesIndex: 0}, [10 + (width - 30) / 2, 30 + (height - 70) / 2]), [2000, 3500])).toEqual(true);
+ expect(
+ pointEquals(
+ chart.convertToPixel({seriesIndex: 0}, [2000, 3500]), [10 + (width - 30) / 2, 30 + (height - 70) / 2]
+ )
+ ).toEqual(true);
+ expect(
+ pointEquals(
+ chart.convertFromPixel({seriesIndex: 0}, [10 + (width - 30) / 2, 30 + (height - 70) / 2]), [2000, 3500]
+ )
+ ).toEqual(true);
expect(pointEquals(chart.convertToPixel({seriesId: 'k2'}, [100, 500]), [10, height - 40])).toEqual(true);
expect(pointEquals(chart.convertFromPixel({seriesId: 'k2'}, [10, height - 40]), [100, 500])).toEqual(true);
diff --git a/test/ut/spec/api/getVisual.test.ts b/test/ut/spec/api/getVisual.test.ts
index 1214b06..de3d747 100755
--- a/test/ut/spec/api/getVisual.test.ts
+++ b/test/ut/spec/api/getVisual.test.ts
@@ -18,20 +18,20 @@
* under the License.
*/
-const utHelper = require('../../core/utHelper');
+import { createChart } from '../../core/utHelper';
+import { EChartsType } from '../../../../src/echarts';
-/* jshint maxlen:200 */
-describe('api/getVisual', function () {
+describe('api/getVisual', function () {
// TODO
// test each chart type, which may set visual on view which can not get from List.
// each of which should test visual map.
// symbol and symbolSize should be tested.
- var chart;
+ let chart: EChartsType;
beforeEach(function () {
- chart = utHelper.createChart();
+ chart = createChart();
});
afterEach(function () {
@@ -44,7 +44,7 @@ describe('api/getVisual', function () {
color: ['#000', '#111', '#222'],
visualMap: {
seriesIndex: 3,
- demension: 1,
+ dimension: 1,
min: 0,
max: 10000,
inRange: {
@@ -62,9 +62,7 @@ describe('api/getVisual', function () {
type: 'scatter',
data: [[10, 7]],
itemStyle: {
- normal: {
- color: '#fff'
- }
+ color: '#fff'
}
},
{
@@ -75,16 +73,12 @@ describe('api/getVisual', function () {
{
value: [333, 222],
itemStyle: {
- normal: {
- color: '#ff0'
- }
+ color: '#ff0'
}
}
],
itemStyle: {
- normal: {
- color: '#eee'
- }
+ color: '#eee'
}
},
{
@@ -95,16 +89,12 @@ describe('api/getVisual', function () {
{
value: [333, 9999],
itemStyle: {
- normal: {
- color: '#ff0'
- }
+ color: 'red'
}
}
],
itemStyle: {
- normal: {
- color: '#eee'
- }
+ color: '#eee'
}
}
]
@@ -118,7 +108,7 @@ describe('api/getVisual', function () {
expect(chart.getVisual({dataIndex: 1, seriesId: 'k2'}, 'color')).toEqual('#ff0');
expect(chart.getVisual({seriesId: 'k2'}, 'color')).toEqual('#eee');
- expect(chart.getVisual({dataIndex: 1, seriesId: 'k3'}, 'color')).toEqual('rgba(255,0,0,1)');
+ expect(chart.getVisual({dataIndex: 1, seriesId: 'k3'}, 'color')).toEqual('red');
expect(chart.getVisual({seriesId: 'k3'}, 'color')).toEqual('#eee');
});
@@ -145,16 +135,12 @@ describe('api/getVisual', function () {
{
value: [50, 222],
itemStyle: {
- normal: {
- color: '#ff0'
- }
+ color: '#ff0'
}
}
],
itemStyle: {
- normal: {
- color: '#eee'
- }
+ color: '#eee'
}
}
]
@@ -167,7 +153,7 @@ describe('api/getVisual', function () {
// it('pie', function () {
- // var chart = this.chart;
+ // const chart = this.chart;
// chart.setOption({
// series: [
@@ -187,7 +173,7 @@ describe('api/getVisual', function () {
// ]
// });
- // var height = chart.getHeight();
+ // const height = chart.getHeight();
// expect(chart.containPixel('series', [40, height / 2])).toEqual(false);
// expect(chart.containPixel('series', [40, height / 2 + 10])).toEqual(true);
@@ -196,7 +182,7 @@ describe('api/getVisual', function () {
// it('graph', function () {
- // var chart = this.chart;
+ // const chart = this.chart;
// chart.setOption({
// series: [
diff --git a/test/ut/tsconfig.json b/test/ut/tsconfig.json
index 08c1487..ff8304b 100644
--- a/test/ut/tsconfig.json
+++ b/test/ut/tsconfig.json
@@ -6,6 +6,7 @@
"noImplicitThis": true,
"strictBindCallApply": true,
"removeComments": true,
+ "sourceMap": true,
// https://github.com/ezolenko/rollup-plugin-typescript2/issues/12#issuecomment-536173372
"moduleResolution": "node",
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@echarts.apache.org
For additional commands, e-mail: commits-help@echarts.apache.org