swiper.test.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. jest.setTimeout(30000);
  2. describe('test swiper', () => {
  3. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  4. const isMP = platformInfo.startsWith('mp')
  5. const isWeb = platformInfo.startsWith('web')
  6. const isHarmony = platformInfo.startsWith('harmony')
  7. let page;
  8. const detailResWithCurrentItemId = {
  9. current: 1,
  10. currentItemId: 'B',//web端多了currentItemId
  11. source: 'autoplay' ,
  12. }
  13. const detailRes = {
  14. current: 1,
  15. source: 'autoplay' ,
  16. }
  17. beforeAll(async () => {
  18. page = await program.reLaunch('/pages/component/swiper/swiper')
  19. await page.waitFor(600)
  20. })
  21. if(!isMP) {
  22. it('check autoplay loop', async () => {
  23. await page.setData({
  24. currentValChange: 0,
  25. autoplaySelect: true,
  26. })
  27. await page.waitFor(isHarmony ? 2700 : 2500)
  28. expect(await page.data('currentValChange')).toEqual(1)
  29. await page.waitFor(isHarmony ? 2700 : 2500)
  30. expect(await page.data('currentValChange')).toEqual(2)
  31. await page.waitFor(isHarmony ? 2700 : 2500)
  32. expect(await page.data('currentValChange')).toEqual(0)
  33. await page.setData({
  34. autoplaySelect: false
  35. })
  36. await page.waitFor(300)
  37. });
  38. }
  39. it('check current', async () => {
  40. if(isMP) {
  41. // 微信小程序表现较为怪异,interval显式的设置非0的情况下,会无视autoplay属性。interval默认值5000
  42. await page.setData({
  43. intervalSelect: 0,
  44. })
  45. }
  46. await page.setData({
  47. currentVal: 2,
  48. })
  49. await page.waitFor(600)
  50. expect(await page.data('currentValChange')).toEqual(2)
  51. await page.setData({
  52. currentVal: 0,
  53. })
  54. await page.waitFor(600)
  55. expect(await page.data('currentValChange')).toEqual(0)
  56. if(isMP) {
  57. await page.setData({
  58. intervalSelect: 2000,
  59. })
  60. }
  61. });
  62. it('check currentId', async () => {
  63. await page.setData({
  64. currentItemIdVal: 'C',
  65. })
  66. await page.waitFor(800)
  67. expect(await page.data('currentValChange')).toEqual(2)
  68. await page.setData({
  69. currentItemIdVal: 'A',
  70. })
  71. await page.waitFor(800)
  72. expect(await page.data('currentValChange')).toEqual(0)
  73. });
  74. it('Trigger Event', async () => {
  75. await page.setData({
  76. swiperChangeSelect: true,
  77. swiperTransitionSelect: true,
  78. swiperAnimationfinishSelect: true,
  79. autoplaySelect:true
  80. })
  81. await page.waitFor(2000)
  82. await page.waitFor(async()=>{
  83. return await page.data('currentValChange') == 1
  84. })
  85. await page.setData({
  86. autoplaySelect:false
  87. })
  88. });
  89. it('Event transition', async () => {
  90. await page.waitFor(100)
  91. const transitionDetailInfo = await page.data('transitionDetailTest')
  92. expect(transitionDetailInfo.dy).toBe(0)
  93. expect(transitionDetailInfo.dx).not.toBe(0)
  94. expect(await page.data('isTransitionTest')).toBe('transition:Success')
  95. });
  96. it('Event change', async () => {
  97. const changeDetailInfo = await page.data('changeDetailTest')
  98. if(isWeb || isMP || isHarmony){
  99. expect(changeDetailInfo).toEqual(detailResWithCurrentItemId)
  100. }else{
  101. expect(changeDetailInfo).toEqual(detailRes)
  102. }
  103. expect(await page.data('isChangeTest')).toBe('change:Success')
  104. });
  105. it('Event animationfinish', async () => {
  106. // 等待最后一个动画结束animationfinish
  107. await page.waitFor(2000)
  108. const animationfinishDetailInfo = await page.data('animationfinishDetailTest')
  109. if(isWeb || isMP || isHarmony){
  110. expect(animationfinishDetailInfo).toEqual(detailResWithCurrentItemId)
  111. }else{
  112. expect(animationfinishDetailInfo).toEqual(detailRes)
  113. }
  114. expect(await page.data('isAnimationfinishTest')).toBe('animationfinish:Success')
  115. });
  116. });