1
0
mirror of https://gitlab.com/JKANetwork/CheckServer.git synced 2026-03-06 10:32:04 +01:00

Start again

This commit is contained in:
2020-10-04 17:14:00 +02:00
parent c0d3912413
commit 091f119048
4382 changed files with 1762543 additions and 9606 deletions

View File

@@ -0,0 +1,136 @@
describe('Component', function() {
var utHelper = window.utHelper;
var testCase = utHelper.prepare(['echarts/model/Component']);
describe('topologicalTravel', function () {
testCase('topologicalTravel_base', function (ComponentModel) {
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
ComponentModel.extend({type: 'a1'});
ComponentModel.extend({type: 'a2'});
var result = [];
var allList = ComponentModel.getAllClassMainTypes();
ComponentModel.topologicalTravel(['m1', 'a1', 'a2'], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([['a2', []], ['a1', []], ['m1', ['a1', 'a2']]]);
});
testCase('topologicalTravel_a1IsAbsent', function (ComponentModel) {
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
ComponentModel.extend({type: 'a2'});
var allList = ComponentModel.getAllClassMainTypes();
var result = [];
ComponentModel.topologicalTravel(['m1', 'a2'], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([['a2', []], ['m1', ['a1', 'a2']]]);
});
testCase('topologicalTravel_empty', function (ComponentModel) {
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
ComponentModel.extend({type: 'a1'});
ComponentModel.extend({type: 'a2'});
var allList = ComponentModel.getAllClassMainTypes();
var result = [];
ComponentModel.topologicalTravel([], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([]);
});
testCase('topologicalTravel_isolate', function (ComponentModel) {
ComponentModel.extend({type: 'a2'});
ComponentModel.extend({type: 'a1'});
ComponentModel.extend({type: 'm1', dependencies: ['a2']});
var allList = ComponentModel.getAllClassMainTypes();
var result = [];
ComponentModel.topologicalTravel(['a1', 'a2', 'm1'], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([['a1', []], ['a2', []], ['m1', ['a2']]]);
});
testCase('topologicalTravel_diamond', function (ComponentModel) {
ComponentModel.extend({type: 'a1', dependencies: []});
ComponentModel.extend({type: 'a2', dependencies: ['a1']});
ComponentModel.extend({type: 'a3', dependencies: ['a1']});
ComponentModel.extend({type: 'm1', dependencies: ['a2', 'a3']});
var allList = ComponentModel.getAllClassMainTypes();
var result = [];
ComponentModel.topologicalTravel(['m1', 'a1', 'a2', 'a3'], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([['a1', []], ['a3', ['a1']], ['a2', ['a1']], ['m1', ['a2', 'a3']]]);
});
testCase('topologicalTravel_loop', function (ComponentModel) {
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
ComponentModel.extend({type: 'm2', dependencies: ['m1', 'a2']});
ComponentModel.extend({type: 'a1', dependencies: ['m2', 'a2', 'a3']});
ComponentModel.extend({type: 'a2'});
ComponentModel.extend({type: 'a3'});
var allList = ComponentModel.getAllClassMainTypes();
expect(function () {
ComponentModel.topologicalTravel(['m1', 'm2', 'a1'], allList);
}).toThrowError(/Circl/);
});
testCase('topologicalTravel_multipleEchartsInstance', function (ComponentModel) {
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
ComponentModel.extend({type: 'a1'});
ComponentModel.extend({type: 'a2'});
var allList = ComponentModel.getAllClassMainTypes();
var result = [];
ComponentModel.topologicalTravel(['m1', 'a1', 'a2'], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([['a2', []], ['a1', []], ['m1', ['a1', 'a2']]]);
result = [];
ComponentModel.extend({type: 'm2', dependencies: ['a1', 'm1']});
var allList = ComponentModel.getAllClassMainTypes();
ComponentModel.topologicalTravel(['m2', 'm1', 'a1', 'a2'], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([['a2', []], ['a1', []], ['m1', ['a1', 'a2']], ['m2', ['a1', 'm1']]]);
});
testCase('topologicalTravel_missingSomeNodeButHasDependencies', function (ComponentModel) {
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
ComponentModel.extend({type: 'a2', dependencies: ['a3']});
ComponentModel.extend({type: 'a3'});
ComponentModel.extend({type: 'a4'});
var result = [];
var allList = ComponentModel.getAllClassMainTypes();
ComponentModel.topologicalTravel(['a3', 'm1'], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([['a3', []], ['a2', ['a3']], ['m1', ['a1', 'a2']]]);
var result = [];
var allList = ComponentModel.getAllClassMainTypes();
ComponentModel.topologicalTravel(['m1', 'a3'], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([['a3', []], ['a2', ['a3']], ['m1', ['a1', 'a2']]]);
});
testCase('topologicalTravel_subType', function (ComponentModel) {
ComponentModel.extend({type: 'm1', dependencies: ['a1', 'a2']});
ComponentModel.extend({type: 'a1.aaa', dependencies: ['a2']});
ComponentModel.extend({type: 'a1.bbb', dependencies: ['a3', 'a4']});
ComponentModel.extend({type: 'a2'});
ComponentModel.extend({type: 'a3'});
ComponentModel.extend({type: 'a4'});
var result = [];
var allList = ComponentModel.getAllClassMainTypes();
ComponentModel.topologicalTravel(['m1', 'a1', 'a2', 'a4'], allList, function (componentType, dependencies) {
result.push([componentType, dependencies]);
});
expect(result).toEqual([['a4', []], ['a2',[]], ['a1', ['a2','a3','a4']], ['m1', ['a1', 'a2']]]);
});
});
});

View File

@@ -0,0 +1,808 @@
describe('modelAndOptionMapping', function() {
var utHelper = window.utHelper;
var testCase = utHelper.prepare([
'echarts/component/grid',
'echarts/chart/line',
'echarts/chart/pie',
'echarts/chart/bar',
'echarts/component/toolbox',
'echarts/component/dataZoom'
]);
function getData0(chart, seriesIndex) {
return getSeries(chart, seriesIndex).getData().get('y', 0);
}
function getSeries(chart, seriesIndex) {
return chart.getModel().getComponent('series', seriesIndex);
}
function getModel(chart, type, index) {
return chart.getModel().getComponent(type, index);
}
function countSeries(chart) {
return countModel(chart, 'series');
}
function countModel(chart, type) {
// FIXME
// access private
return chart.getModel()._componentsMap[type].length;
}
function getChartView(chart, series) {
return chart._chartsMap[series.__viewId];
}
function countChartViews(chart) {
return chart._chartsViews.length;
}
function saveOrigins(chart) {
var count = countSeries(chart);
var origins = [];
for (var i = 0; i < count; i++) {
var series = getSeries(chart, i);
origins.push({
model: series,
view: getChartView(chart, series)
});
}
return origins;
}
function modelEqualsToOrigin(chart, idxList, origins, boolResult) {
for (var i = 0; i < idxList.length; i++) {
var idx = idxList[i];
expect(origins[idx].model === getSeries(chart, idx)).toEqual(boolResult);
}
}
function viewEqualsToOrigin(chart, idxList, origins, boolResult) {
for (var i = 0; i < idxList.length; i++) {
var idx = idxList[i];
expect(
origins[idx].view === getChartView(chart, getSeries(chart, idx))
).toEqual(boolResult);
}
}
describe('idNoNameNo', function () {
testCase.createChart()('sameTypeNotMerge', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22]},
{type: 'line', data: [33]}
]
};
var chart = this.chart;
chart.setOption(option);
// Not merge
var origins = saveOrigins(chart);
chart.setOption(option, true);
expect(countChartViews(chart)).toEqual(3);
expect(countSeries(chart)).toEqual(3);
modelEqualsToOrigin(chart, [0, 1, 2], origins, false);
viewEqualsToOrigin(chart, [0, 1, 2], origins, true);
});
testCase.createChart()('sameTypeMergeFull', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22]},
{type: 'line', data: [33]}
]
};
var chart = this.chart;
chart.setOption(option);
// Merge
var origins = saveOrigins(chart);
chart.setOption({
series: [
{type: 'line', data: [111]},
{type: 'line', data: [222]},
{type: 'line', data: [333]}
]
});
expect(countSeries(chart)).toEqual(3);
expect(countChartViews(chart)).toEqual(3);
expect(getData0(chart, 0)).toEqual(111);
expect(getData0(chart, 1)).toEqual(222);
expect(getData0(chart, 2)).toEqual(333);
viewEqualsToOrigin(chart, [0, 1, 2], origins, true);
modelEqualsToOrigin(chart, [0, 1, 2], origins, true);
});
testCase.createChart()('sameTypeMergePartial', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22]},
{type: 'line', data: [33]}
]
};
var chart = this.chart;
chart.setOption(option);
// Merge
var origins = saveOrigins(chart);
chart.setOption({
series: [
{type: 'line', data: [22222]}
]
});
expect(countSeries(chart)).toEqual(3);
expect(countChartViews(chart)).toEqual(3);
expect(getData0(chart, 0)).toEqual(22222);
expect(getData0(chart, 1)).toEqual(22);
expect(getData0(chart, 2)).toEqual(33);
viewEqualsToOrigin(chart, [0, 1, 2], origins, true);
modelEqualsToOrigin(chart, [0, 1, 2], origins, true);
});
testCase.createChart()('differentTypeMerge', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22]},
{type: 'line', data: [33]}
]
};
var chart = this.chart;
chart.setOption(option);
// Merge
var origins = saveOrigins(chart);
chart.setOption({
series: [
{type: 'line', data: [111]},
{type: 'bar', data: [222]},
{type: 'line', data: [333]}
]
});
expect(countSeries(chart)).toEqual(3);
expect(countChartViews(chart)).toEqual(3);
expect(getData0(chart, 0)).toEqual(111);
expect(getData0(chart, 1)).toEqual(222);
expect(getData0(chart, 2)).toEqual(333);
expect(getSeries(chart, 1).type === 'series.bar').toEqual(true);
modelEqualsToOrigin(chart, [0, 2], origins, true);
modelEqualsToOrigin(chart, [1], origins, false);
viewEqualsToOrigin(chart, [0, 2], origins, true);
viewEqualsToOrigin(chart, [1], origins, false);
});
});
describe('idSpecified', function () {
testCase.createChart()('sameTypeNotMerge', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], id: 20},
{type: 'line', data: [33], id: 30},
{type: 'line', data: [44]},
{type: 'line', data: [55]}
]
};
var chart = this.chart;
chart.setOption(option);
expect(countSeries(chart)).toEqual(5);
expect(countChartViews(chart)).toEqual(5);
expect(getData0(chart, 0)).toEqual(11);
expect(getData0(chart, 1)).toEqual(22);
expect(getData0(chart, 2)).toEqual(33);
expect(getData0(chart, 3)).toEqual(44);
expect(getData0(chart, 4)).toEqual(55);
var origins = saveOrigins(chart);
chart.setOption(option, true);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
});
testCase.createChart()('sameTypeMerge', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], id: 20},
{type: 'line', data: [33], id: 30},
{type: 'line', data: [44]},
{type: 'line', data: [55]}
]
};
var chart = this.chart;
chart.setOption(option);
var origins = saveOrigins(chart);
chart.setOption(option);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
});
testCase.createChart()('differentTypeNotMerge', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], id: 20},
{type: 'line', data: [33], id: 30},
{type: 'line', data: [44]},
{type: 'line', data: [55]}
]
};
var chart = this.chart;
chart.setOption(option);
var origins = saveOrigins(chart);
var option2 = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'bar', data: [22], id: 20},
{type: 'line', data: [33], id: 30},
{type: 'bar', data: [44]},
{type: 'line', data: [55]}
]
};
chart.setOption(option2, true);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
viewEqualsToOrigin(chart, [0, 2, 4], origins, true);
viewEqualsToOrigin(chart, [1, 3], origins, false);
});
testCase.createChart()('differentTypeMergeFull', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], id: 20},
{type: 'line', data: [33], id: 30, name: 'a'},
{type: 'line', data: [44]},
{type: 'line', data: [55]}
]
};
var chart = this.chart;
chart.setOption(option);
var origins = saveOrigins(chart);
var option2 = {
series: [
{type: 'line', data: [11]},
{type: 'bar', data: [22], id: 20, name: 'a'},
{type: 'line', data: [33], id: 30},
{type: 'bar', data: [44]},
{type: 'line', data: [55]}
]
};
chart.setOption(option2);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
modelEqualsToOrigin(chart, [0, 2, 4], origins, true);
modelEqualsToOrigin(chart, [1, 3], origins, false);
viewEqualsToOrigin(chart, [0, 2, 4], origins, true);
viewEqualsToOrigin(chart, [1, 3], origins, false);
});
testCase.createChart()('differentTypeMergePartial1', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], id: 20},
{type: 'line', data: [33]},
{type: 'line', data: [44], id: 40},
{type: 'line', data: [55]}
]
};
var chart = this.chart;
chart.setOption(option);
var origins = saveOrigins(chart);
var option2 = {
series: [
{type: 'bar', data: [444], id: 40},
{type: 'line', data: [333]},
{type: 'line', data: [222], id: 20}
]
};
chart.setOption(option2);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
expect(getData0(chart, 0)).toEqual(333);
expect(getData0(chart, 1)).toEqual(222);
expect(getData0(chart, 2)).toEqual(33);
expect(getData0(chart, 3)).toEqual(444);
expect(getData0(chart, 4)).toEqual(55);
modelEqualsToOrigin(chart, [0, 1, 2, 4], origins, true);
modelEqualsToOrigin(chart, [3], origins, false);
viewEqualsToOrigin(chart, [0, 1, 2, 4], origins, true);
viewEqualsToOrigin(chart, [3], origins, false);
});
testCase.createChart()('differentTypeMergePartial2', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], id: 20}
]
};
var chart = this.chart;
chart.setOption(option);
var option2 = {
series: [
{type: 'bar', data: [444], id: 40},
{type: 'line', data: [333]},
{type: 'line', data: [222], id: 20},
{type: 'line', data: [111]}
]
};
chart.setOption(option2);
expect(countChartViews(chart)).toEqual(4);
expect(countSeries(chart)).toEqual(4);
expect(getData0(chart, 0)).toEqual(333);
expect(getData0(chart, 1)).toEqual(222);
expect(getData0(chart, 2)).toEqual(444);
expect(getData0(chart, 3)).toEqual(111);
});
testCase.createChart()('mergePartialDoNotMapToOtherId', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11], id: 10},
{type: 'line', data: [22], id: 20}
]
};
var chart = this.chart;
chart.setOption(option);
var option2 = {
series: [
{type: 'bar', data: [444], id: 40}
]
};
chart.setOption(option2);
expect(countChartViews(chart)).toEqual(3);
expect(countSeries(chart)).toEqual(3);
expect(getData0(chart, 0)).toEqual(11);
expect(getData0(chart, 1)).toEqual(22);
expect(getData0(chart, 2)).toEqual(444);
});
testCase.createChart()('idDuplicate', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11], id: 10},
{type: 'line', data: [22], id: 10}
]
};
var chart = this.chart;
expect(function () {
chart.setOption(option);
}).toThrowError(/duplicate/);
});
});
describe('noIdButNameExists', function () {
testCase.createChart()('sameTypeNotMerge', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], name: 'a'},
{type: 'line', data: [33], name: 'b'},
{type: 'line', data: [44]},
{type: 'line', data: [55], name: 'a'}
]
};
var chart = this.chart;
chart.setOption(option);
expect(getSeries(chart, 1)).not.toEqual(getSeries(chart, 4));
expect(countSeries(chart)).toEqual(5);
expect(countChartViews(chart)).toEqual(5);
expect(getData0(chart, 0)).toEqual(11);
expect(getData0(chart, 1)).toEqual(22);
expect(getData0(chart, 2)).toEqual(33);
expect(getData0(chart, 3)).toEqual(44);
expect(getData0(chart, 4)).toEqual(55);
var origins = saveOrigins(chart);
chart.setOption(option, true);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
});
testCase.createChart()('sameTypeMerge', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], name: 'a'},
{type: 'line', data: [33], name: 'b'},
{type: 'line', data: [44]},
{type: 'line', data: [55], name: 'a'}
]
};
var chart = this.chart;
chart.setOption(option);
var origins = saveOrigins(chart);
chart.setOption(option);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
viewEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, true);
});
testCase.createChart()('differentTypeNotMerge', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], name: 'a'},
{type: 'line', data: [33], name: 'b'},
{type: 'line', data: [44]},
{type: 'line', data: [55], name: 'a'}
]
};
var chart = this.chart;
chart.setOption(option);
var origins = saveOrigins(chart);
var option2 = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'bar', data: [22], name: 'a'},
{type: 'line', data: [33], name: 'b'},
{type: 'bar', data: [44]},
{type: 'line', data: [55], name: 'a'}
]
};
chart.setOption(option2, true);
expect(countChartViews(chart)).toEqual(5);
expect(countSeries(chart)).toEqual(5);
modelEqualsToOrigin(chart, [0, 1, 2, 3, 4], origins, false);
viewEqualsToOrigin(chart, [0, 2, 4], origins, true);
viewEqualsToOrigin(chart, [1, 3], origins, false);
});
testCase.createChart()('differentTypeMergePartialOneMapTwo', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], name: 'a'},
{type: 'line', data: [33]},
{type: 'line', data: [44], name: 'b'},
{type: 'line', data: [55], name: 'a'}
]
};
var chart = this.chart;
chart.setOption(option);
var origins = saveOrigins(chart);
var option2 = {
series: [
{type: 'bar', data: [444], id: 40},
{type: 'line', data: [333]},
{type: 'bar', data: [222], name: 'a'}
]
};
chart.setOption(option2);
expect(countChartViews(chart)).toEqual(6);
expect(countSeries(chart)).toEqual(6);
expect(getData0(chart, 0)).toEqual(333);
expect(getData0(chart, 1)).toEqual(222);
expect(getData0(chart, 2)).toEqual(33);
expect(getData0(chart, 3)).toEqual(44);
expect(getData0(chart, 4)).toEqual(55);
expect(getData0(chart, 5)).toEqual(444);
modelEqualsToOrigin(chart, [0, 2, 3, 4], origins, true);
modelEqualsToOrigin(chart, [1], origins, false);
viewEqualsToOrigin(chart, [0, 2, 3, 4], origins, true);
viewEqualsToOrigin(chart, [1], origins, false);
});
testCase.createChart()('differentTypeMergePartialTwoMapOne', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22], name: 'a'}
]
};
var chart = this.chart;
chart.setOption(option);
var option2 = {
series: [
{type: 'bar', data: [444], name: 'a'},
{type: 'line', data: [333]},
{type: 'line', data: [222], name: 'a'},
{type: 'line', data: [111]}
]
};
chart.setOption(option2);
expect(countChartViews(chart)).toEqual(4);
expect(countSeries(chart)).toEqual(4);
expect(getData0(chart, 0)).toEqual(333);
expect(getData0(chart, 1)).toEqual(444);
expect(getData0(chart, 2)).toEqual(222);
expect(getData0(chart, 3)).toEqual(111);
});
testCase.createChart()('mergePartialCanMapToOtherName', function () {
// Consider case: axis.name = 'some label', which can be overwritten.
var option = {
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11], name: 10},
{type: 'line', data: [22], name: 20}
]
};
var chart = this.chart;
chart.setOption(option);
var option2 = {
series: [
{type: 'bar', data: [444], name: 40},
{type: 'bar', data: [999], name: 40},
{type: 'bar', data: [777], id: 70}
]
};
chart.setOption(option2);
expect(countChartViews(chart)).toEqual(3);
expect(countSeries(chart)).toEqual(3);
expect(getData0(chart, 0)).toEqual(444);
expect(getData0(chart, 1)).toEqual(999);
expect(getData0(chart, 2)).toEqual(777);
});
});
describe('ohters', function () {
testCase.createChart()('aBugCase', function () {
var option = {
series: [
{
type:'pie',
radius: ['20%', '25%'],
center:['20%', '20%'],
avoidLabelOverlap: true,
hoverAnimation :false,
label: {
normal: {
show: true,
position: 'center',
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
},
emphasis: {
show: true
}
},
data:[
{value:135, name:'视频广告'},
{value:1548}
]
}
]
};
var chart = this.chart;
chart.setOption(option);
chart.setOption({
series: [
{
type:'pie',
radius: ['20%', '25%'],
center: ['20%', '20%'],
avoidLabelOverlap: true,
hoverAnimation: false,
label: {
normal: {
show: true,
position: 'center',
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
}
},
data: [
{value:135, name:'视频广告'},
{value:1548}
]
},
{
type:'pie',
radius: ['20%', '25%'],
center: ['60%', '20%'],
avoidLabelOverlap: true,
hoverAnimation: false,
label: {
normal: {
show: true,
position: 'center',
textStyle: {
fontSize: '30',
fontWeight: 'bold'
}
}
},
data: [
{value:135, name:'视频广告'},
{value:1548}
]
}
]
}, true);
expect(countChartViews(chart)).toEqual(2);
expect(countSeries(chart)).toEqual(2);
});
testCase.createChart()('color', function () {
var option = {
backgroundColor: 'rgba(1,1,1,1)',
xAxis: {data: ['a']},
yAxis: {},
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22]},
{type: 'line', data: [33]}
]
};
var chart = this.chart;
chart.setOption(option);
expect(chart._model.option.backgroundColor).toEqual('rgba(1,1,1,1)');
// Not merge
chart.setOption({
backgroundColor: '#fff'
}, true);
expect(chart._model.option.backgroundColor).toEqual('#fff');
});
testCase.createChart()('innerId', function () {
var option = {
xAxis: {data: ['a']},
yAxis: {},
toolbox: {
feature: {
dataZoom: {}
}
},
dataZoom: [
{type: 'inside', id: 'a'},
{type: 'slider', id: 'b'}
],
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22]}
]
};
var chart = this.chart;
chart.setOption(option);
expect(countModel(chart, 'dataZoom')).toEqual(4);
expect(getModel(chart, 'dataZoom', 0).id).toEqual('a');
expect(getModel(chart, 'dataZoom', 1).id).toEqual('b');
// Merge
chart.setOption({
dataZoom: [
{type: 'slider', id: 'c'},
{type: 'slider', name: 'x'}
]
});
expect(countModel(chart, 'dataZoom')).toEqual(5);
expect(getModel(chart, 'dataZoom', 0).id).toEqual('a');
expect(getModel(chart, 'dataZoom', 1).id).toEqual('b');
expect(getModel(chart, 'dataZoom', 4).id).toEqual('c');
});
});
});

View File

@@ -0,0 +1,161 @@
describe('timelineOptions', function() {
var utHelper = window.utHelper;
var testCase = utHelper.prepare([
'echarts/component/grid',
'echarts/chart/line',
'echarts/chart/pie',
'echarts/chart/bar',
'echarts/component/timeline'
]);
function getData0(chart, seriesIndex) {
return getSeries(chart, seriesIndex).getData().get('y', 0);
}
function getSeries(chart, seriesIndex) {
return chart.getModel().getComponent('series', seriesIndex);
}
testCase.createChart()('timeline_setOptionOnceMore_baseOption', function () {
var option = {
baseOption: {
timeline: {
axisType: 'category',
autoPlay: false,
playInterval: 1000
},
xAxis: {data: ['a']},
yAxis: {}
},
options: [
{
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22]}
]
},
{
series: [
{type: 'line', data: [111]},
{type: 'line', data: [222]}
]
}
]
};
var chart = this.chart;
chart.setOption(option);
expect(getData0(chart, 0)).toEqual(11);
expect(getData0(chart, 1)).toEqual(22);
chart.setOption({
xAxis: {data: ['b']}
});
expect(getData0(chart, 0)).toEqual(11);
expect(getData0(chart, 1)).toEqual(22);
chart.setOption({
xAxis: {data: ['c']},
timeline: {
currentIndex: 1
}
});
expect(getData0(chart, 0)).toEqual(111);
expect(getData0(chart, 1)).toEqual(222);
});
testCase.createChart()('timeline_setOptionOnceMore_substitudeTimelineOptions', function () {
var option = {
baseOption: {
timeline: {
axisType: 'category',
autoPlay: false,
playInterval: 1000,
currentIndex: 2
},
xAxis: {data: ['a']},
yAxis: {}
},
options: [
{
series: [
{type: 'line', data: [11]},
{type: 'line', data: [22]}
]
},
{
series: [
{type: 'line', data: [111]},
{type: 'line', data: [222]}
]
},
{
series: [
{type: 'line', data: [1111]},
{type: 'line', data: [2222]}
]
}
]
};
var chart = this.chart;
chart.setOption(option);
var ecModel = chart.getModel();
expect(getData0(chart, 0)).toEqual(1111);
expect(getData0(chart, 1)).toEqual(2222);
chart.setOption({
baseOption: {
backgroundColor: '#987654',
xAxis: {data: ['b']}
},
options: [
{
series: [
{type: 'line', data: [55]},
{type: 'line', data: [66]}
]
},
{
series: [
{type: 'line', data: [555]},
{type: 'line', data: [666]}
]
}
]
});
var ecModel = chart.getModel();
var option = ecModel.getOption();
expect(option.backgroundColor).toEqual('#987654');
expect(getData0(chart, 0)).toEqual(1111);
expect(getData0(chart, 1)).toEqual(2222);
chart.setOption({
timeline: {
currentIndex: 0
}
});
expect(getData0(chart, 0)).toEqual(55);
expect(getData0(chart, 1)).toEqual(66);
chart.setOption({
timeline: {
currentIndex: 2
}
});
// no 1111 2222 any more, replaced totally by new timeline.
expect(getData0(chart, 0)).toEqual(55);
expect(getData0(chart, 1)).toEqual(66);
});
});