Skip to content

AI-native design editor. Open-source Figma alternative.

test(native): open a document before editor fixtures

Danila Poyarkovf4f37360348d
diff --git a/tests/e2e/native/layer-drag.spec.ts b/tests/e2e/native/layer-drag.spec.ts
index 78b70aa74..eb23e1c3e 100644
--- a/tests/e2e/native/layer-drag.spec.ts
+++ b/tests/e2e/native/layer-drag.spec.ts
@@ -10,10 +10,6 @@ import { nativeDrag, readElementClientGeometry } from '#tests/helpers/tauri/wind
describe('native layer dragging', () => {
it('delivers a WebView drag sequence and reorders once', async function () {
if (process.platform !== 'win32') this.skip()
- await browser.waitUntil(
- async () => browser.execute(() => Boolean(window.openPencil?.getStore?.())),
- { timeout: 30_000, timeoutMsg: 'OpenPencil editor did not initialize' }
- )
const ids = await createNativeLayerFixture()
const source = await $(`[data-node-id="${ids.third}"] [data-test-id="layers-item"]`)
const target = await $(`[data-node-id="${ids.first}"] [data-test-id="layers-item"]`)
diff --git a/tests/e2e/native/text-editing.spec.ts b/tests/e2e/native/text-editing.spec.ts
index 09f47b3d1..2ee9965e6 100644
--- a/tests/e2e/native/text-editing.spec.ts
+++ b/tests/e2e/native/text-editing.spec.ts
@@ -8,10 +8,6 @@ import { withNativeEventRecorder } from '#tests/helpers/tauri/event-recorder'
describe('native text editing', () => {
it('commits ordinary WebView input exactly once', async () => {
- await browser.waitUntil(
- async () => browser.execute(() => Boolean(window.openPencil?.getStore?.())),
- { timeout: 30_000, timeoutMsg: 'OpenPencil editor did not initialize' }
- )
await createNativeTextFixture('Replace me')
const textarea = await $('textarea[aria-hidden="true"]')
await textarea.waitForExist()
@@ -42,4 +38,18 @@ describe('native text editing', () => {
)
})
})
+
+ it('reuses the open document when preparing another text fixture', async () => {
+ const tabCount = await browser.execute(() => document.querySelectorAll('[role="tab"]').length)
+ const id = await createNativeTextFixture('Another fixture')
+ const snapshot = await readNativeEditorSnapshot()
+
+ assert.equal(snapshot.editingTextId, id)
+ assert.equal(snapshot.editingText, 'Another fixture')
+ assert.equal(snapshot.textNodeCount, 1)
+ assert.equal(
+ await browser.execute(() => document.querySelectorAll('[role="tab"]').length),
+ tabCount
+ )
+ })
})
diff --git a/tests/helpers/tauri/editor-snapshot.ts b/tests/helpers/tauri/editor-snapshot.ts
index 1e4ca0744..010b1a7b4 100644
--- a/tests/helpers/tauri/editor-snapshot.ts
+++ b/tests/helpers/tauri/editor-snapshot.ts
@@ -4,7 +4,33 @@ export type NativeLayerFixture = {
third: string
}
+// Home has an editor store too, but no mounted canvas or text-input session.
+async function ensureNativeEditorReady(): Promise<void> {
+ await browser.waitUntil(
+ async () => browser.execute(() => Boolean(window.openPencil?.getStore?.())),
+ { timeout: 30_000, timeoutMsg: 'OpenPencil store did not initialize' }
+ )
+ await browser.execute(() => {
+ const store = window.openPencil?.getStore?.()
+ if (document.querySelector('canvas') && store?.textEditor) return
+ const newDesign = [...document.querySelectorAll('button')].find(
+ (button) => button.textContent?.trim() === 'New design'
+ )
+ // Setup only: input assertions still use WebDriver after the document is ready.
+ newDesign?.click()
+ })
+ await browser.waitUntil(
+ async () =>
+ browser.execute(() => {
+ const store = window.openPencil?.getStore?.()
+ return Boolean(document.querySelector('canvas') && store?.textEditor)
+ }),
+ { timeout: 30_000, timeoutMsg: 'Native canvas and text editor did not initialize' }
+ )
+}
+
export async function createNativeLayerFixture(): Promise<NativeLayerFixture> {
+ await ensureNativeEditorReady()
return browser.execute(() => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil editor is not ready')
@@ -59,6 +85,7 @@ export async function readNativeEditorSnapshot(): Promise<NativeEditorSnapshot>
}
export async function createNativeTextFixture(text = ''): Promise<string> {
+ await ensureNativeEditorReady()
return browser.execute((initialText) => {
const store = window.openPencil?.getStore?.()
if (!store) throw new Error('OpenPencil editor is not ready')