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

DCloud-WZF's avatar
DCloud-WZF 已提交
3 4
const RECT_LEFT = 15;
const RECT_WIDTH = 150;
5
const RECT_HEIGHT = 100;
6

7 8 9 10 11 12 13 14 15 16 17 18
describe('nodes-info', () => {
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(500)
  })
  it('get-node-info', async () => {
    const btnGetNodeInfo = await page.$('.btn-get-node-info')

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

DCloud-WZF's avatar
DCloud-WZF 已提交
19 20
    const data = await page.data()

21
    // TODO 和浏览器的计算存在差异
DCloud-WZF's avatar
DCloud-WZF 已提交
22 23 24
    const nodeInfo = data.nodeInfoList[0]
    expect(Math.round(nodeInfo.left)).toBe(RECT_LEFT)
    expect(Math.round(nodeInfo.width)).toBe(RECT_WIDTH)
25
    expect(Math.round(nodeInfo.height)).toBe(RECT_HEIGHT)
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
    // android 6 分辨率为 720*1280,需要调整期望数值
    if (!process.env.uniTestPlatformInfo.startsWith('android 6')) {
      const nodeInfo = data.nodeInfoList[0]
      expect(nodeInfo.left > 15).toBe(true)
      expect(nodeInfo.width == 150).toBe(true)
      expect(nodeInfo.height == 100).toBe(true)
    }
  })
  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()

DCloud-WZF's avatar
DCloud-WZF 已提交
42 43 44 45 46
    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)
47 48 49 50 51 52 53
    if (!process.env.uniTestPlatformInfo.startsWith('android 6')) {
      const nodeInfo1 = data.nodeInfoList[0]
      expect(nodeInfo1.left > 15).toBe(true)
      expect(nodeInfo1.top > 220).toBe(true)
      expect(nodeInfo1.width == 150).toBe(true)
      expect(nodeInfo1.height == 100).toBe(true)

DCloud-WZF's avatar
DCloud-WZF 已提交
54 55 56 57
    const nodeInfo2 = data.nodeInfoList[1]
    expect(nodeInfo2.left > 200).toBe(true)
    expect(nodeInfo2.top > 220).toBe(true)
    expect(Math.round(nodeInfo2.width)).toBe(RECT_WIDTH)
58
    expect(Math.round(nodeInfo2.height)).toBe(RECT_HEIGHT)
59 60 61 62 63 64 65
      const nodeInfo2 = data.nodeInfoList[1]
      expect(nodeInfo2.left > 200).toBe(true)
      expect(nodeInfo2.top > 220).toBe(true)
      expect(nodeInfo2.width == 150).toBe(true)
      expect(nodeInfo2.height == 100).toBe(true)
    }
  })
DCloud-WZF's avatar
DCloud-WZF 已提交
66
})