radio.test.js 2.5 KB
Newer Older
1 2 3 4 5 6 7 8
function getData(key = '') {
  return new Promise(async (resolve, reject) => {
    const data = await page.data()
    resolve(key ? data[key] : data)
  })
}

let page
9
let originEventCallbackNum
10 11
beforeAll(async () => {
  page = await program.reLaunch('/pages/component/radio/radio')
12 13 14 15 16
  await page.waitFor(2000)
  originEventCallbackNum = await page.callMethod('getEventCallbackNum')
})
beforeEach(async () => {
  await page.callMethod('setEventCallbackNum', 0)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
})

describe('Radio.uvue', () => {
  it('change', async () => {
    expect(await getData('value')).toEqual('')
    const radio1 = await page.$('.r1')
    await radio1.tap()
    expect(await getData('value')).toEqual('r1')
    const radio = await page.$('.r')
    await radio.tap()
    expect(await getData('value')).toEqual('r')
    const radio2 = await page.$('.r2')
    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')
    expect(radioElements.length).toBe(12)
  })
  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')
H
hdx 已提交
48 49 50
    // TODO
    const newValue1 = await radio.property('checked')
    expect(newValue1.toString()).toBe(true + '')
51 52 53
    await page.setData({
      checked: false,
    })
H
hdx 已提交
54 55
    const newValue2 = await radio.property('checked')
    expect(newValue2.toString()).toBe(false + '')
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  })
  it('color', async () => {
    const radio = await page.$('.r')
    expect(await radio.attribute('color')).toBe('#007aff')
    await page.setData({
      color: '#63acfc',
    })
    expect(await radio.attribute('color')).toBe('#63acfc')
  })
  it('disabled', async () => {
    const radio = await page.$('.r2')
    expect(await radio.attribute('disabled')).toBe(true + '')
    await page.setData({
      disabled: false,
    })
    expect(await radio.attribute('disabled')).toBe(false + '')
  })
73 74 75
  it('trigger UniRadioGroupChangeEvent', async () => {
    const element = await page.$('#trigger-change')
    await element.tap()
76 77
    console.log('radio trigger change event', element)
    await page.waitFor(1000)
78 79 80
    const eventCallbackNum = await page.callMethod('getEventCallbackNum')
    expect(eventCallbackNum - originEventCallbackNum).toBe(3)
  })
81
})