2023-05-30 14:28:56 +00:00
|
|
|
import { PlaywrightTestArgs, PlaywrightWorkerArgs } from '@playwright/test'
|
2023-06-02 15:21:45 +00:00
|
|
|
import { Editor } from '@tldraw/tldraw'
|
2023-05-30 14:28:56 +00:00
|
|
|
|
|
|
|
export function sleep(ms: number) {
|
|
|
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
|
|
|
}
|
|
|
|
|
2023-06-02 15:21:45 +00:00
|
|
|
declare const editor: Editor
|
2023-05-30 14:28:56 +00:00
|
|
|
|
|
|
|
export async function setup({ page }: PlaywrightTestArgs & PlaywrightWorkerArgs) {
|
|
|
|
await setupPage(page)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setupWithShapes({ page }: PlaywrightTestArgs & PlaywrightWorkerArgs) {
|
|
|
|
await setupPage(page)
|
|
|
|
await setupPageWithShapes(page)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function cleanup({ page }: PlaywrightTestArgs) {
|
|
|
|
await cleanupPage(page)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setupPage(page: PlaywrightTestArgs['page']) {
|
[refactor] User-facing APIs (#1478)
This PR updates our user-facing APIs for the Tldraw and TldrawEditor
components, as well as the Editor (App). It mainly incorporates surface
changes from #1450 without any changes to validators or migrators,
incorporating feedback / discussion with @SomeHats and @ds300.
Here we:
- remove the TldrawEditorConfig
- bring back a loose version of shape definitions
- make a separation between "core" shapes and "default" shapes
- do not allow custom shapes, migrators or validators to overwrite core
shapes
- but _do_ allow new shapes
## `<Tldraw>` component
In this PR, the `Tldraw` component wraps both the `TldrawEditor`
component and our `TldrawUi` component. It accepts a union of props for
both components. Previously, this component also added local syncing via
a `useLocalSyncClient` hook call, however that has been pushed down to
the `TldrawEditor` component.
## `<TldrawEditor>` component
The `TldrawEditor` component now more neatly wraps up the different ways
that the editor can be configured.
## The store prop (`TldrawEditorProps.store`)
There are three main ways for the `TldrawEditor` component to be run:
1. with an externally defined store
2. with an externally defined syncing store (local or remote)
3. with an internally defined store
4. with an internally defined locally syncing store
The `store` prop allows for these configurations.
If the `store` prop is defined, it may be defined either as a `TLStore`
or as a `SyncedStore`. If the store is a `TLStore`, then the Editor will
assume that the store is ready to go; if it is defined as a SyncedStore,
then the component will display the loading / error screens as needed,
or the final editor once the store's status is "synced".
When the store is left undefined, then the `TldrawEditor` will create
its own internal store using the optional `instanceId`, `initialData`,
or `shapes` props to define the store / store schema.
If the `persistenceKey` prop is left undefined, then the store will not
be synced. If the `persistenceKey` is defined, then the store will be
synced locally. In the future, we may also here accept the API key /
roomId / etc for creating a remotely synced store.
The `SyncedStore` type has been expanded to also include types used for
remote syncing, e.g. with `ConnectionStatus`.
## Tools
By default, the App has two "baked-in" tools: the select tool and the
zoom tool. These cannot (for now) be replaced or removed. The default
tools are used by default, but may be replaced by other tools if
provided.
## Shapes
By default, the App has a set of "core" shapes:
- group
- embed
- bookmark
- image
- video
- text
That cannot by overwritten because they're created by the app at
different moments, such as when double clicking on the canvas or via a
copy and paste event. In follow up PRs, we'll split these out so that
users can replace parts of the code where these shapes are created.
### Change Type
- [x] `major` — Breaking Change
### Test Plan
- [x] Unit Tests
2023-06-01 15:47:34 +00:00
|
|
|
await page.goto('http://localhost:5420/end-to-end')
|
2023-05-30 14:28:56 +00:00
|
|
|
await page.waitForSelector('.tl-canvas')
|
2023-06-24 13:46:04 +00:00
|
|
|
await page.evaluate(() => {
|
2023-07-18 21:50:23 +00:00
|
|
|
editor.user.updateUserPreferences({ animationSpeed: 0 })
|
2023-06-24 13:46:04 +00:00
|
|
|
})
|
2023-10-28 21:58:32 +00:00
|
|
|
await page.mouse.move(50, 50)
|
2023-05-30 14:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function setupPageWithShapes(page: PlaywrightTestArgs['page']) {
|
2023-09-19 15:33:39 +00:00
|
|
|
// delete everything
|
|
|
|
await page.keyboard.press('Control+a')
|
|
|
|
await page.keyboard.press('Backspace')
|
|
|
|
|
|
|
|
// create shapes
|
2023-05-30 14:28:56 +00:00
|
|
|
await page.keyboard.press('r')
|
|
|
|
await page.mouse.click(200, 200)
|
|
|
|
await page.keyboard.press('r')
|
|
|
|
await page.mouse.click(200, 250)
|
|
|
|
await page.keyboard.press('r')
|
|
|
|
await page.mouse.click(250, 300)
|
2023-09-19 15:33:39 +00:00
|
|
|
|
|
|
|
// deselect everything
|
|
|
|
await page.evaluate(() => editor.selectNone())
|
2023-05-30 14:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function cleanupPage(page: PlaywrightTestArgs['page']) {
|
|
|
|
await page.keyboard.press('Control+a')
|
|
|
|
await page.keyboard.press('Delete')
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getAllShapeLabels(page: PlaywrightTestArgs['page']) {
|
|
|
|
return await page
|
|
|
|
.locator('.tl-shapes')
|
|
|
|
.first()
|
|
|
|
.evaluate((e) => {
|
|
|
|
const labels: { index: string; label: string }[] = []
|
|
|
|
for (const child of e.children) {
|
|
|
|
const index = (child as HTMLDivElement).style.zIndex
|
|
|
|
const label = child.querySelector('.tl-text-content') as HTMLDivElement
|
|
|
|
labels.push({ index, label: label.innerText })
|
|
|
|
}
|
|
|
|
labels.sort((a, b) => (a.index > b.index ? 1 : -1))
|
|
|
|
return labels.map((l) => l.label)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getAllShapeTypes(page: PlaywrightTestArgs['page']) {
|
|
|
|
return await page
|
|
|
|
.locator('.tl-shape')
|
|
|
|
.elementHandles()
|
|
|
|
.then((handles) => Promise.all(handles.map((h) => h.getAttribute('data-shape-type'))))
|
|
|
|
}
|