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

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

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

DCloud-WZF's avatar
DCloud-WZF 已提交
27
  it('value', async () => {
Y
yurj26 已提交
28
    await page.callMethod('setValue')
29
    await page.waitFor(1000)
30 31


32
    const newValue1 = await pickerViewEl.property('value')
33
    // TODO
34
    expect(newValue1.toString()).toEqual('0,1,30')
Y
yurj26 已提交
35
    if (process.env.UNI_PLATFORM === 'app-android') {
36
      expect(await page.data('result')).toEqual([0, 0, 0])
Y
yurj26 已提交
37 38
    }
    await page.callMethod('setValue1')
39
    await page.waitFor(1000)
40
    const newValue2 = await pickerViewEl.property('value')
41 42
    // TODO
    expect(newValue2.toString()).toEqual('10,10,10')
Y
yurj26 已提交
43
    if (process.env.UNI_PLATFORM === 'app-android') {
44
      expect(await page.data('result')).toEqual([10, 10, 10])
Y
yurj26 已提交
45
    }
DCloud-WZF's avatar
DCloud-WZF 已提交
46
  })
Y
yurj26 已提交
47

DCloud-WZF's avatar
DCloud-WZF 已提交
48 49 50 51 52 53
  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)
  })
54

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

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

97 98 99 100 101 102 103 104 105 106 107 108 109 110
  if (process.env.UNI_AUTOMATOR_APP_WEBVIEW !== 'true') {
    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));"
      await page.setData({
        maskTopStyle: linearToTop,
        maskBottomStyle: linearToBottom,
      })
      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)
      await toScreenshot('picker-view-app-mask-top-bottom-style')
111
    })
112

113 114 115 116 117
    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)
118

119 120 121 122 123
      const {
        year,
        month,
        day
      } = await page.data()
124 125 126
      expect(year).toEqual(2018)
      expect(month).toEqual(1)
      expect(day).toEqual(12)
DCloud-WZF's avatar
DCloud-WZF 已提交
127
    })
128

129 130 131 132
    it('trigger UniPickerViewChangeEvent', async () => {
      await page.callMethod('setValue')
      await page.waitFor(1500)
      const eventCallbackNum = await page.callMethod('getEventCallbackNum')
133
      // 年月日滚动三次,测试 e.tagName +1 和 e.type+2,正常为9
134 135 136
      expect(eventCallbackNum).toBe(9)
    })
  }
137

138
})