progress.test.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isMP = platformInfo.startsWith('mp')
  3. const isWeb = platformInfo.startsWith('web')
  4. function getData(key = '') {
  5. return new Promise(async (resolve, reject) => {
  6. const data = await page.data()
  7. resolve(key ? data[key] : data)
  8. })
  9. }
  10. describe('Progress.uvue', () => {
  11. let page
  12. beforeAll(async () => {
  13. page = await program.reLaunch('/pages/component/progress/progress')
  14. await page.waitFor(2000);
  15. })
  16. beforeEach(async () => {
  17. await page.callMethod('setEventCallbackNum', 0)
  18. })
  19. it('percent', async () => {
  20. await page.callMethod('setProgress')
  21. await page.waitFor(1000);
  22. const p = await page.$('.p')
  23. expect(await p.attribute('percent')).toEqual(20 + '')
  24. const p1 = await page.$('.p1')
  25. expect(await p1.attribute('percent')).toEqual(40 + '')
  26. const p2 = await page.$('.p2')
  27. expect(await p2.attribute('percent')).toEqual(60 + '')
  28. const p3 = await page.$('.p3')
  29. expect(await p3.attribute('percent')).toEqual(80 + '')
  30. if (process.env.UNI_PLATFORM === 'app-android') {
  31. expect(await getData('curPercent')).toEqual(20)
  32. }
  33. await page.callMethod('clearProgress')
  34. await page.waitFor(1000)
  35. expect(await p.attribute('percent')).toEqual(0 + '')
  36. expect(await p1.attribute('percent')).toEqual(0 + '')
  37. expect(await p2.attribute('percent')).toEqual(0 + '')
  38. expect(await p3.attribute('percent')).toEqual(0 + '')
  39. if (process.env.UNI_PLATFORM === 'app-android') {
  40. expect(await getData('curPercent')).toEqual(0)
  41. }
  42. })
  43. it('length', async () => {
  44. const elements = await page.$$('.progress')
  45. expect(elements.length).toBe(4)
  46. })
  47. if(isMP) {
  48. it('show-info', async () => {
  49. const el = await page.$('.p')
  50. expect(await el.property('showInfo')).toEqual(true)
  51. await page.setData({
  52. showInfo: false
  53. })
  54. expect(await el.property('showInfo')).toEqual(false)
  55. })
  56. } else {
  57. it('show-info', async () => {
  58. const el = await page.$('.p')
  59. expect(await el.attribute('show-info')).toEqual(true + '')
  60. await page.setData({
  61. showInfo: false
  62. })
  63. expect(await el.attribute('show-info')).toEqual(false + '')
  64. })
  65. }
  66. it('border-radius', async () => {
  67. const el = await page.$('.p')
  68. expect(await el.attribute('border-radius')).toEqual(0 + '')
  69. await page.setData({
  70. borderRadius: 5
  71. })
  72. expect(await el.attribute('border-radius')).toEqual(5 + '')
  73. })
  74. it('font-size', async () => {
  75. const el = await page.$('.p')
  76. expect(await el.attribute('font-size')).toEqual(16 + '')
  77. await page.setData({
  78. fontSize: 18
  79. })
  80. expect(await el.attribute('font-size')).toEqual(18 + '')
  81. })
  82. it('stroke-width', async () => {
  83. const el = await page.$('.p')
  84. expect(await el.attribute('stroke-width')).toEqual(3 + '')
  85. await page.setData({
  86. strokeWidth: 6
  87. })
  88. expect(await el.attribute('stroke-width')).toEqual(6 + '')
  89. if(isWeb) {
  90. await page.setData({
  91. strokeWidth: '10px'
  92. })
  93. expect(await el.attribute('stroke-width')).toEqual('10px')
  94. await page.setData({
  95. strokeWidth: '30rpx'
  96. })
  97. expect(await el.attribute('stroke-width')).toEqual('30rpx')
  98. }
  99. })
  100. it('backgroundColor', async () => {
  101. const el = await page.$('.p')
  102. expect(await el.attribute('background-color')).toEqual('#EBEBEB')
  103. await page.setData({
  104. backgroundColor: "#007aff"
  105. })
  106. expect(await el.attribute('background-color')).toEqual('#007aff')
  107. })
  108. it('trigger UniProgressActiveendEvent', async () => {
  109. if (isWeb || isMP) {
  110. expect(1).toBe(1)
  111. return
  112. }
  113. await page.setData({
  114. pgList: [21, 40, 60, 80]
  115. })
  116. // 动画执行
  117. await page.waitFor(1000);
  118. const eventCallbackNum = await page.callMethod('getEventCallbackNum')
  119. expect(eventCallbackNum).toBe(3)
  120. })
  121. })