From d7dca48e007775899effbf42735f30153bad3fdd Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Wed, 16 Feb 2011 22:11:26 +0100 Subject: [PATCH] Add tests for Layer & PathStyle. --- test/index.html | 3 + test/tests/Layer.js | 44 ++++++++++++++ test/tests/PathStyle.js | 130 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 test/tests/Layer.js create mode 100644 test/tests/PathStyle.js diff --git a/test/index.html b/test/index.html index d9b49da3..16b85fce 100644 --- a/test/index.html +++ b/test/index.html @@ -18,6 +18,7 @@ + @@ -29,12 +30,14 @@ + +

QUnit Test Suite

diff --git a/test/tests/Layer.js b/test/tests/Layer.js new file mode 100644 index 00000000..cc608b0d --- /dev/null +++ b/test/tests/Layer.js @@ -0,0 +1,44 @@ +module('Layer'); + +test('previousSibling / nextSibling', function() { + var doc = new Doc(); + var firstLayer = doc.activeLayer; + var secondLayer = new Layer(); + equals(secondLayer.previousSibling == firstLayer, true); + equals(secondLayer.nextSibling == null, true); + + // Move another layer into secondLayer and check nextSibling / + // previousSibling: + var path = new Path(); + var thirdLayer = new Layer(); + secondLayer.appendBottom(thirdLayer); + equals(secondLayer.children.length, 2); + equals(thirdLayer.nextSibling == path, true); + secondLayer.appendTop(thirdLayer); + equals(thirdLayer.nextSibling == null, true); + equals(thirdLayer.previousSibling == path, true); + equals(doc.layers.length == 2, true); + + firstLayer.appendTop(secondLayer); + equals(doc.layers.length == 1, true); +}); + +test('moveAbove / moveBelow', function() { + var doc = new Doc(); + var firstLayer = doc.activeLayer; + var secondLayer = new Layer(); + secondLayer.moveBelow(firstLayer); + equals(secondLayer.previousSibling == null, true); + equals(secondLayer.nextSibling == firstLayer, true); + + var path = new Path(); + firstLayer.appendTop(path); + + // move the layer above the path, inside the firstLayer: + secondLayer.moveAbove(path); + equals(secondLayer.previousSibling == path, true); + equals(secondLayer.parent == firstLayer, true); + + // There should now only be one layer left: + equals(doc.layers.length, 1); +}); \ No newline at end of file diff --git a/test/tests/PathStyle.js b/test/tests/PathStyle.js new file mode 100644 index 00000000..627aaf02 --- /dev/null +++ b/test/tests/PathStyle.js @@ -0,0 +1,130 @@ +module('Path Style'); + +test('currentStyle', function() { + var doc = new Doc(); + doc.currentStyle.fillColor = 'black'; + var path = new Path(); + equals(path.fillColor, 'black'); + + // When changing the current style of the document, the style of + // paths created using document.currentStyle should not change. + doc.currentStyle.fillColor = 'red'; + equals(path.fillColor, 'black'); +}); + +test('setting currentStyle to an object', function() { + var doc = new Doc(); + doc.currentStyle = { + fillColor: 'red', + strokeColor: 'green' + }; + var path = new Path(); + equals(path.fillColor, 'red'); + equals(path.strokeColor, 'green'); +}); + +test('setting path styles to an object', function() { + var doc = new Doc(); + var path = new Path(); + path.style = { + fillColor: 'red', + strokeColor: 'green' + }; + equals(path.fillColor, 'red'); + equals(path.strokeColor, 'green'); +}); + +test('setting group styles to an object', function() { + var doc = new Doc(); + var group = new Group(); + var path = new Path(); + group.appendTop(path); + group.style = { + fillColor: 'red', + strokeColor: 'green' + }; + equals(path.fillColor, 'red'); + equals(path.strokeColor, 'green'); +}); + +test('getting group styles', function() { + var doc = new Doc(); + var group = new Group(); + var path = new Path(); + path.fillColor = 'red'; + group.appendTop(path); + + equals(group.fillColor, 'red'); + + var secondPath = new Path(); + secondPath.fillColor = 'black'; + group.appendTop(secondPath); + + // the group now contains two paths with different fillColors and therefore + // should return null: + equals(group.fillColor, null); + + //If we remove the first path, it should now return 'black': + group.children[0].remove(); + equals(group.fillColor, 'black'); +}); + +test('setting group styles', function() { + var doc = new Doc(); + var group = new Group(); + var path = new Path(); + path.fillColor = 'red'; + group.appendTop(path); + + var secondPath = new Path(); + secondPath.fillColor = 'blue'; + secondPath.strokeColor = 'red'; + group.appendTop(secondPath); + + // Change the fill color of the group: + group.fillColor = 'black'; + + // the paths contained in the group should now both have their fillColor + // set to black: + equals(path.fillColor, 'black'); + equals(secondPath.fillColor, 'black'); + + // The second path still has its strokeColor set to red: + equals(secondPath.strokeColor, 'red'); +}); + +test('setting group styles 2', function() { + var doc = new Doc(); + var group = new Group(); + var path = new Path(); + path.fillColor = 'red'; + group.appendTop(path); + + equals(group.fillColor, 'red'); + + var secondPath = new Path(); + secondPath.fillColor = 'blue'; + secondPath.strokeColor = 'red'; + group.appendTop(secondPath); + + equals(secondPath.fillColor, 'blue'); + equals(secondPath.strokeColor, 'red'); + + // By appending a path with a different fillcolor, + // the group's fillColor should return null: + equals(group.fillColor, null); + + // But, both paths have a red strokeColor, so: + equals(group.strokeColor, 'red'); + + // Change the fill color of the group's style: + group.style.fillColor = 'black'; + + // the paths contained in the group should now both have their fillColor + // set to black: + equals(path.fillColor, 'black'); + equals(secondPath.fillColor, 'black'); + + // The second path still has its strokeColor set to red: + equals(secondPath.strokeColor, 'red'); +}); \ No newline at end of file