picker.test.js 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isHarmony = platformInfo.startsWith('harmony')
  3. const isWeb = platformInfo.startsWith('web')
  4. const PAGE_PATH = '/pages/component/picker/picker'
  5. describe('Picker.uvue', () => {
  6. if (!isHarmony && !isWeb) {
  7. it('not support', () => {
  8. expect(1).toBe(1)
  9. })
  10. return
  11. }
  12. beforeAll(async () => {
  13. page = await program.reLaunch(PAGE_PATH)
  14. await page.waitFor('view');
  15. });
  16. function getData(key = '') {
  17. return new Promise(async (resolve, reject) => {
  18. const data = await page.data()
  19. resolve(key ? data[key] : data)
  20. })
  21. }
  22. function getValue(className, propertyValue = 'value') {
  23. return new Promise(async (resolve, reject) => {
  24. const el = await page.$(className)
  25. const value = await el.property(propertyValue)
  26. resolve(value)
  27. })
  28. }
  29. it('picker disabled', async () => {
  30. expect(await getValue('.picker-disabled--test')).toBe(0)
  31. const pickerValueEl = await page.$('.picker-disabled--value')
  32. expect(await pickerValueEl.text()).toBe('中国')
  33. })
  34. it('picker selector', async () => {
  35. expect(await getValue('.picker-selector--test')).toBe(await getData('index'))
  36. await page.setData({ index: 1 })
  37. const pickerValueEl = await page.$('.picker-selector--value')
  38. expect(await pickerValueEl.text()).toBe('美国')
  39. await page.callMethod('setSelectorValue')
  40. await page.waitFor(1500)
  41. expect(await pickerValueEl.text()).toBe('巴西')
  42. })
  43. it('picker multiSelector', async () => {
  44. expect(await getValue('.picker-multi--test')).toEqual(await getData('multiIndex'))
  45. const pickerMultiValueEl = await page.$('.picker-multi--value')
  46. expect(await pickerMultiValueEl.text()).toStrictEqual('亚洲,中国,北京')
  47. await page.setData({ multiIndex: [0, 0, 2] })
  48. const pickerMultiValueEl2 = await page.$('.picker-multi--value')
  49. expect(await pickerMultiValueEl2.text()).toStrictEqual('亚洲,中国,广州')
  50. })
  51. it('picker time', async () => {
  52. expect(await getValue('.picker-time--test')).toBe(await getData('time'))
  53. await page.setData({ time: '15:30' })
  54. expect(await getValue('.picker-time--test')).toEqual('15:30')
  55. })
  56. it('picer date-day', async () => {
  57. expect(await getValue('.picker-date-day--test')).toBe(await getData('dayDate'))
  58. await page.setData({ dayDate: '2028-05-20' })
  59. expect(await getValue('.picker-date-day--test')).toEqual('2028-05-20')
  60. expect(await getValue('.picker-date-day--test', 'start')).toStrictEqual(await getData('startDate'))
  61. expect(await getValue('.picker-date-day--test', 'end')).toStrictEqual(await getData('endDate'))
  62. })
  63. it('picker date-month', async () => {
  64. expect(await getValue('.picker-date-month--test')).toBe(await getData('monthDate'))
  65. await page.setData({ monthDate: '2028-05' })
  66. expect(await getValue('.picker-date-month--test')).toEqual('2028-05')
  67. expect(await getValue('.picker-date-month--test', 'start')).toStrictEqual(await getData('startDate'))
  68. expect(await getValue('.picker-date-month--test', 'end')).toStrictEqual(await getData('endDate'))
  69. })
  70. it('picker date-year', async () => {
  71. expect(await getValue('.picker-date-year--test')).toBe(await getData('yearDate'))
  72. await page.setData({ yearDate: '2028' })
  73. expect(await getValue('.picker-date-year--test')).toEqual('2028')
  74. expect(await getValue('.picker-date-year--test', 'start')).toStrictEqual(await getData('startDate'))
  75. expect(await getValue('.picker-date-year--test', 'end')).toStrictEqual(await getData('endDate'))
  76. })
  77. })