checkbox.test.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isMP = platformInfo.startsWith('mp')
  3. describe('Checkbox.uvue', () => {
  4. let page
  5. beforeAll(async () => {
  6. page = await program.reLaunch('/pages/component/checkbox/checkbox')
  7. await page.waitFor('view')
  8. await page.waitFor(1000)
  9. })
  10. it('change', async () => {
  11. expect(await page.data('value')).toEqual([])
  12. const cb1 = await page.$('.cb1')
  13. await cb1.tap()
  14. await page.waitFor(100)
  15. expect(await page.data('value')).toEqual(['cb', 'cb1'])
  16. const cb = await page.$('.cb')
  17. await cb.tap()
  18. await page.waitFor(100)
  19. expect(await page.data('value')).toEqual(['cb1'])
  20. const cb2 = await page.$('.cb2')
  21. await cb2.tap()
  22. await page.waitFor(100)
  23. expect(await page.data('value')).toEqual(['cb1'])
  24. await cb1.tap()
  25. await page.waitFor(100)
  26. expect(await page.data('value')).toEqual([])
  27. })
  28. it('length', async () => {
  29. const checkboxGroupElements = await page.$$('.checkbox-group')
  30. expect(checkboxGroupElements.length).toBe(4)
  31. const checkboxElements = await page.$$('.checkbox')
  32. expect(checkboxElements.length).toBe(12)
  33. })
  34. it('text', async () => {
  35. const cb = await page.$('.cb1')
  36. expect(await cb.text()).toEqual('未选中')
  37. await page.setData({
  38. text: 'not selected',
  39. })
  40. expect(await cb.text()).toEqual('not selected')
  41. })
  42. if(isMP) {
  43. it('disabled', async () => {
  44. const cb = await page.$('.cb2')
  45. const disabled1 = await cb.property('disabled')
  46. expect(disabled1).toBe(true)
  47. await page.setData({
  48. disabled: false,
  49. })
  50. const disabled2 = await cb.property('disabled')
  51. expect(disabled2).toBe(false)
  52. })
  53. } else {
  54. it('disabled', async () => {
  55. const cb = await page.$('.cb2')
  56. const disabled1 = await cb.attribute('disabled')
  57. expect(disabled1).toBe(true + '')
  58. await page.setData({
  59. disabled: false,
  60. })
  61. const disabled2 = await cb.attribute('disabled')
  62. expect(disabled2).toBe(false + '')
  63. })
  64. }
  65. if(!isMP) {
  66. // 自动化测试获取的property checked在app、web和微信小程序之间有差异。微信小程序获取的和显示效果一致,app、web获取的是绑定值
  67. it('checked', async () => {
  68. const cb = await page.$('.cb')
  69. // TODO
  70. const newValue1 = await cb.property('checked')
  71. expect(newValue1.toString()).toBe(true + '')
  72. await page.setData({
  73. checked: false,
  74. })
  75. // TODO
  76. const newValue2 = await cb.property('checked')
  77. expect(newValue2.toString()).toBe(false + '')
  78. })
  79. }
  80. if(!isMP) {
  81. it('color', async () => {
  82. const cb = await page.$('.cb')
  83. expect(await cb.attribute('color')).toBe('#007aff')
  84. await page.setData({
  85. color: '#63acfc',
  86. })
  87. expect(await cb.attribute('color')).toBe('#63acfc')
  88. })
  89. it('icon color', async () => {
  90. const cb = await page.$('.cb')
  91. expect(await cb.attribute('iconColor')).toBe('#211cfe')
  92. await page.setData({
  93. iconColor: '#63acfc',
  94. })
  95. expect(await cb.attribute('iconColor')).toBe('#63acfc')
  96. })
  97. it('foreColor', async () => {
  98. const cb = await page.$('.cb')
  99. expect(await cb.attribute('foreColor')).toBe('#ff0000')
  100. await page.setData({
  101. foreColor: '#63acfe',
  102. })
  103. expect(await cb.attribute('foreColor')).toBe('#63acfe')
  104. })
  105. it('trigger UniCheckboxGroupChangeEvent', async () => {
  106. const element = await page.$('.checkbox-item-0')
  107. await element.tap()
  108. // 设置等待2.5s,避免 toast 弹框影响后续截图测试
  109. await page.waitFor(2500)
  110. const { testEvent } = await page.data()
  111. expect(testEvent).toBe(true)
  112. })
  113. }
  114. })