2024-12-03 18:22:15 +03:00
|
|
|
import { test, type Locator, type Page } from '@playwright/test'
|
2024-02-08 15:17:56 +03:00
|
|
|
import * as actions from './actions'
|
2024-03-06 18:34:07 +03:00
|
|
|
import { expect } from './customExpect'
|
2024-12-03 18:22:15 +03:00
|
|
|
import { mockExpressionUpdate, mockMethodCallInfo } from './expressionUpdates'
|
2024-11-04 18:33:53 +03:00
|
|
|
import { CONTROL_KEY } from './keyboard'
|
2024-02-08 15:17:56 +03:00
|
|
|
import * as locate from './locate'
|
|
|
|
import { graphNodeByBinding } from './locate'
|
|
|
|
|
2024-10-21 15:56:39 +03:00
|
|
|
/** Prepare the graph for the tests. We add the table type to the `aggregated` node. */
|
2024-02-08 15:17:56 +03:00
|
|
|
async function initGraph(page: Page) {
|
|
|
|
await actions.goToGraph(page)
|
2024-11-26 12:22:41 +03:00
|
|
|
await mockExpressionUpdate(page, 'aggregated', { type: ['Standard.Table.Table.Table'] })
|
2024-02-08 15:17:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Scenario: We open the default visualisation of the `aggregated` node. We expect it to be a table visualisation and to
|
|
|
|
contain 10 rows and the values 0,0 to 3,0, which are just some sample values that should be visible in the table
|
|
|
|
after opening it.
|
|
|
|
*/
|
|
|
|
test('Load Table Visualisation', async ({ page }) => {
|
|
|
|
await initGraph(page)
|
|
|
|
|
|
|
|
const aggregatedNode = graphNodeByBinding(page, 'aggregated')
|
|
|
|
await aggregatedNode.click()
|
|
|
|
await page.keyboard.press('Space')
|
|
|
|
await page.waitForTimeout(1000)
|
|
|
|
const tableVisualization = locate.tableVisualization(page)
|
2024-03-06 18:34:07 +03:00
|
|
|
await expect(tableVisualization).toExist()
|
2024-02-08 15:17:56 +03:00
|
|
|
await expect(tableVisualization).toContainText('10 rows.')
|
|
|
|
await expect(tableVisualization).toContainText('0,0')
|
|
|
|
await expect(tableVisualization).toContainText('1,0')
|
|
|
|
await expect(tableVisualization).toContainText('2,0')
|
|
|
|
await expect(tableVisualization).toContainText('3,0')
|
|
|
|
})
|
2024-10-21 10:27:46 +03:00
|
|
|
|
2024-12-03 18:22:15 +03:00
|
|
|
test('Copy/paste from Table Visualization', async ({ page, context }) => {
|
2024-12-06 14:49:30 +03:00
|
|
|
const expectClipboard = expect.poll(() =>
|
|
|
|
page.evaluate(() => window.navigator.clipboard.readText()),
|
|
|
|
)
|
2024-10-21 10:27:46 +03:00
|
|
|
await context.grantPermissions(['clipboard-read', 'clipboard-write'])
|
|
|
|
await actions.goToGraph(page)
|
|
|
|
|
2024-11-04 18:33:53 +03:00
|
|
|
await actions.openVisualization(page, 'Table')
|
2024-10-21 10:27:46 +03:00
|
|
|
const tableVisualization = locate.tableVisualization(page)
|
|
|
|
await expect(tableVisualization).toExist()
|
|
|
|
await tableVisualization.getByText('0,0').hover()
|
|
|
|
await page.mouse.down()
|
|
|
|
await tableVisualization.getByText('2,1').hover()
|
|
|
|
await page.mouse.up()
|
2024-12-03 18:22:15 +03:00
|
|
|
|
|
|
|
// Copy from table visualization
|
2024-11-04 18:33:53 +03:00
|
|
|
await page.keyboard.press(`${CONTROL_KEY}+C`)
|
2024-12-06 14:49:30 +03:00
|
|
|
await expectClipboard.toMatch(/^0,0\t0,1\r\n1,0\t1,1\r\n2,0\t2,1$/)
|
2024-10-21 10:27:46 +03:00
|
|
|
|
|
|
|
// Paste to Node.
|
|
|
|
await actions.clickAtBackground(page)
|
|
|
|
const nodesCount = await locate.graphNode(page).count()
|
2024-11-04 18:33:53 +03:00
|
|
|
await page.keyboard.press(`${CONTROL_KEY}+V`)
|
2024-10-21 10:27:46 +03:00
|
|
|
await expect(locate.graphNode(page)).toHaveCount(nodesCount + 1)
|
2024-12-03 18:22:15 +03:00
|
|
|
// Node binding would be `node1` for pasted node.
|
|
|
|
const nodeBinding = 'node1'
|
|
|
|
await mockMethodCallInfo(page, nodeBinding, {
|
|
|
|
methodPointer: {
|
|
|
|
module: 'Standard.Table.Table',
|
|
|
|
definedOnType: 'Standard.Table.Table.Table',
|
|
|
|
name: 'input',
|
|
|
|
},
|
|
|
|
notAppliedArguments: [],
|
|
|
|
})
|
|
|
|
await expectTableInputContent(page, locate.graphNode(page).last())
|
2024-10-21 10:27:46 +03:00
|
|
|
|
|
|
|
// Paste to Table Widget.
|
|
|
|
const node = await actions.createTableNode(page)
|
|
|
|
const widget = node.locator('.WidgetTableEditor')
|
|
|
|
await expect(widget).toBeVisible()
|
2024-10-25 15:26:21 +03:00
|
|
|
await widget.getByRole('button', { name: 'Add new column' }).click()
|
2024-11-28 17:40:29 +03:00
|
|
|
await widget.locator('.valueCell').first().click()
|
2024-11-04 18:33:53 +03:00
|
|
|
await page.keyboard.press(`${CONTROL_KEY}+V`)
|
2024-12-03 18:22:15 +03:00
|
|
|
await expectTableInputContent(page, node)
|
|
|
|
|
|
|
|
// Copy from table input widget
|
|
|
|
await node.getByText('0,0').hover()
|
|
|
|
await page.mouse.down()
|
|
|
|
await node.getByText('2,1').hover()
|
|
|
|
await page.mouse.up()
|
|
|
|
await page.keyboard.press(`${CONTROL_KEY}+C`)
|
2024-12-06 14:49:30 +03:00
|
|
|
await expectClipboard.toMatch(/^0,0\t0,1\r\n1,0\t1,1\r\n2,0\t2,1$/)
|
2024-12-03 18:22:15 +03:00
|
|
|
|
|
|
|
// Copy from table input widget with headers
|
|
|
|
await node.getByText('0,0').hover()
|
|
|
|
await page.mouse.down()
|
|
|
|
await node.getByText('2,1').hover()
|
|
|
|
await page.mouse.up()
|
|
|
|
await page.mouse.down({ button: 'right' })
|
|
|
|
await page.mouse.up({ button: 'right' })
|
|
|
|
await page.getByText('Copy with Headers').click()
|
2024-12-06 14:49:30 +03:00
|
|
|
await expectClipboard.toMatch(/^Column #1\tColumn #2\r\n0,0\t0,1\r\n1,0\t1,1\r\n2,0\t2,1$/)
|
2024-12-03 18:22:15 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
async function expectTableInputContent(page: Page, node: Locator) {
|
|
|
|
const widget = node.locator('.WidgetTableEditor')
|
|
|
|
await expect(widget).toBeVisible({ timeout: 5000 })
|
2024-11-28 17:40:29 +03:00
|
|
|
await expect(widget.locator('.valueCell')).toHaveText([
|
2024-10-21 10:27:46 +03:00
|
|
|
'0,0',
|
|
|
|
'0,1',
|
|
|
|
'1,0',
|
|
|
|
'1,1',
|
|
|
|
'2,0',
|
|
|
|
'2,1',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
])
|
2024-12-03 18:22:15 +03:00
|
|
|
}
|