mirror of
https://github.com/igorski/bitmappery.git
synced 2026-06-16 19:25:38 +02:00
Split `definitions/document.ts` into unique files per actor type. Create `model` folder to store the above types, their factories and the state changing actions.
83 lines
2.7 KiB
TypeScript
83 lines
2.7 KiB
TypeScript
import { type Store } from "vuex";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { createStore, mockZCanvas } from "../../mocks";
|
|
|
|
mockZCanvas();
|
|
|
|
import { LayerTypes } from "@/definitions/layer-types";
|
|
import DocumentFactory from "@/model/factories/document-factory";
|
|
import { type BitMapperyState } from "@/store";
|
|
import { addTextLayer } from "@/model/actions/layer-add-text-layer";
|
|
|
|
const mockEnqueueState = vi.fn();
|
|
vi.mock( "@/model/factories/history-state-factory", () => ({
|
|
enqueueState: ( ...args: any[] ) => mockEnqueueState( ...args ),
|
|
}));
|
|
|
|
describe( "add text Layer action", () => {
|
|
let store: Store<BitMapperyState>;
|
|
|
|
beforeEach(() => {
|
|
store = createStore();
|
|
store.getters.activeDocument = DocumentFactory.create();
|
|
store.getters.activeLayerIndex = 3;
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.resetAllMocks();
|
|
});
|
|
|
|
it( "should be able to add a new Text Layer into the Documents Layer list", () => {
|
|
addTextLayer( store );
|
|
|
|
expect( store.commit ).toHaveBeenCalledTimes( 1 );
|
|
expect( store.commit ).toHaveBeenCalledWith( "addLayer", { type: LayerTypes.LAYER_TEXT });
|
|
});
|
|
|
|
it( "should store the action in state history", () => {
|
|
addTextLayer( store );
|
|
|
|
expect( mockEnqueueState ).toHaveBeenCalledWith(
|
|
`layerAdd_${store.getters.activeLayerIndex}`, {
|
|
undo: expect.any( Function ),
|
|
redo: expect.any( Function )
|
|
}
|
|
);
|
|
});
|
|
|
|
it( "should add the Layer to the currently active tile group when the Document is of the timeline type", () => {
|
|
store.getters.activeDocument.type = "timeline";
|
|
store.getters.activeGroup = 2;
|
|
|
|
addTextLayer( store );
|
|
|
|
expect( store.commit ).toHaveBeenCalledWith( "addLayer", {
|
|
type: LayerTypes.LAYER_TEXT,
|
|
rel: {
|
|
type: "tile",
|
|
id: 2
|
|
}
|
|
});
|
|
});
|
|
|
|
it( "should remove the added Text Layer when calling undo in state history", () => {
|
|
addTextLayer( store );
|
|
|
|
const { undo } = mockEnqueueState.mock.calls[ 0 ][ 1 ];
|
|
undo();
|
|
|
|
expect( store.commit ).toHaveBeenCalledTimes( 2 );
|
|
expect( store.commit ).toHaveBeenNthCalledWith( 2, "removeLayer", store.getters.activeLayerIndex );
|
|
});
|
|
|
|
it( "should re-add a Text Layer when calling redo in state history", () => {
|
|
addTextLayer( store );
|
|
|
|
const { undo, redo } = mockEnqueueState.mock.calls[ 0 ][ 1 ];
|
|
undo();
|
|
redo();
|
|
|
|
expect( store.commit ).toHaveBeenCalledTimes( 3 );
|
|
expect( store.commit ).toHaveBeenNthCalledWith( 3, "addLayer", { type: LayerTypes.LAYER_TEXT });
|
|
});
|
|
}); |