element-get-bounding-client-rect-async.test.js 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
const PAGE_PATH = '/pages/API/element-get-bounding-client-rect-async/element-get-bounding-client-rect-async'

const RECT_X = 15;
const RECT_HEIGHT = 100;
const RECT_LEFT = 15;

describe('element-get-bounding-client-rect-async', () => {
  const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(500)
  })
  it('getBoundingClientRectSync', async () => {
H
hdx 已提交
15
    await invokeGetBoundingClientRect(page, 'getBoundingClientRectAsync', 'rectInfo');
16 17 18
  })
})

H
hdx 已提交
19
async function invokeGetBoundingClientRect(page, methodName, dataName) {
20 21 22 23
  await page.callMethod(methodName);
  await page.waitFor(50)

  const data = await page.data()
H
hdx 已提交
24 25
  const systemInfo = await program.systemInfo();
  const width = systemInfo.screenWidth
26 27

  const rectInfo = data[dataName]
H
hdx 已提交
28 29 30 31

  console.log('width', width);
  console.log('rectInfo', rectInfo);

32 33
  expect(Math.round(rectInfo.x)).toBe(RECT_X)
  expect(Math.round(rectInfo.y) > 90).toBe(true)
34
  expect(width - 15 * 2 - Math.round(rectInfo.width) >= 0).toBe(true)
35 36 37
  expect(Math.round(rectInfo.height)).toBe(RECT_HEIGHT)
  expect(Math.round(rectInfo.left)).toBe(RECT_LEFT)
  expect(Math.round(rectInfo.top) > 90).toBe(true)
38
  expect(width - 15 - Math.round(rectInfo.right) >= 0).toBe(true)
39 40
  expect(Math.round(rectInfo.bottom) > 200).toBe(true)
}