nodes-info.test.js 2.0 KB
Newer Older
1 2 3 4
const PAGE_PATH = '/pages/API/nodes-info/nodes-info'

const RECT_LEFT = 15;
const RECT_WIDTH = 150;
5
const RECT_HEIGHT = 100;
6 7 8 9 10 11 12

describe('nodes-info', () => {
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(500)
  })
H
hdx 已提交
13 14 15 16 17 18 19 20
  it('get-root-node-info', async () => {
    const page = await program.currentPage()
    await page.callMethod('getRootNodeInfo')
    await page.waitFor(100)

    const data = await page.data()
    expect(data.rootNodeInfo != null).toBe(true)
  })
21 22 23 24 25 26
  it('get-node-info', async () => {
    const btnGetNodeInfo = await page.$('.btn-get-node-info')

    await btnGetNodeInfo.tap()
    await page.waitFor(50)

27 28
    const data = await page.data()

29
    // TODO 和浏览器的计算存在差异
30 31 32
    const nodeInfo = data.nodeInfoList[0]
    expect(Math.round(nodeInfo.left)).toBe(RECT_LEFT)
    expect(Math.round(nodeInfo.width)).toBe(RECT_WIDTH)
33
    expect(Math.round(nodeInfo.height)).toBe(RECT_HEIGHT)
34 35 36 37 38 39 40 41 42
  })
  it('get-all-node-info', async () => {
    const btnGetAllNodeInfo = await page.$('.btn-get-all-node-info')

    await btnGetAllNodeInfo.tap()
    await page.waitFor(50)

    const data = await page.data()

43 44 45 46 47 48 49 50 51 52
    const nodeInfo1 = data.nodeInfoList[0]
    expect(Math.round(nodeInfo1.left)).toBe(RECT_LEFT)
    expect(nodeInfo1.top > 220).toBe(true)
    expect(Math.round(nodeInfo1.width)).toBe(RECT_WIDTH)
    expect(Math.round(nodeInfo1.height)).toBe(RECT_HEIGHT)

    const nodeInfo2 = data.nodeInfoList[1]
    expect(nodeInfo2.left > 180).toBe(true)
    expect(nodeInfo2.top > 220).toBe(true)
    expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH)
53
    expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT)
54
  })
55 56 57

  // #ifdef APP
  //检测onResize获取BoundingClientRect信息是否有效
58
  /* it('check_resizeRectValid', async () => {
59 60
    const resizeRectValid = await page.data('resizeRectValid')
    expect(resizeRectValid).toBe(true)
61
  }) */
62 63
  // #endif

64
})