提交 d377f1b7 编写于 作者: Y yurj26

feat(button): add test

上级 9c9f75e3
module.exports = {
"is-custom-runtime": false,
"compile": true,
"h5": {
"options": {
"headless": true
},
"executablePath": ""
},
"mp-weixin": {
"port": 9420,
"account": "",
"args": "",
"cwd": "",
"launch": true,
"teardown": "disconnect",
"remote": false,
"executablePath": ""
},
"app-plus": {
"android": {
"id": "",
"executablePath": ""
},
"version": "",
"ios": {
"id": "",
"executablePath": ""
},
"uni-app-x": {
"version": "/Applications/HBuilderX-Alpha.app/Contents/HBuilderX/plugins/uniappx-launcher/base/version.txt",
"android": {
"id": "emulator-5554",
"executablePath": "/Applications/HBuilderX-Alpha.app/Contents/HBuilderX/plugins/uniappx-launcher/base/android_base.apk"
}
}
}
}
\ No newline at end of file
module.exports = {
testTimeout: 10000,
reporters: [
'default'
],
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
moduleFileExtensions: ['js', 'json'],
rootDir: __dirname,
testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)"],
testPathIgnorePatterns: ['/node_modules/']
}
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 () => {
const btnLen = await page.$$('.button')
expect(btnLen.length).toBe(13)
})
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 () => {
// TODO 目前获取组件属性只能通过组件的name,并且拿到的是最后一个
const btn = await page.$('Button')
expect(await btn.property('type')).toBe('warn')
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 () => {
const btn = await page.$('Button')
expect(await btn.property('size')).toBe('mini')
await page.setData({
size: 'default'
})
await page.waitFor(500)
expect(await btn.property('size')).toBe('default')
await page.setData({
size: 'mini'
})
})
it('plain', async () => {
const btn = await page.$('Button')
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 () => {
const btn = await page.$('Button')
expect(await btn.property('disabled')).toBe(false)
await page.setData({
disabled: true
})
await page.waitFor(500)
expect(await btn.property('disabled')).toBe(true)
})
})
\ No newline at end of file
...@@ -2,18 +2,18 @@ ...@@ -2,18 +2,18 @@
<view> <view>
<page-head :title="title"></page-head> <page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt"> <view class="uni-padding-wrap uni-common-mt">
<button type="primary">页面主操作 Normal</button> <button type="primary" class="button test-button">页面主操作 Normal</button>
<!-- <button type="primary" :loading="loading" class="button">页面主操作 Loading</button> --> <!-- <button type="primary" :loading="loading" class="button">页面主操作 Loading</button> -->
<button type="primary" :disabled="true" class="button">页面主操作 Disabled</button> <button type="primary" :disabled="true" class="button">页面主操作 Disabled</button>
<button type="default" class="button">页面次要操作 Normal</button> <button type="default" class="button default-button" @click="addCount">页面次要操作 Normal</button>
<button type="default" :disabled="true" class="button">页面次要操作 Disabled</button> <button type="default" :disabled="true" class="button disabled-button">页面次要操作 Disabled</button>
<button type="warn" class="button">警告类操作 Normal</button> <button type="warn" class="button">警告类操作 Normal</button>
<button type="warn" :disabled="true" class="button">警告类操作 Disabled</button> <button type="warn" :disabled="true" class="button">警告类操作 Disabled</button>
<view class="button-sp-area"> <view class="button-sp-area">
<button type="primary" :plain="true" class="button">按钮</button> <button type="primary" :plain="true" class="button text-button">{{text}}</button>
<button type="primary" :disabled="true" :plain="true" class="button"> <button type="primary" :disabled="true" :plain="true" class="button">
不可点击的按钮 不可点击的按钮
</button> </button>
...@@ -24,7 +24,8 @@ ...@@ -24,7 +24,8 @@
<view class="uni-flex uni-row"> <view class="uni-flex uni-row">
<button class="button mini-btn" type="primary" size="mini">按钮</button> <button class="button mini-btn" type="primary" size="mini">按钮</button>
<button class="button mini-btn" type="default" size="mini">按钮</button> <button class="button mini-btn" type="default" size="mini">按钮</button>
<button class="button mini-btn" type="warn" size="mini">按钮</button> <button class="button mini-btn" :type="type" :size="size" :plain="plain"
:disabled="disabled">按钮</button>
</view> </view>
</view> </view>
</view> </view>
...@@ -36,7 +37,13 @@ ...@@ -36,7 +37,13 @@
return { return {
title: 'button', title: 'button',
loading: false, loading: false,
_timer: 0 _timer: 0,
text: '按钮',
type: 'warn',
size: 'mini',
plain: false,
disabled: false,
count: 0
} }
}, },
onShow() { onShow() {
...@@ -55,6 +62,9 @@ ...@@ -55,6 +62,9 @@
// clearTimeout(this._timer); // clearTimeout(this._timer);
// } // }
// } // }
addCount() {
this.count++
}
}, },
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册