button.test.js 2.5 KB
Newer Older
Y
yurj26 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
function getData(key = '') {
    return new Promise(async (resolve, reject) => {
        const data = await page.data()
        resolve(key ? data[key] : data)
    })
}

let page
beforeAll(async () => {
    page = await program.reLaunch('/pages/component/button/button')
    await page.waitFor(1000)
})

describe('Button.uvue', () => {
    it('click', async () => {
        const defaultBtn = await page.$('.default-button')
        const disabledBtn = await page.$('.disabled-button')
        expect(await getData('count')).toEqual(0)
        await defaultBtn.tap()
        expect(await getData('count')).toEqual(1)
        await disabledBtn.tap()
        expect(await getData('count')).toEqual(1)
    })
    it('length', async () => {
Y
yurj26 已提交
25 26
        const elements = await page.$$('.button')
        expect(elements.length).toBe(13)
Y
yurj26 已提交
27 28 29 30 31 32 33 34 35 36 37
    })
    it('text', async () => {
        const textBtn = await page.$('.text-button')
        expect(await textBtn.text()).toEqual('按钮')
        await page.setData({
            text: 'button'
        })
        // TODO 待修复
        expect(await textBtn.text()).toEqual('button')
    })
    it('type', async () => {
Y
yurj26 已提交
38 39
        const btn = await page.$('.test-button')
        expect(await btn.property('type')).toBe('primary')
Y
yurj26 已提交
40 41 42 43 44 45 46 47 48 49 50 51
        await page.setData({
            type: 'default'
        })
        await page.waitFor(500)
        expect(await btn.property('type')).toBe('default')
        await page.setData({
            type: 'warn'
        })
        await page.waitFor(500)
        expect(await btn.property('type')).toBe('warn')
    })
    it('size', async () => {
Y
yurj26 已提交
52
        const btn = await page.$('.test-button')
Y
yurj26 已提交
53 54 55 56
        expect(await btn.property('size')).toBe('default')
        await page.setData({
            size: 'mini'
        })
Y
yurj26 已提交
57 58
        await page.waitFor(500)
        expect(await btn.property('size')).toBe('mini')
Y
yurj26 已提交
59 60
    })
    it('plain', async () => {
Y
yurj26 已提交
61
        const btn = await page.$('.test-button')
Y
yurj26 已提交
62 63 64 65 66 67 68 69
        expect(await btn.property('plain')).toBe(false)
        await page.setData({
            plain: true
        })
        await page.waitFor(500)
        expect(await btn.property('plain')).toBe(true)
    })
    it('disabled', async () => {
Y
yurj26 已提交
70
        const btn = await page.$('.test-button')
Y
yurj26 已提交
71 72 73 74 75 76 77 78
        expect(await btn.property('disabled')).toBe(false)
        await page.setData({
            disabled: true
        })
        await page.waitFor(500)
        expect(await btn.property('disabled')).toBe(true)
    })
})