charts.html revision 9fe78cb6e8c09c2e8e2a4628772453f0b9c1bcb7
<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] + ".");
}
}
}
});
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);
}
}),
//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}
];
var mychart = new Y.Chart({type: "pie", width:400, height:400, dataProvider:myDataValues});
mychart.render("#mychart");
this.chart = mychart;
},
tearDown: function() {
},
testWidthAndHeightEqual: function()
{
var graphic = this.chart.get("graph").get("graphic"),
shapes = graphic.get("shapes"),
i,
shape;
for(i in shapes)
{
if(shapes.hasOwnProperty(i))
{
shape = shapes[i];
}
}
},
testWidthGreaterThanHeight: function()
{
var graphic = this.chart.get("graph").get("graphic"),
shapes,
i,
shape;
this.chart.set("width", 500);
shapes = graphic.get("shapes");
for(i in shapes)
{
if(shapes.hasOwnProperty(i))
{
shape = shapes[i];
}
}
},
testHeightGreaterThanWidth: function()
{
var graphic = this.chart.get("graph").get("graphic"),
shapes,
i,
shape;
this.chart.set("height", 600);
shapes = graphic.get("shapes");
for(i in shapes)
{
if(shapes.hasOwnProperty(i))
{
shape = shapes[i];
}
}
}
});
suite.add(ChartTests);
suite.add(GraphTests);
suite.add(PieCenterTest);
//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>