element-get-bounding-client-rect-async.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const PAGE_PATH = '/pages/API/element-get-bounding-client-rect-async/element-get-bounding-client-rect-async'
  2. const RECT_X = 15;
  3. const RECT_HEIGHT = 100;
  4. const RECT_LEFT = 15;
  5. describe('element-get-bounding-client-rect-async', () => {
  6. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  7. let page
  8. beforeAll(async () => {
  9. page = await program.reLaunch(PAGE_PATH)
  10. await page.waitFor(500)
  11. })
  12. it('getBoundingClientRectSync', async () => {
  13. await invokeGetBoundingClientRect(page, 'getBoundingClientRectAsync', 'rectInfo');
  14. })
  15. })
  16. async function invokeGetBoundingClientRect(page, methodName, dataName) {
  17. await page.callMethod(methodName);
  18. await page.waitFor(50)
  19. const data = await page.data()
  20. const systemInfo = await program.systemInfo();
  21. const width = systemInfo.screenWidth
  22. const rectInfo = data[dataName]
  23. console.log('width', width);
  24. console.log('rectInfo', rectInfo);
  25. expect(Math.round(rectInfo.x)).toBe(RECT_X)
  26. expect(Math.round(rectInfo.y) > 90).toBe(true)
  27. expect(width - 15 * 2 - Math.round(rectInfo.width) >= 0).toBe(true)
  28. expect(Math.round(rectInfo.height)).toBe(RECT_HEIGHT)
  29. expect(Math.round(rectInfo.left)).toBe(RECT_LEFT)
  30. expect(Math.round(rectInfo.top) > 90).toBe(true)
  31. expect(width - 15 - Math.round(rectInfo.right) >= 0).toBe(true)
  32. expect(Math.round(rectInfo.bottom) > 200).toBe(true)
  33. }