mirror of
https://github.com/konvajs/konva.git
synced 2025-05-03 12:27:47 +08:00
added unit tests for Jonathan\'s toJSON() fix
This commit is contained in:
parent
ca6e8f1d14
commit
40a92a9988
14
dist/kinetic-core.js
vendored
14
dist/kinetic-core.js
vendored
@ -1725,18 +1725,16 @@ Kinetic.Stage.prototype = {
|
|||||||
function addNode(node) {
|
function addNode(node) {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
|
|
||||||
var cleanAttrs = node.attrs;
|
obj.attrs = {};
|
||||||
|
|
||||||
// remove function, image, DOM, and objects with methods
|
// serialize only attributes that are not function, image, DOM, or objects with methods
|
||||||
for(var key in cleanAttrs) {
|
for(var key in node.attrs) {
|
||||||
var val = cleanAttrs[key];
|
var val = node.attrs[key];
|
||||||
if(go._isFunction(val) || go._isElement(val) || go._hasMethods(val)) {
|
if(!go._isFunction(val) && !go._isElement(val) && !go._hasMethods(val)) {
|
||||||
cleanAttrs[key] = undefined;
|
obj.attrs[key] = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.attrs = cleanAttrs;
|
|
||||||
|
|
||||||
obj.nodeType = node.nodeType;
|
obj.nodeType = node.nodeType;
|
||||||
obj.shapeType = node.shapeType;
|
obj.shapeType = node.shapeType;
|
||||||
|
|
||||||
|
2
dist/kinetic-core.min.js
vendored
2
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
8
tests/assets/unitDataUrls.js
Normal file
8
tests/assets/unitDataUrls.js
Normal file
File diff suppressed because one or more lines are too long
@ -14,7 +14,7 @@
|
|||||||
</style>
|
</style>
|
||||||
<link rel="stylesheet" type="text/css"href="../base.css">
|
<link rel="stylesheet" type="text/css"href="../base.css">
|
||||||
<script src="../../dist/kinetic-core.js"></script>
|
<script src="../../dist/kinetic-core.js"></script>
|
||||||
<script src="../assets/dataUrls.js"></script>
|
<script src="../assets/functionalDataUrls.js"></script>
|
||||||
<script src="../js/Test.js"></script>
|
<script src="../js/Test.js"></script>
|
||||||
<script src="../js/functionalTests.js"></script>
|
<script src="../js/functionalTests.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<script src="../../dist/kinetic-core.js"></script>
|
<script src="../../dist/kinetic-core.js"></script>
|
||||||
<script src="../assets/worldMap.js"></script>
|
<script src="../assets/worldMap.js"></script>
|
||||||
<script src="../assets/tiger.js"></script>
|
<script src="../assets/tiger.js"></script>
|
||||||
|
<script src="../assets/unitDataUrls.js"></script>
|
||||||
<script src="../js/Test.js"></script>
|
<script src="../js/Test.js"></script>
|
||||||
<script src="../js/unitTests.js"></script>
|
<script src="../js/unitTests.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
@ -328,6 +328,8 @@ Test.prototype.tests = {
|
|||||||
//test(stage.toJSON() === json, "problem loading stage with json");
|
//test(stage.toJSON() === json, "problem loading stage with json");
|
||||||
},
|
},
|
||||||
'STAGE - serialize stage with custom shape': function(containerId) {
|
'STAGE - serialize stage with custom shape': function(containerId) {
|
||||||
|
var urls = dataUrls['STAGE - serialize stage with custom shape'];
|
||||||
|
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
container: containerId,
|
container: containerId,
|
||||||
width: 578,
|
width: 578,
|
||||||
@ -359,10 +361,26 @@ Test.prototype.tests = {
|
|||||||
group.add(triangle);
|
group.add(triangle);
|
||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
test(triangle.getId() === 'myTriangle', 'triangle id should be myTriangle');
|
stage.toDataURL(function(startDataUrl) {
|
||||||
|
test(startDataUrl === urls[0], 'start data url is incorrect');
|
||||||
|
|
||||||
var expectedJson = '{"attrs":{"width":578,"height":200,"throttle":80,"visible":true,"listen":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"throttle":80,"visible":true,"listen":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listen":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Group","children":[{"attrs":{"fill":"#00D2FF","stroke":"black","strokeWidth":4,"detectionType":"path","shadow":{"blur":10,"alpha":1,"offset":{"x":0,"y":0}},"visible":true,"listen":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"id":"myTriangle"},"nodeType":"Shape"}]}]}]}';
|
test(triangle.getId() === 'myTriangle', 'triangle id should be myTriangle');
|
||||||
//test(stage.toJSON() === expectedJson, "problem serializing stage with custom shape");
|
|
||||||
|
//console.log(stage.toJSON())
|
||||||
|
|
||||||
|
var expectedJson = '{"attrs":{"width":578,"height":200,"throttle":80,"visible":true,"listening":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Stage","children":[{"attrs":{"throttle":80,"visible":true,"listening":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Layer","children":[{"attrs":{"visible":true,"listening":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false},"nodeType":"Group","children":[{"attrs":{"fill":"#00D2FF","stroke":"black","strokeWidth":4,"detectionType":"path","shadow":{"blur":10,"alpha":1,"offset":{"x":0,"y":0}},"visible":true,"listening":true,"alpha":1,"x":0,"y":0,"scale":{"x":1,"y":1},"rotation":0,"offset":{"x":0,"y":0},"dragConstraint":"none","dragBounds":{},"draggable":false,"id":"myTriangle"},"nodeType":"Shape"}]}]}]}';
|
||||||
|
test(stage.toJSON() === expectedJson, "problem serializing stage with custom shape");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* test redrawing layer after serialization
|
||||||
|
* drawing should be the same
|
||||||
|
*/
|
||||||
|
layer.draw();
|
||||||
|
|
||||||
|
stage.toDataURL(function(endDataUrl) {
|
||||||
|
test(endDataUrl === urls[0], 'end data url is incorrect');
|
||||||
|
});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
'STAGE - load stage with custom shape using json': function(containerId) {
|
'STAGE - load stage with custom shape using json': function(containerId) {
|
||||||
var stage = new Kinetic.Stage({
|
var stage = new Kinetic.Stage({
|
||||||
@ -2996,7 +3014,7 @@ Test.prototype.tests = {
|
|||||||
var offsetChange = false;
|
var offsetChange = false;
|
||||||
var shadowOffsetChange = false;
|
var shadowOffsetChange = false;
|
||||||
|
|
||||||
rect.on('offsetChange', function() {
|
rect.on('offsetChange', function(val) {
|
||||||
offsetChange = true;
|
offsetChange = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user