progress.test.js 2.8 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
})

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