diff --git a/packages/core/test/specs/utils/sorter/sorterLayers.ts b/packages/core/test/specs/utils/sorter/sorterLayers.ts new file mode 100644 index 000000000..3d1005410 --- /dev/null +++ b/packages/core/test/specs/utils/sorter/sorterLayers.ts @@ -0,0 +1,74 @@ +import Component from '../../../../src/dom_components/model/Component'; +import Editor from '../../../../src/editor'; +import LayersComponentNode from '../../../../src/utils/sorter/LayersComponentNode'; +import { setupTestEditor } from '../../../common'; + +describe('Layers sorter', () => { + let editor: Editor; + let fixtures: HTMLElement; + + const setCanvasVisibility = (cmp: Component, visible: boolean) => { + const el = cmp.getEl(); + + Object.defineProperty(el, 'offsetWidth', { + configurable: true, + get: () => (visible ? 120 : 0), + }); + + Object.defineProperty(el, 'offsetHeight', { + configurable: true, + get: () => (visible ? 24 : 0), + }); + }; + + const getChildIds = (cmp: Component) => cmp.components().map((child) => child.getAttributes().id); + + beforeEach(() => { + ({ editor, fixtures } = setupTestEditor({ withCanvas: true })); + }); + + afterEach(() => { + jest.restoreAllMocks(); + editor.destroy(); + }); + + test('removes the wrong hidden sibling when sorting layers with hidden siblings in the same collection', () => { + editor.setComponents(` +
+