tldraw/apps/examples/e2e/shared-e2e.ts
Steve Ruiz 41601ac61e
Stickies: release candidate (#3249)
This PR is the target for the stickies PRs that are moving forward. It
should collect changes.

- [x] New icon
- [x] Improved shadows
- [x] Shadow LOD
- [x] New colors / theme options
- [x] Shrink text size to avoid word breaks on the x axis
- [x] Hide indicator whilst typing (reverted)
- [x] Adjacent note positions
  - [x] buttons / clone handles
  - [x] position helpers for creating / translating (pits)
- [x] keyboard shortcuts: (Tab, Shift+tab (RTL aware), Cmd-Enter,
Shift+Cmd+enter)
  - [x] multiple shape translating 
- [x] Text editing
  - [x] Edit on type (feature flagged)
  - [x] click goes in correct place
- [x] Notes as parents (reverted)
- [x] Update colors
- [x] Update SVG appearance

### Change Type

- [x] `sdk` — Changes the tldraw SDK
- [x] `feature` — New feature

### Test Plan

Todo: fold in test plans for child PRs

### Unit tests:

- [ ] Shrink text size to avoid word breaks on the x axis
- [x] Adjacent notes
  - [x] buttons (clone handles)
  - [x] position helpers (pits)
- [x] keyboard shortcuts: (Tab, Shift+tab (RTL aware), Cmd-Enter,
Shift+Cmd+enter)
- [ ] Text editing
  - [ ] Edit on type
  - [ ] click goes in correct place

### Release Notes

- Improves sticky notes (see list)

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Mime Čuvalo <mimecuvalo@gmail.com>
Co-authored-by: alex <alex@dytry.ch>
Co-authored-by: Mitja Bezenšek <mitja.bezensek@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Lu[ke] Wilson <l2wilson94@gmail.com>
Co-authored-by: huppy-bot[bot] <128400622+huppy-bot[bot]@users.noreply.github.com>
2024-04-14 18:40:02 +00:00

75 lines
2.2 KiB
TypeScript

import { PlaywrightTestArgs, PlaywrightWorkerArgs } from '@playwright/test'
import { Editor } from 'tldraw'
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
declare const editor: Editor
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']) {
await page.goto('http://localhost:5420/end-to-end')
await page.waitForSelector('.tl-canvas')
await page.evaluate(() => {
editor.user.updateUserPreferences({ animationSpeed: 0 })
})
await page.mouse.move(50, 50)
}
export async function setupPageWithShapes(page: PlaywrightTestArgs['page']) {
// delete everything
await page.keyboard.press('Control+a')
await page.keyboard.press('Backspace')
// create shapes
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)
// deselect everything
await page.keyboard.press('Escape')
await page.keyboard.press('Escape')
}
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'))))
}