pielegend.html revision b325078c1fbaa59f507067749a2d4872829afa5c
<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-legend', 'test', 'console', function (Y)
{
var suite = new Y.Test.Suite("Y.Charts.Legend"),
LegendTestTemplate = function(cfg, globalCfg)
{
var i;
cfg.height = cfg.height || 300;
cfg.categoryKey = "date";
this.attrCfg = cfg;
for(i in globalCfg)
{
if(globalCfg.hasOwnProperty(i))
{
this[i] = globalCfg[i];
}
}
};
Y.extend(LegendTestTemplate, Y.Test.Case, {
setUp: function() {
},
tearDown: function() {
this.chart.destroy(true);
}
});
var basicDataValues = [
],
pieDataValues = [
],
topLegend = function()
{
return {
position: "top",
styles: {
hAlign: "center"
}
};
},
bottomLegend = function()
{
return {
position: "bottom",
styles: {
hAlign: "center"
}
};
},
leftLegend = function()
{
return {
position: "left",
styles: {
vAlign: "middle"
}
};
},
rightLegend = function()
{
return {
position: "right",
styles: {
vAlign: "middle"
}
};
},
testLegend = function()
{
var assert = Y.Assert,
chart = this.chart,
legend = chart.get("legend");
assert.isTrue(legend instanceof Y.ChartLegend);
},
testLegendPosition = function()
{
var assert = Y.Assert,
chart = this.chart,
legend = chart.get("legend");
},
testLegendItemsLength = function()
{
var assert = Y.Assert,
chart = this.chart,
legend = chart.get("legend"),
chartSC = chart.get("seriesCollection"),
legendItems = legend.get("items");
},
testPieLegendItemsLength = function()
{
var assert = Y.Assert,
chart = this.chart,
legend = chart.get("legend"),
chartSC = chart.get("seriesCollection")[0].get("markers"),
legendItems = legend.get("items");
},
testLegendItemsText = function()
{
var assert = Y.Assert,
chart = this.chart,
legend = chart.get("legend"),
chartSC = chart.get("seriesCollection"),
legendItems = legend.get("items"),
i = 0,
len = chartSC.length;
for(; i < len; ++i)
{
}
},
testPieLegendItemsText = function()
{
var assert = Y.Assert,
chart = this.chart,
legend = chart.get("legend"),
displayName,
legendItems = legend.get("items"),
i = 0,
len = legendItems.length;
for(; i < len; ++i)
{
displayName = chart.getSeriesItems(series, i).category.value;
assert.areEqual(displayName, legendItems[i].text);
}
},
PieNoLegendTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart"
}, {
name: "Pie No Legend Tests",
testNoLegend: function()
{
var assert = Y.Assert,
chart = this.chart,
legend = chart.get("legend");
assert.isUndefined(legend);
}
}),
PieTopLegendTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: topLegend()
}, {
name: "Top Legend Test",
testLegend: testLegend
}),
PieRightLegendTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: rightLegend()
}, {
name: "Pie Right Legend Test",
testLegend: testLegend
}),
PieBottomLegendTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: bottomLegend()
}, {
name: "Pie Bottom Legend Test",
testLegend: testLegend
}),
PieLeftLegendTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: leftLegend()
}, {
name: "Pie Left Legend Test",
testLegend: testLegend
}),
PieTopLegendPositionTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: topLegend()
}, {
name: "Pie Top Legend Position Test",
legendPosition: "top",
testLegendPosition: testLegendPosition
}),
PieRightLegendPositionTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: rightLegend()
}, {
name: "Pie Right Legend Position Test",
legendPosition: "right",
testLegend: testLegendPosition
}),
PieBottomLegendPositionTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: bottomLegend()
}, {
name: "Pie Bottom Legend Position Test",
legendPosition: "bottom",
testLegend: testLegendPosition
}),
PieLeftLegendPositionTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: leftLegend()
}, {
name: "Pie Left Legend Position Test",
legendPosition: "left",
testLegend: testLegendPosition
}),
PieTopLegendItemsLengthTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: topLegend()
}, {
name: "Pie Top Legend Items Length Test",
testLegend: testPieLegendItemsLength
}),
PieRightLegendItemsLengthTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: rightLegend()
}, {
name: "Pie Right Legend Items Length Test",
testLegend: testPieLegendItemsLength
}),
PieBottomLegendItemsLengthTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: bottomLegend()
}, {
name: "Pie Bottom Legend Items Length Test",
testLegend: testPieLegendItemsLength
}),
PieLeftLegendItemsLengthTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: leftLegend()
}, {
name: "Pie Left Legend Items Length Test",
testLegend: testPieLegendItemsLength
}),
PieTopLegendItemsTextTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: topLegend()
}, {
name: "Pie Top Legend Items Text Test",
testLegend: testPieLegendItemsText
}),
PieRightLegendItemsTextTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: rightLegend()
}, {
name: "Pie Right Legend Items Text Test",
testLegend: testPieLegendItemsText
}),
PieBottomLegendItemsTextTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: bottomLegend()
}, {
name: "Pie Bottom Legend Items Text Test",
testLegend: testPieLegendItemsText
}),
PieLeftLegendItemsTextTest = new LegendTestTemplate({
type: "pie",
dataProvider: pieDataValues,
render: "#mychart",
legend: leftLegend()
}, {
name: "Pie Left Legend Items Text Test",
testLegend: testPieLegendItemsText
});
suite.add(PieNoLegendTest);
suite.add(PieTopLegendTest);
suite.add(PieRightLegendTest);
suite.add(PieBottomLegendTest);
suite.add(PieLeftLegendTest);
suite.add(PieTopLegendPositionTest);
suite.add(PieRightLegendPositionTest);
suite.add(PieBottomLegendPositionTest);
suite.add(PieLeftLegendPositionTest);
suite.add(PieTopLegendItemsLengthTest);
suite.add(PieRightLegendItemsLengthTest);
suite.add(PieBottomLegendItemsLengthTest);
suite.add(PieLeftLegendItemsLengthTest);
suite.add(PieTopLegendItemsTextTest);
suite.add(PieRightLegendItemsTextTest);
suite.add(PieBottomLegendItemsTextTest);
suite.add(PieLeftLegendItemsTextTest);
//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>