picker-view.test.js 3.0 KB
Newer Older
Y
yurj26 已提交
1
function getData(key = '') {
DCloud-WZF's avatar
DCloud-WZF 已提交
2 3 4 5
  return new Promise(async (resolve, reject) => {
    const data = await page.data()
    resolve(key ? data[key] : data)
  })
Y
yurj26 已提交
6
}
7 8

const PAGE_PATH = '/pages/component/picker-view/picker-view'
Y
yurj26 已提交
9 10 11

let page
beforeAll(async () => {
12
  page = await program.reLaunch(PAGE_PATH)
Y
yurj26 已提交
13
  await page.waitFor('view')
14 15 16 17 18
  await page.callMethod('setEventCallbackNum', 0)
})

afterEach(async () => {
  await page.callMethod('setEventCallbackNum', 0)
Y
yurj26 已提交
19 20 21
})

describe('PickerView.uvue', () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
22 23
  it('value', async () => {
    const el = await page.$('.picker-view')
Y
yurj26 已提交
24
    await page.callMethod('setValue')
25 26
    await page.waitFor(1000)
    const newValue1 = await el.property('value')
27 28
    // TODO
    expect(newValue1.toString()).toEqual('0,0,0')
Y
yurj26 已提交
29 30 31
    if (process.env.UNI_PLATFORM === 'app-android') {
      expect(await getData('result')).toEqual([0, 0, 0])
    }
Y
yurj26 已提交
32

Y
yurj26 已提交
33
    await page.callMethod('setValue1')
34 35
    await page.waitFor(1000)
    const newValue2 = await el.property('value')
36 37
    // TODO
    expect(newValue2.toString()).toEqual('10,10,10')
Y
yurj26 已提交
38 39 40
    if (process.env.UNI_PLATFORM === 'app-android') {
      expect(await getData('result')).toEqual([10, 10, 10])
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
41
  })
Y
yurj26 已提交
42

DCloud-WZF's avatar
DCloud-WZF 已提交
43 44 45 46 47 48 49 50 51 52
  it('length', async () => {
    const els = await page.$$('.picker-view')
    expect(els.length).toBe(1)
    const els1 = await page.$$('.picker-view-column')
    expect(els1.length).toBe(3)
  })
  it('indicator-style', async () => {
    const el = await page.$('.picker-view')
    await page.setData({
      indicatorStyle: 'height: 100px;',
雪洛's avatar
雪洛 已提交
53
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
54
    await page.waitFor(500)
雪洛's avatar
雪洛 已提交
55
    expect(await el.attribute('indicatorStyle')).toBe('height: 100px;')
DCloud-WZF's avatar
DCloud-WZF 已提交
56 57 58 59 60 61
  })
  it('mask-top-style', async () => {
    const el = await page.$('.picker-view')
    await page.setData({
      maskTopStyle: 'background: #ffffff;',
    })
雪洛's avatar
雪洛 已提交
62
    expect(await el.attribute('mask-top-style')).toBe('background: #ffffff;')
DCloud-WZF's avatar
DCloud-WZF 已提交
63 64 65 66 67 68
  })
  it('mask-bottom-style', async () => {
    const el = await page.$('.picker-view')
    await page.setData({
      maskBottomStyle: 'background: #ffffff;',
    })
雪洛's avatar
雪洛 已提交
69
    expect(await el.attribute('mask-bottom-style')).toBe('background: #ffffff;')
DCloud-WZF's avatar
DCloud-WZF 已提交
70
  })
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99

  it('reopen-picker-view-page', async () => {
    page = await program.switchTab('/pages/tabBar/component')
    await page.waitFor(500)
    page = await program.navigateTo(PAGE_PATH)
    await page.waitFor(500)
    const date = new Date()
    const {
      year,
      month,
      day
    } = await page.data()
    expect(year).toEqual(date.getFullYear())
    expect(month).toEqual(date.getMonth() + 1)
    expect(day).toEqual(date.getDate())
  })

  it('trigger UniPickerViewChangeEvent', async () => {

    // if web skip todo
    if (
      process.env.uniTestPlatformInfo.startsWith('web')
    ) {
      expect(1).toBe(1)
      return
    }

    const el = await page.$('.picker-view')
    await page.callMethod('setValue')
100
    await page.waitFor(1500)
101 102 103 104 105
    const eventCallbackNum = await page.callMethod('getEventCallbackNum')
    // 3 times 3*3
    expect(eventCallbackNum).toBe(9)
  })
})