From 31e0634d3ca3c7391e1e32704ad3dd055f6f7c36 Mon Sep 17 00:00:00 2001 From: Danila Poyarkov Date: Sat, 4 Jul 2026 12:42:06 +0300 Subject: [PATCH] test(fig): cover cross-page clone roundtrip --- .../io/fig/export/guid-collision.test.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/engine/io/fig/export/guid-collision.test.ts b/tests/engine/io/fig/export/guid-collision.test.ts index 5c5a1c931..834b1648d 100644 --- a/tests/engine/io/fig/export/guid-collision.test.ts +++ b/tests/engine/io/fig/export/guid-collision.test.ts @@ -75,6 +75,43 @@ describe('export: GUID collision prevention', () => { expect(rects.length).toBe(2) }) + test('cross-page cloned frames survive export roundtrip', async () => { + const graph = new SceneGraph() + const page1 = graph.getPages()[0] + page1.name = 'Page 1' + const frame = graph.createNode('FRAME', page1.id, { + name: 'A', + width: 200, + height: 100 + }) + graph.createNode('TEXT', frame.id, { + name: 'Label', + text: 'Hello', + width: 100, + height: 20 + }) + + const clone = graph.cloneTree(frame.id, page1.id) + expect(clone).not.toBeNull() + if (!clone) throw new Error('Expected clone to exist') + const page2 = graph.addPage('Page 2') + graph.reparentNode(clone.id, page2.id) + + const figBytes = await exportFigFile(graph) + const reimported = await parseFigFile(figBytes.buffer as ArrayBuffer) + const pages = reimported.getPages() + + expect(pages.map((page) => page.name)).toEqual(['Page 1', 'Page 2']) + for (const page of pages) { + const [child] = reimported.getChildren(page.id) + expect(child?.name).toBe('A') + expect(child?.type).toBe('FRAME') + expect(child ? reimported.getChildren(child.id).map((node) => node.name) : []).toEqual([ + 'Label' + ]) + } + }) + test('export roundtrip preserves three nodes with identical source.id', async () => { const graph = new SceneGraph() const page = graph.getPages()[0]