All files / src/tests reroute.spec.ts

0% Statements 0/41
0% Branches 0/1
0% Functions 0/7
0% Lines 0/40

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74                                                                                                                                                   
import { ElementHandle, expect, test } from '@playwright/test'
 
import { clickCenter, getGraphView, move, takeBeforeEach } from './helper'
 
async function getConnectionPath(connection: ElementHandle<HTMLElement | SVGElement>) {
  const path = await connection.$('path')
 
  Iif (!path) throw new Error('cannot find path')
 
  return path
}
 
test.describe('Reroute', () => {
  const { getContainer } = takeBeforeEach('', 500, 500)
 
  test('has no pins', async ({ page }) => {
    await expect(page.getByTestId('pin')).toHaveCount(0)
  })
 
  test('add pin', async ({ page }) => {
    const { connections } = await getGraphView(getContainer())
    const path = await getConnectionPath((await connections())[0])
 
    await clickCenter(page, path)
 
    await expect(page.getByTestId('pin')).toHaveCount(1)
    expect(await page.screenshot()).toMatchSnapshot('added-pin.png')
  })
 
  test('add pin and translate node', async ({ page }) => {
    const { nodes, connections } = await getGraphView(getContainer())
 
    const path = await getConnectionPath((await connections())[0])
    const firstNode = (await nodes())[0]
 
    await clickCenter(page, path)
    await move(page, firstNode, -200, 65)
 
    expect(await page.screenshot()).toMatchSnapshot('added-pin-node-translate.png')
  })
 
  test('remove pin', async ({ page }) => {
    const { connections } = await getGraphView(getContainer())
    const path = await getConnectionPath((await connections())[0])
 
    await clickCenter(page, path)
 
    expect(await page.screenshot()).toMatchSnapshot('added-pin.png')
 
    await clickCenter(page, '[data-testid="pin"]', 'right')
 
    await expect(page.getByTestId('pin')).toHaveCount(0)
    expect(await page.screenshot()).toMatchSnapshot('removed-pin.png')
  })
 
  test('move pin', async ({ page }) => {
    test.skip(String(process.env.APP).startsWith('react16'), 'React.js v16 has problems with pin translation')
 
    const { connections } = await getGraphView(getContainer())
    const path = await getConnectionPath((await connections())[0])
 
    await clickCenter(page, path)
 
    expect(await page.screenshot()).toMatchSnapshot('added-pin.png')
 
    const pin = await page.$('[data-testid="pin"]')
 
    await move(page, pin!, 0, -100, 'center')
 
    await expect(page.getByTestId('pin')).toHaveCount(1)
    expect(await page.screenshot()).toMatchSnapshot('moved-pin.png')
  })
})