Permalink
Browse files

Charts unit test updates.

  • Loading branch information...
tripp committed Mar 22, 2013
1 parent 42d5834 commit 6a5010622ff5cbd9486206e6b0441b3c65c7170c
@@ -4,17 +4,68 @@ YUI.add('axis-category-tests', function(Y) {
}
Y.extend(Y.CategoryAxisTest, Y.ChartTestTemplate, {
setUp: function() {
- this.axis = new Y.CategoryAxis({
- dataProvider: this.dataProvider,
- keys: this.dataKeys,
- position: this.position
- });
+ var position = this.position,
+ cfg = {
+ dataProvider: this.dataProvider,
+ keys: this.dataKeys,
+ position: position
+ };
+ if(position === "right" || position === "left") {
+ cfg.height = this.height;
+ } else {
+ cfg.width = this.width;
+ }
+ this.axis = new Y.CategoryAxis(cfg);
},
tearDown: function() {
this.axis = null;
},
+ _getDataFromLabelValues: function(startPoint, labelValues, edgeOffset, multiplier, direction, data)
+ {
+ var points = [],
+ values = [],
+ labelValue,
+ labelIndex,
+ i,
+ len = labelValues.length,
+ staticCoord,
+ dynamicCoord,
+ constantVal,
+ newPoint,
+ rawVal;
+ if(direction === "vertical")
+ {
+ staticCoord = "x";
+ dynamicCoord = "y";
+ }
+ else
+ {
+ staticCoord = "y";
+ dynamicCoord = "x";
+ }
+ constantVal = startPoint[staticCoord];
+ for(i = 0; i < len; i = i + 1)
+ {
+ labelValue = labelValues[i];
+ labelIndex = Y.Array.indexOf(data, labelValues);
+ if(Y.Lang.isNumber(labelIndex) && labelIndex > -1)
+ {
+ rawVal = labelIndex ? (labelIndex * multiplier) : 0;
+ newPoint = {};
+ newPoint[staticCoord] = constantVal;
+ newPoint[dynamicCoord] = rawVal + edgeOffset;
+ points.push(newPoint);
+ values.push(labelValue);
+ }
+ }
+ return {
+ points: points,
+ values: values
+ };
+ },
+
"test: getMajorUnitDistance()" : function() {
var position = this.position,
vertical = position === "left" || position === "right",
@@ -116,6 +167,72 @@ YUI.add('axis-category-tests', function(Y) {
}
axis.destroy(true);
mydiv.destroy(true);
+ },
+
+ "test: _getDataFromLabelValues()" : function() {
+ var axis = this.axis,
+ labelValues = [
+ "01/02/2009",
+ "01/07/2009",
+ "01/12/2009",
+ "01/17/2009",
+ "01/22/2009"
+ ],
+ len,
+ i,
+ layoutLength = axis.getLength(),
+ data = axis.get("data"),
+ startPoint = axis.getFirstPoint(axis._layout.getLineStart.apply(axis)),
+ edgeOffset = 0,
+ multiplier = (layoutLength - (edgeOffset * 2))/(axis.getTotalMajorUnits() - 1),
+ position = this.position,
+ direction = position === "left" || position === "right" ? "vertical" : "horizontal",
+ axisLabelValues,
+ testLabelValues,
+ axisPoint,
+ testPoint,
+ data = axis.get("data"),
+ assertFn = function() {
+ axisLabelData = axis._getDataFromLabelValues.apply(axis, [
+ startPoint,
+ labelValues,
+ edgeOffset,
+ layoutLength,
+ direction
+ ]);
+ testLabelData = this._getDataFromLabelValues(
+ startPoint,
+ labelValues,
+ edgeOffset,
+ multiplier,
+ direction,
+ data
+ );
+ testPoints = testLabelData.points;
+ testValues = testLabelData.values;
+ axisPoints = axisLabelData.points;
+ axisValues = axisLabelData.values;
+ len = testPoints.length;
+ for(i = 0; i < len; i = i + 1) {
+ testPoint = testPoints[i];
+ axisPoint = axisPoints[i];
+ testValue = testValues[i];
+ axisValue = axisPoints[i];
+ if(testPoint) {
+ Y.Assert.areEqual(testPoint.x, axisPoint.x, "The x value for the " + i + " index of the axis points should be " + testPoint.x + ".");
+ Y.Assert.areEqual(testPoint.y, axisPoint.y, "The y value for the " + i + " index of the axis points should be " + testPoint.y + ".");
+ } else {
+ Y.Assert.isNull(axisPoint, "There should not be a value for the axis point.");
+ }
+ }
+ };
+ assertFn.apply(this);
+ //hit the branch
+ labelValues[3] = "2/11/2012";
+ assertFn.apply(this);
+ //use labels that include the first (to hit another branch)
+ labelValues = ["01/01/2009", "01/11/2009", "01/21/2009"];
+ assertFn.apply(this);
}
});
@@ -148,27 +265,31 @@ YUI.add('axis-category-tests', function(Y) {
dataProvider: plainOldDataProvider,
dataKeys: ["date"],
position: "left",
+ height: 400,
name: "CategoryAxis Tests"
}));
suite.add(new Y.CategoryAxisTest({
dataProvider: plainOldDataProvider,
dataKeys: ["date"],
position: "top",
+ width: 700,
name: "CategoryAxis Tests"
}));
suite.add(new Y.CategoryAxisTest({
dataProvider: plainOldDataProvider,
dataKeys: ["date"],
position: "right",
+ height: 400,
name: "CategoryAxis Tests"
}));
suite.add(new Y.CategoryAxisTest({
dataProvider: plainOldDataProvider,
dataKeys: ["date"],
position: "bottom",
+ width: 700,
name: "CategoryAxis Tests"
}));
Oops, something went wrong.

0 comments on commit 6a50106

Please sign in to comment.