label.test.js 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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
let page;
describe('label.uvue', () => {
  console.log(process.env.uniTestPlatformInfo,process.env.uniTestPlatformInfo.startsWith('web'))
  if (!process.env.uniTestPlatformInfo.startsWith('web')) {
    it('app', () => {
      expect(1).toBe(1)
    })
    return
  }
  beforeAll(async () => {
    page = await program.reLaunch('/pages/component/label/label')
    await page.waitFor('view');
  });
  afterEach(async() => {
    await page.setData({
      checkboxValue: [],
      radioValue:''
    })
  });
  function getData(key = '') {
    return new Promise(async (resolve, reject) => {
      const data = await page.data()
      resolve(key ? data[key] : data)
    })
  }
  it('表单组件在label内', async () => {
    expect(await getData('checkboxValue')).toEqual([])
    const checkboxItems = await page.$$('.checkboxItemsTest')
    await checkboxItems[0].tap()
    expect(await getData('checkboxValue')).toEqual(['USA', 'CHN'])
  })
  it('label用for标识表单组件', async () => {
    const radioItems = await page.$$('.label-2-text')
    await radioItems[0].tap()
    expect(await getData('radioValue')).toEqual('USA')
    await radioItems[1].tap()
    expect(await getData('radioValue')).toEqual('CHN')
  })
  it('label内有多个时选中第一个', async () => {
    const labelText = await page.$('.uni-center')
    await labelText.tap()
    expect(await getData('checkboxValue')).toEqual([''])
  })
})