tldraw/apps/examples/e2e/tests/test-clipboard.spec.ts
Steve Ruiz e3cf05f408
Add playwright tests (#1484)
This PR replaces our webdriver end to end tests with playwright tests.

It:
- replaces our webdriver workflow with a new e2e workflow based on
playwright
- removes the webdriver project
- adds e2e tests to our examples app
- replaces all `data-wd` attributes with `data-testid`

### Coverage

Most of the tests from our previous e2e tests are reproduced here,
though there are some related to our gestures that will need to be done
in a different way—or not at all. I've also added a handful of new
tests, too.

### Where are they

The tests are now part of our examples app rather than being in its own
different app. This should help us test our different examples too. As
far as I can tell there are no downsides here in terms of the regular
developer experience, though they might complicate any CodeSandbox
projects that are hooked into the examples app.

### Change Type

- [x] `tests` — Changes to any testing-related code only (will not
publish a new version)
2023-05-30 15:28:56 +01:00

79 lines
2.7 KiB
TypeScript

import test, { expect } from '@playwright/test'
import { App } from '@tldraw/tldraw'
import { setup } from '../shared-e2e'
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
declare const app: App
/**
* 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(() => app.shapesArray.length)).toBe(1)
expect(await page.evaluate(() => app.selectedShapes.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(() => app.shapesArray.length)).toBe(2)
expect(await page.evaluate(() => app.selectedShapes.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(() => app.shapesArray.length)).toBe(1)
expect(await page.evaluate(() => app.selectedShapes.length)).toBe(1)
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()
expect(await page.evaluate(() => app.shapesArray.length)).toBe(2)
expect(await page.evaluate(() => app.selectedShapes.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(() => app.shapesArray.length)).toBe(1)
expect(await page.evaluate(() => app.selectedShapes.length)).toBe(1)
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()
expect(await page.evaluate(() => app.shapesArray.length)).toBe(2)
expect(await page.evaluate(() => app.selectedShapes.length)).toBe(1)
})
})