progress.test.js 3.3 KB
Newer Older
Y
yurj26 已提交
1
function getData(key = '') {
Y
yurj26 已提交
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 9
}

let page
beforeAll(async () => {
Y
yurj26 已提交
10 11
  page = await program.reLaunch('/pages/component/progress/progress')
  await page.waitFor(2000);
Y
yurj26 已提交
12 13
})

14 15 16 17
beforeEach(async () => {
  await page.callMethod('setEventCallbackNum', 0)
})

Y
yurj26 已提交
18
describe('Progress.uvue', () => {
Y
yurj26 已提交
19 20 21 22
  it('percent', async () => {
    await page.callMethod('setProgress')
    await page.waitFor(1000);
    const p = await page.$('.p')
23
    expect(await p.attribute('percent')).toEqual(20 + '')
Y
yurj26 已提交
24
    const p1 = await page.$('.p1')
25
    expect(await p1.attribute('percent')).toEqual(40 + '')
Y
yurj26 已提交
26
    const p2 = await page.$('.p2')
27
    expect(await p2.attribute('percent')).toEqual(60 + '')
Y
yurj26 已提交
28
    const p3 = await page.$('.p3')
29
    expect(await p3.attribute('percent')).toEqual(80 + '')
Y
yurj26 已提交
30 31 32 33 34
    if (process.env.UNI_PLATFORM === 'app-android') {
      expect(await getData('curPercent')).toEqual(20)
    }
    await page.callMethod('clearProgress')
    await page.waitFor(1000)
35 36 37 38
    expect(await p.attribute('percent')).toEqual(0 + '')
    expect(await p1.attribute('percent')).toEqual(0 + '')
    expect(await p2.attribute('percent')).toEqual(0 + '')
    expect(await p3.attribute('percent')).toEqual(0 + '')
Y
yurj26 已提交
39 40 41 42 43 44 45 46 47 48
    if (process.env.UNI_PLATFORM === 'app-android') {
      expect(await getData('curPercent')).toEqual(0)
    }
  })
  it('length', async () => {
    const elements = await page.$$('.progress')
    expect(elements.length).toBe(4)
  })
  it('show-info', async () => {
    const el = await page.$('.p')
49
    expect(await el.attribute('show-info')).toEqual(true + '')
Y
yurj26 已提交
50 51
    await page.setData({
      showInfo: false
Y
yurj26 已提交
52
    })
53
    expect(await el.attribute('show-info')).toEqual(false + '')
Y
yurj26 已提交
54 55 56
  })
  it('border-radius', async () => {
    const el = await page.$('.p')
57
    expect(await el.attribute('border-radius')).toEqual(0 + '')
Y
yurj26 已提交
58 59
    await page.setData({
      borderRadius: 5
Y
yurj26 已提交
60
    })
61
    expect(await el.attribute('border-radius')).toEqual(5 + '')
Y
yurj26 已提交
62 63 64
  })
  it('font-size', async () => {
    const el = await page.$('.p')
65
    expect(await el.attribute('font-size')).toEqual(16 + '')
Y
yurj26 已提交
66 67
    await page.setData({
      fontSize: 18
Y
yurj26 已提交
68
    })
69
    expect(await el.attribute('font-size')).toEqual(18 + '')
Y
yurj26 已提交
70 71 72
  })
  it('stroke-width', async () => {
    const el = await page.$('.p')
73
    expect(await el.attribute('stroke-width')).toEqual(3 + '')
Y
yurj26 已提交
74 75
    await page.setData({
      strokeWidth: 6
Y
yurj26 已提交
76
    })
77
    expect(await el.attribute('stroke-width')).toEqual(6 + '')
Y
yurj26 已提交
78 79 80
  })
  it('backgroundColor', async () => {
    const el = await page.$('.p')
雪洛's avatar
雪洛 已提交
81
    expect(await el.attribute('background-color')).toEqual('#EBEBEB')
Y
yurj26 已提交
82 83
    await page.setData({
      backgroundColor: "#007aff"
Y
yurj26 已提交
84
    })
雪洛's avatar
雪洛 已提交
85
    expect(await el.attribute('background-color')).toEqual('#007aff')
Y
yurj26 已提交
86
  })
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
  it('trigger UniProgressActiveendEvent', async () => {

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

    await page.setData({
      pgList: [21, 40, 60, 80]
    })
    // 动画执行
    await page.waitFor(1000);
    const eventCallbackNum = await page.callMethod('getEventCallbackNum')
    expect(eventCallbackNum).toBe(3)
  })
104
})