charts.html revision 2283e3a241de1db1aaba484b89c8aadd89446b36
<html>
<head>
<style>
/*Supplemental: CSS for the YUI distribution*/
#custom-doc { width: 95%; min-width: 950px; }
#mychart {
padding:10px 10px 10px 10px;
}
</style>
</head>
<body class="yui3-skin-sam">
<h3>Unit Tests</h3>
<div id="mychart"></div>
<script>
YUI({
allowRollup: false,
filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'min'
}).use('charts', 'test', 'console', function (Y)
{
var suite = new Y.Test.Suite("Y.Charts");
var ChartTests = new Y.Test.Case({
name: "Chart Tests",
setUp: function() {
var myDataValues = [
];
var mychart = new Y.Chart({width:400, height:300, dataProvider:myDataValues});
mychart.render("#mychart");
this.chart = mychart;
},
tearDown: function() {
},
//Test to ensure that all items in the series collection are of the correct type.
testGetSeriesByIndex: function()
{
var series = this.chart.getSeries(0),
assert = Y.Assert;
assert.isInstanceOf(Y.CartesianSeries, series);
},
//Test to ensure that all items in the series collection are of the correct type.
testGetSeriesByKey: function()
{
var series = this.chart.getSeries("revenue"),
assert = Y.Assert;
assert.isInstanceOf(Y.CartesianSeries, series);
},
//Test to ensure the series axes are numeric and the category axis is of type category
testGetAxesByKey: function()
{
var category = this.chart.getAxisByKey("category"),
values = this.chart.getAxisByKey("values"),
assert = Y.Assert;
assert.isInstanceOf(Y.CategoryAxis, category);
assert.isInstanceOf(Y.NumericAxis, values);
},
//Test to ensure that getCategoryAxis returns a category axis
testGetCategoryAxis: function()
{
var category = this.chart.get("categoryAxis"),
assert = Y.Assert;
assert.isInstanceOf(Y.CategoryAxis, category);
},
//Test that the graph attribute is of type Graph
testGetGraph: function()
{
},
//Test to ensure that the axes hash contains AxisRenderer instances
testGetAxes: function()
{
var assert = Y.Assert,
axes = this.chart.get("axes"),
i;
for(i in axes)
{
if(axes.hasOwnProperty(i))
{
assert.isInstanceOf(Y.Axis, axes[i]);
}
}
},
//Test to ensure that default series keys are correct
testGetSeriesKeys: function()
{
var assert = Y.Assert,
YArray = Y.Array,
selectedIndex,
testKeys = ['values', 'expenses', 'revenue'],
newArray = [],
actualKeys = this.chart.get("seriesKeys"),
i = 0,
len = testKeys.length;
assert.areEqual(actualKeys.length, testKeys.length, "Actual seriesKeys array is not the correct length.");
for(; i < len; ++i)
{
assert.isNotNull(selectedIndex + 1, "The seriesKeys array should contain the following key: " + testKeys[i] + ".");
if(selectedIndex > -1)
{
newArray.push(actualKeys[selectedIndex]);
}
else
{
throw new Error("The actual seriesKeys array should but does not contain " + testKeys[i] + ".");
}
}
assert.areEqual(newArray.length, actualKeys.length, "The seriesKeys array has more keys than it should.");
},
//Test to ensure default attributes are correct
testGetDefaultAttributes: function()
{
var assert = Y.Assert,
attrs = {
direction: "horizontal",
type: "combo",
valueAxisName: "values",
categoryAxisName: "category",
categoryKey: "category"
},
chart = this.chart,
i;
for(i in attrs)
{
if(attrs.hasOwnProperty(i))
{
assert.areEqual(chart.get(i), attrs[i], "The attribute " + i + " should equal " + attrs[i] + ".");
}
}
}
});
var GraphTests = new Y.Test.Case({
name: "Graph Tests",
setUp: function() {
var myDataValues = [
];
var mychart = new Y.Chart({width:400, height:300, dataProvider:myDataValues, seriesKeys:["values", "revenue"]});
mychart.render("#mychart");
this.chart = mychart;
},
tearDown: function() {
},
"test:graph._getSeries(line)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("line");
},
"test:graph._getSeries(column)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("column");
},
"test:graph._getSeries(bar)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("bar");
},
"test:graph._getSeries(area)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("area");
},
"test:graph._getSeries(stackedarea)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("stackedarea");
},
"test:graph._getSeries(stackedcolumn)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("stackedcolumn");
Y.Assert.areEqual(series, Y.StackedColumnSeries, "The series type should be Y.StackedColumnSeries");
},
"test:graph._getSeries(stackedbar)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("stackedbar");
},
"test:graph._getSeries(stackedline)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("stackedline");
},
"test:graph._getSeries(markerseries)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("markerseries");
},
"test:graph._getSeries(stackedmarkerseries)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("stackedmarkerseries");
Y.Assert.areEqual(series, Y.StackedMarkerSeries, "The series type should be Y.StackedMarkerSeries");
},
"test:graph._getSeries(spline)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("spline");
},
"test:graph._getSeries(areaspline)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("areaspline");
},
"test:graph._getSeries(stackedspline)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("stackedspline");
Y.Assert.areEqual(series, Y.StackedSplineSeries, "The series type should be Y.StackedSplineSeries");
},
"test:graph._getSeries(stackedareapline)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("stackedareaspline");
Y.Assert.areEqual(series, Y.StackedAreaSplineSeries, "The series type should be Y.StackedAreaSplineSeries");
},
"test:graph._getSeries(pie)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("pie");
},
"test:graph._getSeries(combo)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("combo");
},
"test:graph._getSeries(stackedcombo)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("stackedcombo");
},
"test:graph._getSeries(combospline)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("combospline");
},
"test:graph._getSeries(stackedcombospline)": function()
{
var graph = this.chart.get("graph"),
series = graph._getSeries("stackedcombospline");
Y.Assert.areEqual(series, Y.StackedComboSplineSeries, "The series type should be Y.StackedComboSplineSeries");
},
"test:graph._getSeries(customclass)" : function()
{
var graph = this.chart.get("graph"),
series;
mycustomprop: null,
mycustommethod: function()
{
var yaypie = "mmmm";
yaypie += "Pie";
}
});
series = graph._getSeries(Y.CustomLineSeries);
}
}),
AxesTests = new Y.Test.Case({
name: "Axes Tests",
setUp: function() {
var myDataValues = [
];
var mychart = new Y.Chart({width:400, height:300, dataProvider:myDataValues, seriesKeys:["values", "revenue"]});
mychart.render("#mychart");
this.chart = mychart;
},
tearDown: function() {
},
//Test axes data classes
testRemoveKey: function()
{
var assert = Y.Assert,
xAxis = this.chart.getCategoryAxis(),
yAxis = this.chart.getAxisByKey("values"),
keys,
l,
i;
l = xAxis.get("keyCollection").length || 0;
assert.areEqual(0, 0, "The value should be zero");
}, this));
keys = yAxis.get("keyCollection");
assert.areEqual(1, keys.length, "The length should be 1");
assert.areEqual(Y.Array.indexOf(keys, "revenue"), -1, "The key revenue should be removed");
}));
xAxis.removeKey("category");
yAxis.removeKey("revenue");
},
testAddKey: function()
{
var assert = Y.Assert,
yAxis = this.chart.getAxisByKey("values"),
keys,
pattern = [3700, 9100, 1100, 1900],
testarray,
i = 0;
l = 4;
keys = yAxis.get("keyCollection");
testarray = yAxis.getDataByKey("expenses");
assert.areEqual(Y.Array.indexOf(keys, "expenses"), 2);
for(; i < l; ++i)
{
}
}, this));
yAxis.addKey("expenses");
}
}),
AxisMinAndMaxTest = new Y.Test.Case({
name: "Axes Min and Max Tests",
setUp: function() {
var myDataValues = [
];
mychart.render("#mychart");
this.minandmaxchart = mychart;
},
tearDown: function() {
},
//Tests a NumericAxis minimum and maximum by applying the labelFunction of the axis to the set minimum and maximum values and
//then comparing the innerHTML of the first and last labels
testMinAndMax: function()
{
count = majorUnit.count - 1,
setMax = 1492,
setMin = 7,
eventListener,
labels;
labels = yAxis.get("labels");
Y.assert(labels[0].innerHTML == yAxis.get("labelFunction").apply(yAxis, [setMin, yAxis.get("labelFormat")]));
Y.assert(labels[count].innerHTML == yAxis.get("labelFunction").apply(yAxis, [setMax, yAxis.get("labelFormat")]));
});
},
//change min to negative value and test.
//change max to negative value and test.
testNegativeMinAndMax: function()
{
count = majorUnit.count- 1,
setMin = -1721,
setMax = -15,
eventListener,
labels;
labels = yAxis.get("labels");
Y.assert(labels[0].innerHTML == yAxis.get("labelFunction").apply(yAxis, [setMin, yAxis.get("labelFormat")]));
Y.assert(labels[count].innerHTML == yAxis.get("labelFunction").apply(yAxis, [setMax, yAxis.get("labelFormat")]));
});
},
//Tests min and max with decimals
testMinAndMaxWithDecimals: function()
{
count = majorUnit.count- 1,
setMin = 14.66,
setMax = 1821.33,
eventListener,
labels;
labels = yAxis.get("labels");
Y.assert(labels[0].innerHTML == yAxis.get("labelFunction").apply(yAxis, [setMin, yAxis.get("labelFormat")]));
Y.assert(labels[count].innerHTML == yAxis.get("labelFunction").apply(yAxis, [setMax, yAxis.get("labelFormat")]));
});
}
}),
//test to ensure that pie charts are drawn from center
PieCenterTest = new Y.Test.Case({
name: "PieChartCenterTest",
setUp: function() {
var myDataValues = [
{day:"Monday", taxes:2000},
{day:"Tuesday", taxes:50},
{day:"Wednesday", taxes:4000},
{day:"Thursday", taxes:200},
{day:"Friday", taxes:2000}
];
mychart.render("#mychart");
this.chart = mychart;
},
tearDown: function() {
},
testWidthAndHeightEqual: function()
{
shapes = graphic.get("shapes"),
i,
shape;
for(i in shapes)
{
{
shape = shapes[i];
}
}
},
testWidthGreaterThanHeight: function()
{
shapes,
i,
shape;
shapes = graphic.get("shapes");
for(i in shapes)
{
{
shape = shapes[i];
}
}
},
testHeightGreaterThanWidth: function()
{
shapes,
i,
shape;
shapes = graphic.get("shapes");
for(i in shapes)
{
{
shape = shapes[i];
}
}
}
});
suite.add(ChartTests);
suite.add(GraphTests);
suite.add(AxesTests);
suite.add(AxisMinAndMaxTest);
suite.add(PieCenterTest);
//create the console
newestOnTop : false,
style: 'block' // to anchor in the example content
});
r.render('#testLogger');
//run the tests
Y.Test.Runner.add(suite);
});
</script>
</body>
</html>