radio.test.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isMP = platformInfo.startsWith('mp')
  3. describe('Radio.uvue', () => {
  4. let page
  5. beforeAll(async () => {
  6. page = await program.reLaunch('/pages/component/radio/radio')
  7. await page.waitFor(2000)
  8. })
  9. it('change', async () => {
  10. expect(await page.data('value')).toEqual('')
  11. const radio1 = await page.$('.r1')
  12. await radio1.tap()
  13. await page.waitFor(100)
  14. expect(await page.data('value')).toEqual('r1')
  15. const radio = await page.$('.r')
  16. await radio.tap()
  17. await page.waitFor(100)
  18. expect(await page.data('value')).toEqual('r')
  19. const radio2 = await page.$('.r2')
  20. await radio2.tap()
  21. await page.waitFor(100)
  22. expect(await page.data('value')).toEqual('r')
  23. })
  24. it('length', async () => {
  25. const radioGroupElements = await page.$$('.radio-group')
  26. expect(radioGroupElements.length).toBe(4)
  27. const radioElements = await page.$$('.radio')
  28. expect(radioElements.length).toBe(12)
  29. })
  30. it('text', async () => {
  31. const radio = await page.$('.r1')
  32. expect(await radio.text()).toEqual('未选中')
  33. await page.setData({
  34. text: 'not selected',
  35. })
  36. expect(await radio.text()).toEqual('not selected')
  37. })
  38. if(!isMP) {
  39. // TODO property('checked')应取到实际显示的值(微信小程序)还是绑定的值(web、app)
  40. it('checked', async () => {
  41. const radio = await page.$('.r')
  42. // TODO
  43. const newValue1 = await radio.property('checked')
  44. expect(newValue1.toString()).toBe(true + '')
  45. await page.setData({
  46. checked: false,
  47. })
  48. const newValue2 = await radio.property('checked')
  49. expect(newValue2.toString()).toBe(false + '')
  50. })
  51. }
  52. it('color', async () => {
  53. const radio = await page.$('.r')
  54. expect(await radio.attribute('color')).toBe('#007aff')
  55. await page.setData({
  56. color: '#63acfc',
  57. })
  58. expect(await radio.attribute('color')).toBe('#63acfc')
  59. })
  60. if(isMP) {
  61. it('disabled', async () => {
  62. const radio = await page.$('.r2')
  63. expect(await radio.property('disabled')).toBe(true)
  64. await page.setData({
  65. disabled: false,
  66. })
  67. expect(await radio.property('disabled')).toBe(false)
  68. })
  69. } else {
  70. it('disabled', async () => {
  71. const radio = await page.$('.r2')
  72. expect(await radio.attribute('disabled')).toBe(true + '')
  73. await page.setData({
  74. disabled: false,
  75. })
  76. expect(await radio.attribute('disabled')).toBe(false + '')
  77. })
  78. }
  79. if(!isMP) {
  80. it('trigger UniRadioGroupChangeEvent', async () => {
  81. const { current } = await page.data()
  82. const nextCurrent = current == 0 ? 1 : 0
  83. const elements = await page.$$('.recommand')
  84. await elements[nextCurrent].tap()
  85. await page.waitFor(500)
  86. const { eventTest } = await page.data()
  87. expect(eventTest).toEqual(true)
  88. })
  89. }
  90. })