enso/app/gui2/e2e/nodeClipboard.spec.ts
Kaz Wesley 6426478c97
Copy/paste improvements (#9734)
Copying nodes:
- Multiple nodes supported.
- Node comments and user-specified colors included.
- Google Sheets data can be pasted to produce a `Table` node, handled the same way as Excel data.

# Important Notes
- Fix E2E tests on OS X.
- Add E2E and unit tests for clipboard.
- Use the lexer to test text escaping; fix text escaping issues and inconsistencies.
2024-04-19 16:33:51 +00:00

71 lines
2.4 KiB
TypeScript

import test from 'playwright/test'
import * as actions from './actions'
import { expect } from './customExpect'
import { CONTROL_KEY } from './keyboard'
import * as locate from './locate'
test.beforeEach(async ({ page }) => {
await page.addInitScript(() => {
class MockClipboard {
private contents: ClipboardItem[] = []
async read(): Promise<ClipboardItem[]> {
return [...this.contents]
}
async write(contents: ClipboardItem[]) {
this.contents = [...contents]
}
}
Object.assign(window.navigator, {
mockClipboard: new MockClipboard(),
})
})
})
test('Copy node with comment', async ({ page }) => {
await actions.goToGraph(page)
// Check state before operation.
const originalNodes = await locate.graphNode(page).count()
await expect(page.locator('.GraphNodeComment')).toExist()
const originalNodeComments = await page.locator('.GraphNodeComment').count()
// Select a node.
const nodeToCopy = locate.graphNodeByBinding(page, 'final')
await nodeToCopy.click()
await expect(nodeToCopy).toBeSelected()
// Copy and paste it.
await page.keyboard.press(`${CONTROL_KEY}+C`)
await page.keyboard.press(`${CONTROL_KEY}+V`)
await expect(nodeToCopy).toBeSelected()
// Node and comment have been copied.
await expect(locate.graphNode(page)).toHaveCount(originalNodes + 1)
await expect(page.locator('.GraphNodeComment')).toHaveCount(originalNodeComments + 1)
})
test('Copy multiple nodes', async ({ page }) => {
await actions.goToGraph(page)
// Check state before operation.
const originalNodes = await locate.graphNode(page).count()
await expect(page.locator('.GraphNodeComment')).toExist()
const originalNodeComments = await page.locator('.GraphNodeComment').count()
// Select some nodes.
const node1 = locate.graphNodeByBinding(page, 'final')
await node1.click()
const node2 = locate.graphNodeByBinding(page, 'data')
await node2.click({ modifiers: ['Shift'] })
await expect(node1).toBeSelected()
await expect(node2).toBeSelected()
// Copy and paste.
await page.keyboard.press(`${CONTROL_KEY}+C`)
await page.keyboard.press(`${CONTROL_KEY}+V`)
await expect(node1).toBeSelected()
await expect(node2).toBeSelected()
// Nodes and comment have been copied.
await expect(locate.graphNode(page)).toHaveCount(originalNodes + 2)
await expect(page.locator('.GraphNodeComment')).toHaveCount(originalNodeComments + 1)
})