mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Add tests for Layer & PathStyle.
This commit is contained in:
parent
4000853c2f
commit
d7dca48e00
3 changed files with 177 additions and 0 deletions
|
@ -18,6 +18,7 @@
|
|||
<script type="text/javascript" src="../src/path/PathItem.js"></script>
|
||||
<script type="text/javascript" src="../src/path/Path.js"></script>
|
||||
<script type="text/javascript" src="../src/document/Doc.js"></script>
|
||||
<script type="text/javascript" src="../src/item/PathStyle.js"></script>
|
||||
<script type="text/javascript" src="lib/qunit/qunit.js"></script>
|
||||
|
||||
<!-- Test Helpers -->
|
||||
|
@ -29,12 +30,14 @@
|
|||
<script type="text/javascript" src="tests/Rectangle.js"></script>
|
||||
<script type="text/javascript" src="tests/Document.js"></script>
|
||||
<script type="text/javascript" src="tests/Item.js"></script>
|
||||
<script type="text/javascript" src="tests/Layer.js"></script>
|
||||
<script type="text/javascript" src="tests/Group.js"></script>
|
||||
<script type="text/javascript" src="tests/Segment.js"></script>
|
||||
<script type="text/javascript" src="tests/Path.js"></script>
|
||||
<script type="text/javascript" src="tests/Path_Shapes.js"></script>
|
||||
<script type="text/javascript" src="tests/Path_Drawing_Commands.js"></script>
|
||||
<script type="text/javascript" src="tests/Path_Bounds.js"></script>
|
||||
<script type="text/javascript" src="tests/PathStyle.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="qunit-header">QUnit Test Suite</h1>
|
||||
|
|
44
test/tests/Layer.js
Normal file
44
test/tests/Layer.js
Normal file
|
@ -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);
|
||||
});
|
130
test/tests/PathStyle.js
Normal file
130
test/tests/PathStyle.js
Normal file
|
@ -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');
|
||||
});
|
Loading…
Reference in a new issue