tldraw/apps/examples/e2e/tests/test-clipboard.spec.ts
alex a0628f9cb2
tldraw_final_v6_final(old version).docx.pdf (#2998)
Rename `@tldraw/tldraw` to just `tldraw`! `@tldraw/tldraw` still exists
as an alias to `tldraw` for folks who are still using that.

### Test Plan

- [x] Unit Tests
- [ ] End to end tests

### Release Notes

- The `@tldraw/tldraw` package has been renamed to `tldraw`. You can
keep using the old version if you want though!
2024-02-29 16:06:19 +00:00

79 lines
2.8 KiB
TypeScript

import test, { expect } from '@playwright/test'
import { Editor } from 'tldraw'
import { setup } from '../shared-e2e'
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
declare const editor: Editor
/**
* These tests are skipped. They are here to show how to use the clipboard
* in tests. The clipboard is not really supported in playwright, so until
* we figure out a way to do it (or until it is supported propertly), we've
* had to skip these tests.
*/
test.describe.skip('clipboard tests', () => {
test.beforeEach(setup)
test('copy and paste from keyboard shortcut', async ({ page }) => {
await page.keyboard.press('r')
await page.mouse.move(100, 100)
await page.mouse.down()
await page.mouse.up()
expect(await page.evaluate(() => editor.getCurrentPageShapes().length)).toBe(1)
expect(await page.evaluate(() => editor.getSelectedShapes().length)).toBe(1)
await page.keyboard.down('Control')
await page.keyboard.press('KeyC')
await sleep(100)
await page.keyboard.press('KeyV')
await page.keyboard.up('Control')
expect(await page.evaluate(() => editor.getCurrentPageShapes().length)).toBe(2)
expect(await page.evaluate(() => editor.getSelectedShapes().length)).toBe(1)
})
test('copy and paste from main menu', async ({ page }) => {
await page.keyboard.press('r')
await page.mouse.move(100, 100)
await page.mouse.down()
await page.mouse.up()
expect(await page.evaluate(() => editor.getCurrentPageShapes().length)).toBe(1)
expect(await page.evaluate(() => editor.getSelectedShapes().length)).toBe(1)
await page.getByTestId('main-menu.button').click()
await page.getByTestId('main-menu-sub-trigger.edit').click()
await page.getByTestId('main-menu.copy').click()
await sleep(100)
await page.getByTestId('main-menu.button').click()
await page.getByTestId('main-menu-sub-trigger.edit').click()
await page.getByTestId('main-menu.paste').click()
expect(await page.evaluate(() => editor.getCurrentPageShapes().length)).toBe(2)
expect(await page.evaluate(() => editor.getSelectedShapes().length)).toBe(1)
})
test('copy and paste from context menu', async ({ page }) => {
await page.keyboard.press('r')
await page.mouse.move(100, 100)
await page.mouse.down()
await page.mouse.up()
expect(await page.evaluate(() => editor.getCurrentPageShapes().length)).toBe(1)
expect(await page.evaluate(() => editor.getSelectedShapes().length)).toBe(1)
await page.mouse.click(100, 100, { button: 'right' })
await page.getByTestId('main-menu.copy').click()
await sleep(100)
await page.mouse.move(200, 200)
await page.mouse.click(100, 100, { button: 'right' })
await page.getByTestId('main-menu.paste').click()
expect(await page.evaluate(() => editor.getCurrentPageShapes().length)).toBe(2)
expect(await page.evaluate(() => editor.getSelectedShapes().length)).toBe(1)
})
})