picker-view.test.js 5.0 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
  const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  const isAndroid = platformInfo.startsWith('android')
  const isIOS = platformInfo.startsWith('ios')
  const isMP = platformInfo.startsWith('mp')
  const isWeb = platformInfo.startsWith('web')
9 10 11 12 13 14
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor('view')
    await page.callMethod('setEventCallbackNum', 0)
    pickerViewEl = await page.$('.picker-view')
  })
15

16 17 18
  afterEach(async () => {
    await page.callMethod('setEventCallbackNum', 0)
  })
19

20
  async function toScreenshot(imgName) {
21 22 23 24 25 26 27 28
    const image = await program.screenshot({
      fullPage: true
    });
    expect(image).toSaveImageSnapshot({
      customSnapshotIdentifier() {
        return imgName
      }
    })
29 30
    await page.waitFor(500);
  }
31

DCloud-WZF's avatar
DCloud-WZF 已提交
32
  it('value', async () => {
Y
yurj26 已提交
33
    await page.callMethod('setValue')
34
    await page.waitFor(1000)
35 36


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

DCloud-WZF's avatar
DCloud-WZF 已提交
53 54 55 56 57 58
  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)
  })
59

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

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

102
  if (process.env.UNI_AUTOMATOR_APP_WEBVIEW !== 'true' && !isMP) {
103 104 105 106 107 108 109 110 111 112 113 114 115
    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')
116
    })
117

118 119 120 121 122
    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)
123

124 125 126 127 128
      const {
        year,
        month,
        day
      } = await page.data()
129 130 131
      expect(year).toEqual(2018)
      expect(month).toEqual(1)
      expect(day).toEqual(12)
DCloud-WZF's avatar
DCloud-WZF 已提交
132
    })
133

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

143
})