mirror of
https://github.com/igorski/bitmappery.git
synced 2026-07-05 14:59:15 +02:00
Implemented layer mirroring effect
This commit is contained in:
41
tests/unit/factories/effects-factory.spec.js
Normal file
41
tests/unit/factories/effects-factory.spec.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import EffectsFactory from "@/factories/effects-factory";
|
||||
|
||||
describe( "Effects factory", () => {
|
||||
describe( "when creating a new Effects list", () => {
|
||||
it( "should create a default Effects structure when no arguments are passed", () => {
|
||||
const effects = EffectsFactory.create();
|
||||
expect( effects ).toEqual({
|
||||
mirrorX: false,
|
||||
mirrorY: false,
|
||||
rotation: expect.any( Number )
|
||||
});
|
||||
});
|
||||
|
||||
it( "should be able to create a Effects list from given arguments", () => {
|
||||
const effects = EffectsFactory.create({
|
||||
mirrorX: true,
|
||||
mirrorY: true,
|
||||
rotation: -90
|
||||
});
|
||||
expect( effects ).toEqual({
|
||||
mirrorX: true,
|
||||
mirrorY: true,
|
||||
rotation: -90
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe( "when serializing and deserializing a Effects list", () => {
|
||||
it( "should do so without data loss", async () => {
|
||||
const effects = EffectsFactory.create({
|
||||
mirrorX: true,
|
||||
mirrorY: true,
|
||||
rotation: 270
|
||||
});
|
||||
const serialized = EffectsFactory.serialize( effects );
|
||||
const deserialized = EffectsFactory.deserialize( serialized );
|
||||
|
||||
expect( deserialized ).toEqual( effects );
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -6,10 +6,17 @@ jest.mock( "@/utils/canvas-util", () => ({
|
||||
imageToBase64: (...args) => mockUpdateFn?.( "imageToBase64", ...args ),
|
||||
base64ToLayerImage: (...args) => mockUpdateFn?.( "base64ToLayerImage", ...args ),
|
||||
}));
|
||||
jest.mock( "@/factories/effects-factory", () => ({
|
||||
create: (...args) => mockUpdateFn?.( "create", ...args ),
|
||||
serialize: (...args) => mockUpdateFn?.( "serialize", ...args ),
|
||||
deserialize: (...args) => mockUpdateFn?.( "deserialize", ...args ),
|
||||
}));
|
||||
|
||||
describe( "Layer factory", () => {
|
||||
describe( "when creating a new layer", () => {
|
||||
it( "should create a default Layer structure when no arguments are passed", () => {
|
||||
const mockEffects = { foo: "bar" };
|
||||
mockUpdateFn = fn => fn === "create" ? mockEffects : {};
|
||||
const layer = LayerFactory.create();
|
||||
expect( layer ).toEqual({
|
||||
id: expect.any( String ),
|
||||
@@ -24,14 +31,13 @@ describe( "Layer factory", () => {
|
||||
width: 1,
|
||||
height: 1,
|
||||
visible: true,
|
||||
effects: {
|
||||
rotation: 0,
|
||||
},
|
||||
effects: mockEffects,
|
||||
selection: null,
|
||||
});
|
||||
});
|
||||
|
||||
it( "should be able to create a layer from given arguments", () => {
|
||||
mockUpdateFn = ( fn, data ) => data;
|
||||
const layer = LayerFactory.create({
|
||||
name: "foo",
|
||||
type: LAYER_IMAGE,
|
||||
@@ -70,32 +76,33 @@ describe( "Layer factory", () => {
|
||||
});
|
||||
|
||||
describe( "when serializing and deserializing a Layer", () => {
|
||||
const layer = LayerFactory.create({
|
||||
name: "foo",
|
||||
type: LAYER_IMAGE,
|
||||
source: { src: "bitmap" },
|
||||
mask: { src: "mask" },
|
||||
x: 100,
|
||||
y: 50,
|
||||
width: 16,
|
||||
height: 9,
|
||||
visible: false,
|
||||
effects: {
|
||||
rotation: -90,
|
||||
},
|
||||
});
|
||||
|
||||
it( "should do so without data loss", async () => {
|
||||
mockUpdateFn = jest.fn(( fn, data ) => JSON.stringify( data ));
|
||||
const layer = LayerFactory.create({
|
||||
name: "foo",
|
||||
type: LAYER_IMAGE,
|
||||
source: { src: "bitmap" },
|
||||
mask: { src: "mask" },
|
||||
x: 100,
|
||||
y: 50,
|
||||
width: 16,
|
||||
height: 9,
|
||||
visible: false,
|
||||
effects: {
|
||||
rotation: -90,
|
||||
},
|
||||
});
|
||||
mockUpdateFn = jest.fn(( fn, data ) => data );
|
||||
|
||||
const serialized = LayerFactory.serialize( layer );
|
||||
expect( mockUpdateFn ).toHaveBeenNthCalledWith( 1, "imageToBase64", layer.source, layer.width, layer.height );
|
||||
expect( mockUpdateFn ).toHaveBeenNthCalledWith( 2, "imageToBase64", layer.mask, layer.width, layer.height );
|
||||
expect( mockUpdateFn ).toHaveBeenNthCalledWith( 3, "serialize", layer.effects );
|
||||
|
||||
mockUpdateFn = jest.fn(( fn, data ) => JSON.parse( data ));
|
||||
mockUpdateFn = jest.fn(( fn, data ) => data );
|
||||
const deserialized = await LayerFactory.deserialize( serialized );
|
||||
expect( mockUpdateFn ).toHaveBeenNthCalledWith( 1, "base64ToLayerImage", expect.any( String ), LAYER_IMAGE, layer.width, layer.height );
|
||||
expect( mockUpdateFn ).toHaveBeenNthCalledWith( 2, "base64ToLayerImage", expect.any( String ), LAYER_MASK, layer.width, layer.height );
|
||||
expect( mockUpdateFn ).toHaveBeenNthCalledWith( 1, "base64ToLayerImage", expect.any( Object ), LAYER_IMAGE, layer.width, layer.height );
|
||||
expect( mockUpdateFn ).toHaveBeenNthCalledWith( 2, "base64ToLayerImage", expect.any( Object ), LAYER_MASK, layer.width, layer.height );
|
||||
expect( mockUpdateFn ).toHaveBeenNthCalledWith( 3, "deserialize", layer.effects );
|
||||
|
||||
// note id's are unique per created session instance and therefor will differ
|
||||
expect({
|
||||
|
||||
Reference in New Issue
Block a user