All files / src/tests scopes.spec.ts

0% Statements 0/45
100% Branches 0/0
0% Functions 0/8
0% Lines 0/45

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 { expect, test } from '@playwright/test'
 
import { boundingBox, getGraphView, isInside, move, pickNode, takeBeforeEach, toRect } from './helper'
 
test.describe('Scopes', () => {
  const { getContainer } = takeBeforeEach('?template=scopes', 500, 500)
 
  test('has nodes', async () => {
    const { findNodes } = await getGraphView(getContainer())
 
    expect(await findNodes('A')).toHaveLength(1)
    expect(await findNodes('B')).toHaveLength(2)
    expect(await findNodes('Parent')).toHaveLength(2)
  })
 
  test('snapshot', async ({ page }) => {
    expect(await page.screenshot()).toMatchSnapshot('scopes.png')
  })
 
  test('has correct sizes', async () => {
    const { findNodes } = await getGraphView(getContainer())
 
    const [A] = await findNodes('A')
    const [B1, B2] = await findNodes('B')
    const [outerParent, innerParent] = await findNodes('Parent')
 
    const aRect = toRect(await boundingBox(A))
    const b1Rect = toRect(await boundingBox(B1))
    const b2Rect = toRect(await boundingBox(B2))
    const outerParentRect = toRect(await boundingBox(outerParent))
    const innerParentRect = toRect(await boundingBox(innerParent))
 
    expect(isInside(aRect, outerParentRect)).toBe(true)
    expect(isInside(b1Rect, innerParentRect)).toBe(true)
    expect(isInside(b2Rect, outerParentRect)).toBe(true)
    expect(isInside(innerParentRect, outerParentRect)).toBe(true)
  })
 
  test('translate nested node', async ({ page }) => {
    const { findNodes } = await getGraphView(getContainer())
    const [node] = await findNodes('B')
 
    await pickNode(page, node)
    await move(page, node, -30, -100)
 
    expect(await page.screenshot()).toMatchSnapshot('scopes-nested-translated.png')
  })
 
  test('translate parent node', async ({ page }) => {
    const { findNodes } = await getGraphView(getContainer())
    const [outerParent] = await findNodes('Parent')
 
    await pickNode(page, outerParent)
    await move(page, outerParent, -30, -100)
 
    expect(await page.screenshot()).toMatchSnapshot('scopes-parent-translated.png')
  })
 
  test('change relation', async ({ page }) => {
    const { findNodes } = await getGraphView(getContainer())
    const [node] = await findNodes('B')
 
    await pickNode(page, node)
    await move(page, node, 0, -220, 'corner', {
      async down() {
        await page.mouse.down({ button: 'left' })
        await page.waitForTimeout(2000)
      }
    })
 
    expect(await page.screenshot()).toMatchSnapshot('scopes-changed-relation.png')
  })
})