mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
add test to check deserialized piskel contains valid frames
This commit is contained in:
parent
dda566a218
commit
dd9b1e0189
@ -7,10 +7,41 @@ describe("Serialization/Deserialization test", function() {
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
delete pskl.app.piskelController;
|
||||
});
|
||||
|
||||
if("serializes frames correctly", function () {
|
||||
// Create piskel.
|
||||
var descriptor = new pskl.model.piskel.Descriptor('piskelName', 'piskelDesc');
|
||||
var piskel = new pskl.model.Piskel(1, 1, 1, descriptor);
|
||||
// Add layer.
|
||||
piskel.addLayer(new pskl.model.Layer('layer1'));
|
||||
// Add frame.
|
||||
piskel.getLayerAt(0).addFrame(pskl.model.Frame.fromPixelGrid([
|
||||
["red", "black"],
|
||||
["blue", "green"]
|
||||
]));
|
||||
|
||||
// Verify the frame is successfully added in the layer.
|
||||
expect(piskel.getLayerAt(0).getFrames().length).toBe(1);
|
||||
|
||||
var serializedPiskel = pskl.utils.serialization.Serializer.serialize(piskel);
|
||||
|
||||
var deserializer = pskl.utils.serialization.Deserializer;
|
||||
deserializer.deserialize(JSON.parse(serializedPiskel), function (p) {
|
||||
// Check the frame has been properly deserialized
|
||||
expect(p.getLayerAt(0).getFrames().length).toBe(1);
|
||||
var frame = p.getLayerAt(0).getFrameAt(0);
|
||||
test.testutils.frameEqualsGrid(flattened, [
|
||||
["red", "black"],
|
||||
["blue", "green"]
|
||||
]);
|
||||
done();
|
||||
});
|
||||
})
|
||||
|
||||
it("serializes layer opacity", function(done) {
|
||||
var descriptor = new pskl.model.piskel.Descriptor('piskelName', 'piskelDesc');
|
||||
var piskel = new pskl.model.Piskel(1, 1, 1, descriptor);
|
||||
@ -35,7 +66,10 @@ describe("Serialization/Deserialization test", function() {
|
||||
expect(p.getLayerAt(0).getOpacity()).toBe(0);
|
||||
expect(p.getLayerAt(1).getOpacity()).toBe(0.3);
|
||||
expect(p.getLayerAt(2).getOpacity()).toBe(0.9);
|
||||
|
||||
// Check the serialization was successful
|
||||
expect(p.getLayerAt(0).getFrames().length).toBe(1);
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user