picker-view.test.js 2.4 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')
Y
yurj26 已提交
14 15 16
})

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

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

DCloud-WZF's avatar
DCloud-WZF 已提交
38 39 40 41 42 43 44 45 46 47
  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
雪洛 已提交
48
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
49
    await page.waitFor(500)
雪洛's avatar
雪洛 已提交
50
    expect(await el.attribute('indicatorStyle')).toBe('height: 100px;')
DCloud-WZF's avatar
DCloud-WZF 已提交
51 52 53 54 55 56
  })
  it('mask-top-style', async () => {
    const el = await page.$('.picker-view')
    await page.setData({
      maskTopStyle: 'background: #ffffff;',
    })
雪洛's avatar
雪洛 已提交
57
    expect(await el.attribute('mask-top-style')).toBe('background: #ffffff;')
DCloud-WZF's avatar
DCloud-WZF 已提交
58 59 60 61 62 63
  })
  it('mask-bottom-style', async () => {
    const el = await page.$('.picker-view')
    await page.setData({
      maskBottomStyle: 'background: #ffffff;',
    })
雪洛's avatar
雪洛 已提交
64
    expect(await el.attribute('mask-bottom-style')).toBe('background: #ffffff;')
65 66 67
  })

  it('reopen-picker-view-page', async () => {
雪洛's avatar
雪洛 已提交
68 69
    await program.switchTab('/')
    await page.waitFor(500)
70 71 72 73 74 75 76 77 78 79 80
    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())
DCloud-WZF's avatar
DCloud-WZF 已提交
81 82
  })
})