radio.test.js 1.9 KB
Newer Older
Y
yurj26 已提交
1
function getData(key = '') {
DCloud-WZF's avatar
DCloud-WZF 已提交
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 () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
10
  page = await program.reLaunch('/pages/component/radio/radio')
DCloud-WZF's avatar
DCloud-WZF 已提交
11
  await page.waitFor(2000);
Y
yurj26 已提交
12 13 14
})

describe('Radio.uvue', () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
15 16
  it('change', async () => {
    expect(await getData('value')).toEqual('')
DCloud-WZF's avatar
DCloud-WZF 已提交
17
    const radio1 = await page.$('.r1')
DCloud-WZF's avatar
DCloud-WZF 已提交
18 19
    await radio1.tap()
    expect(await getData('value')).toEqual('r1')
DCloud-WZF's avatar
DCloud-WZF 已提交
20
    const radio = await page.$('.r')
DCloud-WZF's avatar
DCloud-WZF 已提交
21 22
    await radio.tap()
    expect(await getData('value')).toEqual('r')
DCloud-WZF's avatar
DCloud-WZF 已提交
23
    const radio2 = await page.$('.r2')
DCloud-WZF's avatar
DCloud-WZF 已提交
24 25 26 27 28 29 30
    await radio2.tap()
    expect(await getData('value')).toEqual('r')
  })
  it('length', async () => {
    const radioGroupElements = await page.$$('.radio-group')
    expect(radioGroupElements.length).toBe(3)
    const radioElements = await page.$$('.radio')
Y
yurj26 已提交
31
    expect(radioElements.length).toBe(12)
DCloud-WZF's avatar
DCloud-WZF 已提交
32 33 34 35 36 37 38 39 40 41 42
  })
  it('text', async () => {
    const radio = await page.$('.r1')
    expect(await radio.text()).toEqual('未选中')
    await page.setData({
      text: 'not selected',
    })
    expect(await radio.text()).toEqual('not selected')
  })
  it('checked', async () => {
    const radio = await page.$('.r')
雪洛's avatar
雪洛 已提交
43
    expect(await radio.attribute('checked')).toBe(true)
DCloud-WZF's avatar
DCloud-WZF 已提交
44 45 46
    await page.setData({
      checked: false,
    })
雪洛's avatar
雪洛 已提交
47
    expect(await radio.attribute('checked')).toBe(false)
DCloud-WZF's avatar
DCloud-WZF 已提交
48 49 50
  })
  it('color', async () => {
    const radio = await page.$('.r')
雪洛's avatar
雪洛 已提交
51
    expect(await radio.attribute('color')).toBe('#007aff')
DCloud-WZF's avatar
DCloud-WZF 已提交
52 53
    await page.setData({
      color: '#63acfc',
Y
yurj26 已提交
54
    })
雪洛's avatar
雪洛 已提交
55
    expect(await radio.attribute('color')).toBe('#63acfc')
DCloud-WZF's avatar
DCloud-WZF 已提交
56 57 58
  })
  it('disabled', async () => {
    const radio = await page.$('.r2')
雪洛's avatar
雪洛 已提交
59
    expect(await radio.attribute('disabled')).toBe(true)
DCloud-WZF's avatar
DCloud-WZF 已提交
60 61 62
    await page.setData({
      disabled: false,
    })
雪洛's avatar
雪洛 已提交
63
    expect(await radio.attribute('disabled')).toBe(false)
DCloud-WZF's avatar
DCloud-WZF 已提交
64 65
  })
})