All files / src/tests minimap.spec.ts

0% Statements 0/55
0% Branches 0/9
0% Functions 0/8
0% Lines 0/50

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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91                                                                                                                                                                                     
import { expect, test } from '@playwright/test'
 
import { getGraphView, getPositions, isInside, isOutside, move, takeBeforeEach } from './helper'
 
test.describe('Minimap', () => {
  const { getContainer } = takeBeforeEach('', 500, 500)
 
  test('has minimap', async ({ page }) => {
    await expect(page.getByTestId('minimap')).toBeVisible()
    await expect(page.getByTestId('minimap')).toHaveCount(1)
  })
 
  test('has mini nodes', async ({ page }) => {
    await expect(page.getByTestId('minimap-node')).toHaveCount(3)
  })
 
  test('has mini viewport', async ({ page }) => {
    await expect(page.getByTestId('minimap-viewport')).toBeVisible()
    await expect(page.getByTestId('minimap-viewport')).toHaveCount(1)
  })
 
  test('translate node', async ({ page }) => {
    const { findNodes } = await getGraphView(getContainer())
 
    const [numberNode1] = await findNodes('Number')
 
    const before = await getPositions(page, '[data-testid="minimap-node"]')
 
    await move(page, numberNode1, -420, 100)
 
    const after = await getPositions(page, '[data-testid="minimap-node"]')
 
    expect(before.width * 1.5).toBeLessThan(after.width)
    expect(await page.screenshot()).toMatchSnapshot('minimap-translate-node.png')
  })
 
  test('translate area', async ({ page }) => {
    const container = getContainer()
    const area = await container.$('div')
    const viewportWidth = page.viewportSize()?.width
 
    Iif (!area) throw new Error('area not found')
    Iif (!viewportWidth) throw new Error('viewportWidth not found')
 
    const body = await page.$('body')
 
    Iif (!body) throw new Error('body not found')
 
    const nodesBefore = await getPositions(page, '[data-testid="minimap-node"]')
    const viewportBefore = await getPositions(page, '[data-testid="minimap-viewport"]')
 
    expect(isInside(nodesBefore, viewportBefore)).toBeTruthy()
 
    await move(page, body, viewportWidth / 2, 0, 'corner')
    await move(page, body, viewportWidth / 2, 0, 'corner')
 
    const nodesAfter = await getPositions(page, '[data-testid="minimap-node"]')
    const viewportAfter = await getPositions(page, '[data-testid="minimap-viewport"]')
 
    expect(isOutside(nodesAfter, viewportAfter)).toBeTruthy()
 
    expect(await page.screenshot()).toMatchSnapshot('minimap-translate-area.png')
  })
 
  test('translate mini viewport', async ({ page }) => {
    const shouldSkip = String(process.env.APP).startsWith('react16')
 
    test.skip(shouldSkip, 'React.js v16 has problems with minimap viewport translation')
 
    await page.waitForSelector('[data-testid="minimap-viewport"]')
 
    const viewport = await page.$('[data-testid="minimap-viewport"]')
 
    Iif (!viewport) throw new Error('viewport not found')
 
    await move(page, viewport, 25, 0)
 
    expect(await page.screenshot()).toMatchSnapshot('minimap-translate-viewport.png')
  })
 
  test('double click viewport', async ({ page }) => {
    const bbox = await page.getByTestId('minimap-viewport').boundingBox()
 
    Iif (!bbox) throw new Error('bbox')
 
    await page.mouse.dblclick(bbox.x + bbox.width * 0.75, bbox.y + bbox.height * 0.75)
 
    expect(await page.screenshot()).toMatchSnapshot('minimap-dblclick-viewport.png')
  })
})