2023-05-30 14:28:56 +00:00
|
|
|
import test, { expect } from '@playwright/test'
|
2023-06-02 15:21:45 +00:00
|
|
|
import { Editor } from '@tldraw/tldraw'
|
2023-05-30 14:28:56 +00:00
|
|
|
import { setup } from '../shared-e2e'
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
|
2023-08-02 18:12:25 +00:00
|
|
|
expect(await page.evaluate(() => editor.currentPageShapes.length)).toBe(1)
|
2023-06-02 15:21:45 +00:00
|
|
|
expect(await page.evaluate(() => editor.selectedShapes.length)).toBe(1)
|
2023-05-30 14:28:56 +00:00
|
|
|
|
|
|
|
await page.keyboard.down('Control')
|
|
|
|
await page.keyboard.press('KeyC')
|
|
|
|
await sleep(100)
|
|
|
|
await page.keyboard.press('KeyV')
|
|
|
|
await page.keyboard.up('Control')
|
|
|
|
|
2023-08-02 18:12:25 +00:00
|
|
|
expect(await page.evaluate(() => editor.currentPageShapes.length)).toBe(2)
|
2023-06-02 15:21:45 +00:00
|
|
|
expect(await page.evaluate(() => editor.selectedShapes.length)).toBe(1)
|
2023-05-30 14:28:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2023-08-02 18:12:25 +00:00
|
|
|
expect(await page.evaluate(() => editor.currentPageShapes.length)).toBe(1)
|
2023-06-02 15:21:45 +00:00
|
|
|
expect(await page.evaluate(() => editor.selectedShapes.length)).toBe(1)
|
2023-05-30 14:28:56 +00:00
|
|
|
|
|
|
|
await page.getByTestId('main.menu').click()
|
|
|
|
await page.getByTestId('menu-item.edit').click()
|
|
|
|
await page.getByTestId('menu-item.copy').click()
|
|
|
|
await sleep(100)
|
|
|
|
await page.getByTestId('main.menu').click()
|
|
|
|
await page.getByTestId('menu-item.edit').click()
|
|
|
|
await page.getByTestId('menu-item.paste').click()
|
|
|
|
|
2023-08-02 18:12:25 +00:00
|
|
|
expect(await page.evaluate(() => editor.currentPageShapes.length)).toBe(2)
|
2023-06-02 15:21:45 +00:00
|
|
|
expect(await page.evaluate(() => editor.selectedShapes.length)).toBe(1)
|
2023-05-30 14:28:56 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
2023-08-02 18:12:25 +00:00
|
|
|
expect(await page.evaluate(() => editor.currentPageShapes.length)).toBe(1)
|
2023-06-02 15:21:45 +00:00
|
|
|
expect(await page.evaluate(() => editor.selectedShapes.length)).toBe(1)
|
2023-05-30 14:28:56 +00:00
|
|
|
|
|
|
|
await page.mouse.click(100, 100, { button: 'right' })
|
|
|
|
await page.getByTestId('menu-item.copy').click()
|
|
|
|
await sleep(100)
|
|
|
|
await page.mouse.move(200, 200)
|
|
|
|
await page.mouse.click(100, 100, { button: 'right' })
|
|
|
|
await page.getByTestId('menu-item.paste').click()
|
|
|
|
|
2023-08-02 18:12:25 +00:00
|
|
|
expect(await page.evaluate(() => editor.currentPageShapes.length)).toBe(2)
|
2023-06-02 15:21:45 +00:00
|
|
|
expect(await page.evaluate(() => editor.selectedShapes.length)).toBe(1)
|
2023-05-30 14:28:56 +00:00
|
|
|
})
|
|
|
|
})
|