charts.html revision 405aac5878aad69932e8149f2c47f600721bb1cf
<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"),
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",
categoryType: "category",
interactionType: "marker"
},
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] + ".");
}
}
}
});
suite.add(ChartTests);
//create the console
var r = new Y.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>