Permalink
Browse files

Merge branch 'trac2533210' into dev-master

Graphics tests.
  • Loading branch information...
tripp committed Apr 1, 2013
2 parents 69b9d4a + 514ec61 commit 6b0f860f0d80ffb01cf327df7ebc70742ffa1a34
@@ -0,0 +1,95 @@
+YUI.add('drawing-tests', function(Y) {
+
+var parentDiv = Y.DOM.create('<div id="testdiv" style="width: 400px; height: 400px;">'),
+ suite = new Y.Test.Suite("Graphics: Drawing"),
+ drawingTests = new Y.Test.Case({
+
+ setUp: function() {
+ this.graphic = new Y.Graphic({
+ render: parentDiv
+ });
+ this.path = this.graphic.addShape({
+ type: "path"
+ });
+ },
+
+ tearDown: function() {
+ this.graphic.destroy();
+ },
+
+ "test: moveTo()" : function() {
+ Y.Assert.areEqual(this.path, this.path.moveTo(10, 10), "The moveTo method should return a reference to the path.");
+ },
+
+ "test: relativeMoveTo()" : function() {
+ Y.Assert.areEqual(this.path, this.path.relativeMoveTo(10, 10), "The relativeMoveTo method should return a reference to the path.");
+ },
+
+ "test: lineTo()" : function() {
+ Y.Assert.areEqual(this.path, this.path.lineTo(10, 10), "The lineTo method should return a reference to the path.");
+ Y.Assert.areEqual(this.path, this.path.lineTo(10, 10, 20, 10, 20, 20, 10, 20, 10, 10), "The lineTo method should return a reference to the path.");
+ Y.Assert.areEqual(this.path, this.path.lineTo([10, 10], [20, 10], [20, 20], [10, 20], [10, 10]), "The lineTo method should return a reference to the path.");
+ },
+
+ "test: relativeLineTo()" : function() {
+ Y.Assert.areEqual(this.path, this.path.relativeLineTo(10, 10), "The relativeLineTo method should return a reference to the path.");
+ },
+
+ "test: curveTo()" : function() {
+ Y.Assert.areEqual(this.path, this.path.curveTo(83.5, 0, 100.5, 17, 100, 50), "The curveTo method should return a reference to the path.");
+ Y.Assert.areEqual(this.path, this.path.curveTo(83.5, 0, 100.5, 17, 100, 50), "The curveTo method should return a reference to the path.");
+ this.path._pathArray = [];
+ Y.Assert.areEqual(this.path, this.path.curveTo(83.5, 0, 100.5, 17, 100, 50), "The curveTo method should return a reference to the path.");
+ },
+
+ "test: relativeCurveTo()" : function() {
+ Y.Assert.areEqual(this.path, this.path.relativeCurveTo(83.5, 0, 100.5, 17, 100, 50), "The relativeCurveTo method should return a reference to the path.");
+ },
+
+ "test: quadraticCurveTo()" : function() {
+ Y.Assert.areEqual(this.path, this.path.quadraticCurveTo(10, 0, 10, 5), "The quadraticCurveTo method should return a reference to the path.");
+ Y.Assert.areEqual(this.path, this.path.quadraticCurveTo(10, 0, 10, 5), "The quadraticCurveTo method should return a reference to the path.");
+ this.path._pathArray = [];
+ Y.Assert.areEqual(this.path, this.path.quadraticCurveTo(10, 0, 10, 5), "The quadraticCurveTo method should return a reference to the path.");
+ },
+
+ "test: relativeQuadraticCurveTo()" : function() {
+ Y.Assert.areEqual(this.path, this.path.relativeQuadraticCurveTo(10, 0, 10, 5), "The relativeQuadraticCurveTo method should return a reference to the path.");
+ },
+
+ "test: drawRect()" : function() {
+ Y.Assert.areEqual(this.path, this.path.drawRect(0, 0, 20, 10), "The drawRect method should return a reference to the path.");
+ },
+
+ "test: drawRoundRect()" : function() {
+ Y.Assert.areEqual(this.path, this.path.drawRoundRect(0, 0, 200, 100, 4, 4), "The drawRoundRect method should return a reference to the path.");
+ },
+
+ "test: drawEllipse()" : function() {
+ Y.Assert.areEqual(this.path, this.path.drawEllipse(0, 0, 20, 10), "The drawEllipse method should return a reference to the path.");
+ },
+
+ "test: drawCircle()" : function() {
+ Y.Assert.areEqual(this.path, this.path.drawCircle(0, 0, 10), "The drawCircle method should return a reference to the path.");
+ },
+
+ "test: drawDiamond()" : function() {
+ Y.Assert.areEqual(this.path, this.path.drawDiamond(0, 0, 20, 10), "The drawDiamond method should return a reference to the path.");
+ },
+
+ "test: drawWedge()" : function() {
+ Y.Assert.areEqual(this.path, this.path.drawWedge(175, 175, -3, 87, 175), "The drawWedge method should return a reference to the path.");
+ this.path.moveTo(100, 85);
+ Y.Assert.areEqual(this.path, this.path.drawWedge(175, 175, -3, 87, 175), "The drawWedge method should return a reference to the path.");
+ //hit over 360 branch
+ Y.Assert.areEqual(this.path, this.path.drawWedge(175, 175, -3, 365, 175), "The drawWedge method should return a reference to the path.");
+ //hit 0 segs branch
+ Y.Assert.areEqual(this.path, this.path.drawWedge(175, 175, -3, 0, 175), "The drawWedge method should return a reference to the path.");
+ }
+ });
+
+ suite.add(drawingTests);
+ Y.Test.Runner.add( suite );
+
+
+}, '@VERSION@' ,{requires:['graphics', 'test']});
@@ -428,10 +428,13 @@ setPathDataTest = function(name, attrs, pathData)
testDefault: function()
{
- var pathData = this.pathData,
- mypath = this.path,
+ var mypath = this.path,
pathAttr = mypath.get("path");
Y.Assert.areEqual(pathData, mypath.get("data"), "The path data should be " + pathData);
+ mypath.set("data", pathData2);
+ Y.Assert.areEqual(pathData2, mypath.get("data"), "The path data should be " + pathData2 + ".");
+ mypath.set("data", "");
+ Y.Assert.areEqual("", mypath.get("data"), "The path data should be an empty string.");
}
});
};
@@ -476,7 +479,6 @@ suite.add(drawWedgeTest("DrawWedgeTestStrokeAndFill", strokeAndFill));
suite.add(drawWedgeTest("DrawWedgeTestStrokeNoFill", strokeNoFill));
suite.add(drawWedgeTest("DrawWedgeTestFillNoStroke", fillNoStroke));
suite.add(setPathDataTest("TestPathDataAttr", {data: pathData}, pathData));
-suite.add(setPathDataTest("TestPathDataAttr", {data: pathData2}, pathData2));
Y.Test.Runner.add( suite );
@@ -0,0 +1,121 @@
+YUI.add('shape-tests', function(Y) {
+
+var parentDiv = Y.DOM.create('<div id="testdiv" style="width: 400px; height: 400px;">'),
+ suite = new Y.Test.Suite("Graphics: Shape"),
+ shapeTests;
+ document.body.appendChild(parentDiv);
+
+ shapeTests = new Y.Test.Case({
+
+ setUp: function() {
+ this.graphic = new Y.Graphic({
+ render: parentDiv
+ });
+ this.shape = this.graphic.addShape({
+ type: "path",
+ });
+ },
+
+ tearDown: function() {
+ this.graphic.destroy();
+ },
+
+ "test: new Y.Shape()" : function() {
+ Y.Assert.isInstanceOf(Y.Shape, this.shape, "This should be an instance of Y.Shape.");
+ },
+
+ "test: initializer()" : function() {
+ function MockInitializerShape() {}
+ MockInitializerShape.prototype = {
+ _setGraphicCalled: false,
+ _parsePathDataCalled: false,
+ _updateHandlerCalled: false,
+ _setGraphic: function() {
+ this._setGraphicCalled = true;
+ },
+ _parsePathData: function() {
+ this._parsePathDataCalled = true;
+ },
+ _updateHandler: function() {
+ this._updateHandlerCalled = true;
+ },
+ get: function() {
+ return this._pathData;
+ },
+ createNode: function() {},
+ _initProps: function() {}
+ };
+ var mockShape = new MockInitializerShape(),
+ shape = this.shape;
+ shape.initializer.apply(mockShape, [{}]);
+ Y.Assert.isFalse(mockShape._setGraphicCalled, "The _setGraphic method should not be called when a graphic is not available.");
+ Y.Assert.isFalse(mockShape._parsePathDataCalled, "The _parsePathData method should not be called when a graphic is not available.");
+ Y.Assert.isTrue(mockShape._updateHandlerCalled, "the _updateHandler method should have been called.");
+ mockShape._pathData = "M5, 0l100, 215 c 150 60 150 60 300 0z";
+ shape.initializer.apply(mockShape, [{graphic: this.graphic}]);
+ Y.Assert.isTrue(mockShape._setGraphicCalled, "The _setGraphic method should have been called.");
+ Y.Assert.isTrue(mockShape._parsePathDataCalled, "The _parsePathData method should have been called.");
+ },
+
+ "test: on()" : function() {
+ var shape = this.shape,
+ handler = function() {
+ //do nothing
+ },
+ handle = this.shape.on("click", handler);
+ Y.Assert.isObject(handle, "The handle should have been set.");
+ Y.Assert.areEqual("click", handle.evt.type, "The event should be a click event.");
+ handle = shape.on("customEvent", handler);
+ Y.Assert.areEqual("customEvent", handle.evt.type, "The event should be a customEvent.");
+ },
+
+ "test: toFront()" : function() {
+ function MockToFrontShape() {}
+ MockToFrontShape.prototype = {
+ mockGraphic: null,
+ get: function() {
+ return this.mockGraphic;
+ }
+ }
+ var shape = this.shape,
+ mockShape = new MockToFrontShape(),
+ graphicToFrontCalled = false;
+ shape.toFront.apply(mockShape);
+ Y.Assert.isFalse(graphicToFrontCalled, "There is no graphic, so the toFront method could not be called.");
+ mockShape.mockGraphic = {
+ _toFront: function() {
+ graphicToFrontCalled = true;
+ }
+ };
+ shape.toFront.apply(mockShape);
+ Y.Assert.isTrue(graphicToFrontCalled, "The graphic's toFront method should have been called.");
+ },
+
+ "test: toBack()" : function() {
+ function MockToBackShape() {}
+ MockToBackShape.prototype = {
+ mockGraphic: null,
+ get: function() {
+ return this.mockGraphic;
+ }
+ }
+ var shape = this.shape,
+ mockShape = new MockToBackShape(),
+ graphicToBackCalled = false;
+ shape.toBack.apply(mockShape);
+ Y.Assert.isFalse(graphicToBackCalled, "There is no graphic, so the toBack method could not be called.");
+ mockShape.mockGraphic = {
+ _toBack: function() {
+ graphicToBackCalled = true;
+ }
+ };
+ shape.toBack.apply(mockShape);
+ Y.Assert.isTrue(graphicToBackCalled, "The graphic's toBack method should have been called.");
+ }
+ });
+
+ suite.add(shapeTests);
+ Y.Test.Runner.add( suite );
+
+
+}, '@VERSION@' ,{requires:['graphics', 'test']});
@@ -0,0 +1,23 @@
+<!doctype html>
+<html>
+<head>
+ <title>Drawing Tests</title>
+</head>
+<body class="yui3-skin-sam">
+
+<div id="log"></div>
+<script src="../../../../build/yui/yui.js"></script>
+<script src="./assets/drawing-tests.js"></script>
+<script>
+YUI({
+ filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'raw',
+ coverage: ['graphics', 'graphics-canvas', 'graphics-canvas-default', 'graphics-svg', 'graphics-svg-default', 'graphics-vml', 'graphics-vml-default']
+}).use('test-console', 'drawing-tests', function (Y) {
+
+ (new Y.Test.Console()).render( "#log" );
+
+ Y.Test.Runner.run();
+});
+</script>
+</body>
+</html>
@@ -0,0 +1,23 @@
+<!doctype html>
+<html>
+<head>
+ <title>Shape Tests</title>
+</head>
+<body class="yui3-skin-sam">
+
+<div id="log"></div>
+<script src="../../../../build/yui/yui.js"></script>
+<script src="./assets/shape-tests.js"></script>
+<script>
+YUI({
+ filter: (window.location.search.match(/[?&]filter=([^&]+)/) || [])[1] || 'raw',
+ coverage: ['graphics', 'graphics-canvas', 'graphics-canvas-default', 'graphics-svg', 'graphics-svg-default', 'graphics-vml', 'graphics-vml-default']
+}).use('test-console', 'shape-tests', function (Y) {
+
+ (new Y.Test.Console()).render( "#log" );
+
+ Y.Test.Runner.run();
+});
+</script>
+</body>
+</html>

0 comments on commit 6b0f860

Please sign in to comment.