button.test.js 2.9 KB
Newer Older
Y
yurj26 已提交
1 2 3 4 5 6
const PAGE_PATH = '/pages/component/button/button'

describe('Button.uvue', () => {
  let page
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
Y
yurj26 已提交
7
    await page.waitFor('view')
Y
yurj26 已提交
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58
  })
  it('click', async () => {
    // TODO 待测试框架支持text的dispatchEvent
    // const btn = await page.$('.btn')
    // expect((await page.data())['count']).toEqual(0)
    // await btn.tap()
    // expect((await page.data())['count']).toEqual(1)
    // await page.setData({
    //   disabled_boolean: true,
    // })
    // await btn.tap()
    // expect((await page.data())['count']).toEqual(1)
    // await page.setData({
    //   disabled_boolean: false,
    // })
    // await btn.tap()
    // expect((await page.data())['count']).toEqual(2)
  })
  it('length', async () => {
    const elements = await page.$$('.btn')
    expect(elements.length).toBe(1)
  })
  it('text', async () => {
    const textBtn = await page.$('.btn')
    expect(await textBtn.text()).toEqual('uni-app-x')
    await page.setData({
      text: 'uni-app-x button',
    })
    expect(await textBtn.text()).toEqual('uni-app-x button')
  })
  it('type', async () => {
    const btn = await page.$('.btn')
    expect(await btn.property('type')).toBe('default')
    await page.setData({
      type_enum_current: 1,
    })
    expect(await btn.property('type')).toBe('primary')
    await page.setData({
      type_enum_current: 2,
    })
    expect(await btn.property('type')).toBe('warn')
  })
  it('size', async () => {
    const btn = await page.$('.btn')
    expect(await btn.property('size')).toBe('default')
    await page.setData({
      size_enum_current: 1,
    })
    expect(await btn.property('size')).toBe('mini')
  })
  it('plain', async () => {
59 60
    const btn = await page.$('.btn')
    // TODO
H
hdx 已提交
61 62
    const newValue1 = await btn.property('plain')
    expect(newValue1.toString()).toBe(false + '')
Y
yurj26 已提交
63 64
    await page.setData({
      plain_boolean: true,
65
    })
H
hdx 已提交
66 67
    const newValue2 = await btn.property('plain')
    expect(newValue2.toString()).toBe(true + '')
Y
yurj26 已提交
68 69
  })
  it('disabled', async () => {
70 71
    const btn = await page.$('.btn')
    // TODO
H
hdx 已提交
72 73
    const newValue1 = await btn.property('disabled')
    expect(newValue1.toString()).toBe(false + '')
Y
yurj26 已提交
74 75
    await page.setData({
      disabled_boolean: true,
76
    })
H
hdx 已提交
77 78
    const newValue2 = await btn.property('disabled')
    expect(newValue2.toString()).toBe(true + '')
79 80 81 82 83 84 85 86 87
  })

  it("checkUniButtonElement", async () => {
    if (process.env.uniTestPlatformInfo.startsWith('web')) {
      expect(1).toBe(1)
      return
    }
    const value = await page.callMethod('checkUniButtonElement')
    expect(value).toBe(true)
Y
yurj26 已提交
88
  })
W
WOSHIMAHAIFENG 已提交
89 90 91 92 93 94 95
  it("setbuttonEmpty", async () => {
    const textBtn = await page.$('.btn')
    await page.setData({
      text: '',
    })
    expect(await textBtn.text()).toEqual('')
  })
Y
yurj26 已提交
96
})