swiper2.test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const PAGE_PATH = '/pages/component/swiper/swiper'
  2. describe('swiper-touch-test', () => {
  3. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  4. const isWeb = platformInfo.startsWith('web')
  5. const isMP = platformInfo.startsWith('mp')
  6. const isHarmony = platformInfo.startsWith('harmony')
  7. const isAndroid = platformInfo.startsWith('android')
  8. let res;
  9. // 屏蔽 web & 小程序,不支持 program.swipe
  10. if (isWeb || isMP) {
  11. it('other platform', () => {
  12. expect(1).toBe(1)
  13. })
  14. return
  15. }
  16. let page
  17. beforeAll(async () => {
  18. page = await program.reLaunch(PAGE_PATH)
  19. await page.waitFor('view');
  20. res = await page.callMethod('jest_getSystemInfo')
  21. })
  22. it('滑动切换 swiper', async () => {
  23. let x = await page.data('swipeX')
  24. let y = await page.data('swipeY')
  25. // harmony onReady getBoundingClientRect 获取节点宽度不稳定,偶发错误
  26. if (isHarmony && x < 20) {
  27. x = 300
  28. }
  29. // program.swipe Android10以上不生效
  30. if(isAndroid && res.osAndroidAPILevel > 28){
  31. // 避免 android 10 侧滑影响
  32. x -= 20
  33. }
  34. await program.swipe({
  35. startPoint: {x, y},
  36. endPoint: {x: 10, y},
  37. duration: 200
  38. })
  39. await page.waitFor(1000)
  40. let val = await page.data('currentValChange')
  41. expect(val).toEqual(1)
  42. })
  43. })