switch.test.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isAndroid = platformInfo.startsWith('android')
  3. const isMP = platformInfo.startsWith('mp')
  4. const PAGE_PATH = '/pages/component/switch/switch'
  5. describe('switch', () => {
  6. let page
  7. beforeAll(async () => {
  8. page = await program.reLaunch(PAGE_PATH)
  9. await page.waitFor(500)
  10. })
  11. it('checked', async () => {
  12. const switch_element = await page.$('.switch-checked')
  13. await page.setData({
  14. checked: false,
  15. })
  16. await page.waitFor(100)
  17. // TODO
  18. const newValue1 = await switch_element.property('checked')
  19. expect(newValue1.toString()).toBe(false + '')
  20. await page.setData({
  21. checked: true,
  22. })
  23. await page.waitFor(100)
  24. // TODO
  25. const newValue2 = await switch_element.property('checked')
  26. expect(newValue2.toString()).toBe(true + '')
  27. })
  28. it('color', async () => {
  29. const switch_element = await page.$('.switch-color')
  30. expect(await switch_element.attribute('color')).toBe('#FFCC33')
  31. const color = '#00ff00'
  32. await page.setData({
  33. color: color
  34. })
  35. await page.waitFor(100)
  36. expect(await switch_element.attribute('color')).toBe(color)
  37. })
  38. if(!isMP) {
  39. it('dark', async () => {
  40. const dark = await page.$('#dark')
  41. const darkChecked = await page.$('#darkChecked')
  42. expect(await dark.attribute('background-color')).toBe('#1f1f1f')
  43. expect(await dark.attribute('fore-color')).toBe('#f0f0f0')
  44. expect(await darkChecked.attribute('active-background-color')).toBe('#007aff')
  45. expect(await darkChecked.attribute('active-fore-color')).toBe('#ffffff')
  46. })
  47. }
  48. it('click', async () => {
  49. let switchElement
  50. // TODO 暂时通过获取组件内部的 class 触发模拟点击
  51. if (isAndroid) {
  52. switchElement = await page.$('.uni-switch-input')
  53. await switchElement.tap()
  54. await page.waitFor(200)
  55. const {
  56. testVerifyEvent
  57. } = await page.data()
  58. expect(testVerifyEvent).toBe(true)
  59. } else {
  60. // switchElement = await page.$('#testTap')
  61. }
  62. // await switchElement.tap()
  63. // await page.waitFor(200)
  64. // const {
  65. // testVerifyEvent
  66. // } = await page.data()
  67. // expect(testVerifyEvent).toBe(true)
  68. })
  69. })