diff --git a/src/store/modules/document-module.ts b/src/store/modules/document-module.ts index 777a4ce..05fac00 100644 --- a/src/store/modules/document-module.ts +++ b/src/store/modules/document-module.ts @@ -151,6 +151,7 @@ const DocumentModule: Module = { layers.push( oldLayers.find( layer => layer.id === id )); }); document.layers = layers; + flushBlendedLayerCache( true ); }, removeLayer( state: DocumentState, index: number ): void { const layer = state.documents[ state.activeIndex ]?.layers[ index ]; @@ -158,6 +159,7 @@ const DocumentModule: Module = { return; } flushLayerRenderers( layer ); + flushBlendedLayerCache( true ); state.documents[ state.activeIndex ].layers.splice( index, 1 ); if ( state.activeLayerIndex === index ) { state.activeLayerIndex = Math.max( 0, index - 1 ); diff --git a/tests/unit/store/modules/document-module.spec.ts b/tests/unit/store/modules/document-module.spec.ts index 0a36a82..7f89a0e 100644 --- a/tests/unit/store/modules/document-module.spec.ts +++ b/tests/unit/store/modules/document-module.spec.ts @@ -1,4 +1,4 @@ -import { it, afterEach, beforeEach, describe, expect, vi, afterAll } from "vitest"; +import { it, afterEach, beforeEach, describe, expect, vi } from "vitest"; import { mockZCanvas, createMockCanvasElement } from "../../mocks"; import { type Layer } from "@/definitions/document"; import { LayerTypes } from "@/definitions/layer-types"; @@ -36,7 +36,7 @@ vi.mock( "@/utils/layer-util", async ( importOriginal ) => { }); describe( "Vuex document module", () => { - afterAll(() => { + afterEach(() => { vi.resetAllMocks(); }); @@ -389,8 +389,13 @@ describe( "Vuex document module", () => { }); describe( "when removing layers", () => { - it( "should be able to remove a layer by reference", () => { - const state = createDocumentState({ + let state: DocumentState; + let layer1: Layer; + let layer2: Layer; + let layer3: Layer; + + beforeEach(() => { + state = createDocumentState({ documents: [ DocumentFactory.create({ name: "foo", layers: [ @@ -402,15 +407,34 @@ describe( "Vuex document module", () => { activeIndex: 0, activeLayerIndex: 1, }); - const [ layer1, layer2, layer3 ] = state.documents[ 0 ].layers; + ([ layer1, layer2, layer3 ] = state.documents[ 0 ].layers ); + }); + + it( "should be able to remove a layer by reference", () => { + mutations.removeLayer( state, 1 ); + + expect( state.documents[ 0 ].layers ).toEqual([ layer1, layer3 ]); + }); + + it( "should set the active layer index to the first Layer", () => { + mutations.removeLayer( state, 1 ); + + expect( state.activeLayerIndex ).toEqual( 0 ); + }); + + it( "should flush the Layer renderers", () => { mockUpdateFn = vi.fn(); mutations.removeLayer( state, 1 ); - expect( state.documents[ 0 ].layers ).toEqual([ layer1, layer3 ]); - expect( state.activeLayerIndex ).toEqual( 0 ); expect( mockUpdateFn ).toHaveBeenNthCalledWith( 1, "flushLayerRenderers", layer2 ); }); + + it( "should flush the blended layer cache fully", () => { + mutations.removeLayer( state, 1 ); + + expect( mockFlushBlendedLayerCache ).toHaveBeenCalledWith( true ); + }); }); it( "should be able to replace all layers in a single operation", () => { @@ -479,6 +503,7 @@ describe( "Vuex document module", () => { expect( state.documents[ 0 ].layers ).toEqual([ orgLayers[ 1 ], orgLayers[ 2 ], orgLayers[ 0 ], orgLayers[ 3 ] ]); + expect( mockFlushBlendedLayerCache ).toHaveBeenCalledWith( true ); }); describe( "when setting the active layer content", () => {