* fix(app): keep a closing tab's canvas off the next document Tab components read the editor through useEditorStore, which resolves to whichever tab is active at each call. When a tab closed, the next tab became active before the closing canvas finished, so the canvas registered its renderers with that document and its cleanup removed them from the wrong one. Every closed document's renderers, WebGL canvases, and detached editor DOM stayed in the remaining tab: about 1,200 DOM nodes, 320 listeners, and 2.5 MB of heap per open and close in a production build. EditorWorkspace now provides its tab's store to app components as it already did for the SDK's useEditor, and useEditorStore returns it inside the tab. App-level menus, shortcuts, and services outside any tab keep following the active tab. Over eight open and close cycles, DOM nodes, listeners, and the remaining tab's renderers stay flat. * fix(app): bind the workspace itself to its tab's store Vue resolves an injection from the parent, so EditorWorkspace could not inject the store it provides and its own template kept following the active tab, reading the next document while its tab closed. It now takes its tab's store directly. * refactor(app): pass the workspace its tab as a prop EditorWorkspace read the active tab once during setup and relied on WorkspaceView keying it by tab to keep that choice. WorkspaceView now passes the tab, the workspace uses its store directly, and provides it to the components below, so the binding is explicit in the template. * test: keep the light-page setup from leaving documents unsaved CanvasHelper switches a fresh document to Figma's light page so canvas specs draw on it in the dark theme. Setting the page color counts as an edit, so every spec's document started unsaved, and closing a tab asked to save changes nobody made: both tab-close specs hit that dialog. The store now exposes markDocumentSaved, which reload and save already use, and the helper takes the light page as the saved state. * test: wait for a closing menu before opening the next one A menu stays in the page while it animates out, and a click on a menubar trigger then is lost, so menu specs failed depending on which tests ran before them. They now open menus through one helper that waits for the previous menu to go and for the named menu to appear. * test: configure storage through the current settings form Storage settings moved the connection fields behind the provider row and save them with one Save button, so the workspace spec timed out looking for an Endpoint field that was not shown.
128 lines
4.8 KiB
TypeScript
128 lines
4.8 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
|
|
import { expect, test } from '@playwright/test'
|
|
|
|
import { CanvasHelper } from '#tests/helpers/canvas'
|
|
|
|
test('configured storage lists previews through ranges before opening the document', async ({
|
|
page
|
|
}) => {
|
|
const fixture = readFileSync('tests/fixtures/gold-preview.fig')
|
|
let fullDocumentGets = 0
|
|
let rangeGets = 0
|
|
await page.route('https://s3.example.com/**', async (route) => {
|
|
const url = new URL(route.request().url())
|
|
if (url.searchParams.get('list-type') === '2') {
|
|
await route.fulfill({
|
|
contentType: 'application/xml',
|
|
body: `<ListBucketResult>
|
|
<IsTruncated>false</IsTruncated>
|
|
<Contents>
|
|
<Key>open_pencil_storage/canvases/remote-1.fig</Key>
|
|
<LastModified>2026-01-02T03:04:05.000Z</LastModified>
|
|
<Size>${fixture.byteLength}</Size>
|
|
</Contents>
|
|
</ListBucketResult>`
|
|
})
|
|
return
|
|
}
|
|
if (url.pathname.endsWith('/remote-1.meta.json')) {
|
|
await route.fulfill({
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ name: 'Remote design', updatedAt: '2026-01-02T03:04:05.000Z' })
|
|
})
|
|
return
|
|
}
|
|
if (url.pathname.endsWith('/remote-1.fig') && route.request().headers().range) {
|
|
const range = route.request().headers().range
|
|
const explicit = range?.match(/^bytes=(\d+)-(\d+)$/)
|
|
const suffix = range?.match(/^bytes=-(\d+)$/)
|
|
let start: number
|
|
let end: number
|
|
if (explicit) {
|
|
start = Number(explicit[1])
|
|
end = Math.min(Number(explicit[2]), fixture.byteLength - 1)
|
|
} else if (suffix) {
|
|
const length = Math.min(Number(suffix[1]), fixture.byteLength)
|
|
start = fixture.byteLength - length
|
|
end = fixture.byteLength - 1
|
|
} else {
|
|
await route.fulfill({ status: 416 })
|
|
return
|
|
}
|
|
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end < start) {
|
|
await route.fulfill({ status: 416 })
|
|
return
|
|
}
|
|
await route.fulfill({
|
|
status: 206,
|
|
headers: {
|
|
'Content-Range': `bytes ${start}-${end}/${fixture.byteLength}`
|
|
},
|
|
contentType: 'application/octet-stream',
|
|
body: fixture.subarray(start, end + 1)
|
|
})
|
|
rangeGets++
|
|
return
|
|
}
|
|
if (url.pathname.endsWith('/remote-1.fig') && route.request().method() === 'HEAD') {
|
|
await route.fulfill({
|
|
status: 200,
|
|
headers: { 'Content-Length': String(fixture.byteLength) }
|
|
})
|
|
return
|
|
}
|
|
if (url.pathname.endsWith('/remote-1.fig')) {
|
|
fullDocumentGets++
|
|
await route.fulfill({ contentType: 'application/octet-stream', body: fixture })
|
|
return
|
|
}
|
|
await route.fulfill({ status: 404 })
|
|
})
|
|
|
|
await page.goto('/storage?test')
|
|
const canvas = new CanvasHelper(page)
|
|
await canvas.waitForInit()
|
|
await page.keyboard.press('ControlOrMeta+KeyN')
|
|
await page.getByRole('button', { name: 'Settings' }).last().click()
|
|
await page.getByTestId('settings-section-storage').click()
|
|
const panel = page.getByTestId('settings-storage-panel')
|
|
await panel.getByRole('button', { name: /S3 storage/ }).click()
|
|
await panel.getByLabel('Endpoint').fill('https://s3.example.com')
|
|
await panel.getByLabel('Bucket').fill('designs')
|
|
await panel.getByLabel('Access key ID').fill('access-key')
|
|
await panel.getByLabel('Secret access key').fill('secret-key')
|
|
await page.getByRole('button', { name: 'Save', exact: true }).click()
|
|
|
|
await page.getByTestId('settings-storage-open-workspace').click()
|
|
await expect(page.getByTestId('recent-files-home')).toBeVisible()
|
|
await page.getByRole('button', { name: 'Refresh', exact: true }).click()
|
|
const entry = page.getByRole('button', { name: /Remote design/ })
|
|
await expect(entry).toBeVisible()
|
|
const preview = entry.locator('img')
|
|
await expect(preview).toBeVisible()
|
|
await expect(preview).toHaveAttribute('src', /^blob:/)
|
|
expect(rangeGets).toBe(3)
|
|
expect(fullDocumentGets).toBe(0)
|
|
|
|
await entry.click()
|
|
await expect(page).toHaveURL(/\/$/)
|
|
await canvas.waitForInit()
|
|
await expect(page.getByText('Remote design').first()).toBeVisible()
|
|
expect(fullDocumentGets).toBe(1)
|
|
})
|
|
|
|
test('storage workspace directs unconfigured users to Settings', async ({ page }) => {
|
|
await page.goto('/storage?test')
|
|
await new CanvasHelper(page).waitForInit()
|
|
await page.keyboard.press('ControlOrMeta+KeyN')
|
|
|
|
await expect(page.getByTestId('recent-files-home')).toBeVisible()
|
|
await expect(page.getByText('Configure storage before using this workspace.')).toBeVisible()
|
|
await expect(page.getByRole('button', { name: 'New design', exact: true })).toBeEnabled()
|
|
|
|
await page.getByRole('button', { name: 'Settings' }).last().click()
|
|
await page.getByTestId('settings-section-storage').click()
|
|
await expect(page.getByTestId('settings-storage-panel')).toBeVisible()
|
|
})
|