charts.html revision e393eced613f9b4a5fb6bdd461d0e0bf5064d5ec
<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().use('charts', 'test', 'console', function (Y)
{
Y.example.test.ChartTest = new Y.Test.Case({
name: "Chart 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 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 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");
}
});
//create the console
newestOnTop : false,
style: 'block' // to anchor in the example content
});
r.render('#testLogger');
//run the tests
});
</script>
</body>
</html>