picker-view.test.js 4.6 KB
Newer Older
1 2

const PAGE_PATH = '/pages/component/picker-view/picker-view'
3
let page,pickerViewEl;
Y
yurj26 已提交
4
describe('PickerView.uvue', () => {
5 6 7 8 9 10
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor('view')
    await page.callMethod('setEventCallbackNum', 0)
    pickerViewEl = await page.$('.picker-view')
  })
11

12 13 14
  afterEach(async () => {
    await page.callMethod('setEventCallbackNum', 0)
  })
15

16
  async function toScreenshot(imgName) {
17
    const image = await program.screenshot({fullPage: true});
18 19 20 21 22
    expect(image).toSaveImageSnapshot({customSnapshotIdentifier() {
      return imgName
    }})
    await page.waitFor(500);
  }
23

DCloud-WZF's avatar
DCloud-WZF 已提交
24
  it('value', async () => {
Y
yurj26 已提交
25
    await page.callMethod('setValue')
26
    await page.waitFor(1000)
27
    const newValue1 = await pickerViewEl.property('value')
28 29
    // TODO
    expect(newValue1.toString()).toEqual('0,0,0')
Y
yurj26 已提交
30
    if (process.env.UNI_PLATFORM === 'app-android') {
31
      expect(await page.data('result')).toEqual([0, 0, 0])
Y
yurj26 已提交
32 33
    }
    await page.callMethod('setValue1')
34
    await page.waitFor(1000)
35
    const newValue2 = await pickerViewEl.property('value')
36 37
    // TODO
    expect(newValue2.toString()).toEqual('10,10,10')
Y
yurj26 已提交
38
    if (process.env.UNI_PLATFORM === 'app-android') {
39
      expect(await page.data('result')).toEqual([10, 10, 10])
Y
yurj26 已提交
40
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
41
  })
Y
yurj26 已提交
42

DCloud-WZF's avatar
DCloud-WZF 已提交
43 44 45 46 47 48
  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)
  })
49

DCloud-WZF's avatar
DCloud-WZF 已提交
50
  it('indicator-style', async () => {
51 52
    // App端动态设置indicatorStyle无效
    const indicatorStyle = "height: 50px;border:#ff5500 solid 1px;background:rgba(182, 179, 255, 0.4);"
DCloud-WZF's avatar
DCloud-WZF 已提交
53
    await page.setData({
54
      indicatorStyle
雪洛's avatar
雪洛 已提交
55
    })
DCloud-WZF's avatar
DCloud-WZF 已提交
56
    await page.waitFor(500)
57
    expect(await pickerViewEl.attribute('indicatorStyle')).toBe(indicatorStyle)
58
    await toScreenshot('picker-view-indicator-style')
DCloud-WZF's avatar
DCloud-WZF 已提交
59
  })
60

61 62 63 64 65 66 67 68
  if(process.env.uniTestPlatformInfo.startsWith('web')){
    // indicator-class、mask-style、mask-class 仅web支持
    it('indicator-class', async () => {
      await page.setData({
        indicatorStyle:"",//清空indicatorStyle
        indicatorClass:"indicator-test",//设置indicatorClass为indicator-test
      })
      expect(await pickerViewEl.attribute('indicatorClass')).toBe("indicator-test")
69
      await toScreenshot('picker-view-web-indicator-class')
70 71 72
      await page.setData({
        indicatorClass:"",//清空indicatorClass
      })
DCloud-WZF's avatar
DCloud-WZF 已提交
73
    })
74 75 76 77
    it('mask-style', async () => {
      const maskStyle = "background-image: linear-gradient(to bottom, #d8e5ff, rgba(216, 229, 255, 0));"
      await page.setData({maskStyle})
      expect(await pickerViewEl.attribute('maskStyle')).toBe(maskStyle)
78
      await toScreenshot('picker-view-web-mask-style')
79 80 81 82
    })
    it('mask-class', async () => {
      await page.setData({maskClass:"mask-test"})
      expect(await pickerViewEl.attribute('maskClass')).toBe("mask-test")
83
      await toScreenshot('picker-view-web-mask-class')
84 85 86
    })
    return
  }
87

88 89 90 91 92 93
  if (process.env.UNI_AUTOMATOR_APP_WEBVIEW) {
    it('platform APP WEBVIEW', () => {
      expect(1).toBe(1)
    })
    return
  }
94

95 96 97 98
  it('mask-top-bottom-style', async () => {
    // App端动态设置mask-top-style、mask-bottom-style无效
    const linearToTop = "background-image: linear-gradient(to bottom, #f4ff73, rgba(216, 229, 255, 0));"
    const linearToBottom = "background-image: linear-gradient(to top, #f4ff73, rgba(216, 229, 255, 0));"
DCloud-WZF's avatar
DCloud-WZF 已提交
99
    await page.setData({
100 101
      maskTopStyle: linearToTop,
      maskBottomStyle: linearToBottom,
DCloud-WZF's avatar
DCloud-WZF 已提交
102
    })
103 104 105 106
    await page.waitFor(500)
    expect(await pickerViewEl.attribute('mask-top-style')).toBe(linearToTop)
    expect(await pickerViewEl.attribute('mask-bottom-style')).toBe(linearToBottom)
    await page.waitFor(2000)
107
    await toScreenshot('picker-view-app-mask-top-bottom-style')
DCloud-WZF's avatar
DCloud-WZF 已提交
108
  })
109

110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
  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 () => {
    await page.callMethod('setValue')
128
    await page.waitFor(1500)
129 130 131 132 133
    const eventCallbackNum = await page.callMethod('getEventCallbackNum')
    // 3 times 3*3
    expect(eventCallbackNum).toBe(9)
  })
})