提交 96469f1d 编写于 作者: Y yurj26

feat: update button test

上级 58016106
const PAGE_PATH = '/pages/component/button/button'
describe('Button.uvue', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
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,
})
await page.waitFor(500)
expect(await btn.property('type')).toBe('primary')
await page.setData({
type_enum_current: 2,
})
await page.waitFor(500)
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,
})
await page.waitFor(500)
expect(await btn.property('size')).toBe('mini')
})
it('plain', async () => {
const btn = await page.$('.btn')
expect(await btn.property('plain')).toBe(false)
await page.setData({
plain_boolean: true,
})
await page.waitFor(500)
expect(await btn.property('plain')).toBe(true)
})
it('disabled', async () => {
const btn = await page.$('.btn')
expect(await btn.property('disabled')).toBe(false)
await page.setData({
disabled_boolean: true,
})
await page.waitFor(500)
expect(await btn.property('disabled')).toBe(true)
})
})
\ No newline at end of file
<script>
import { type ItemType } from '@/components/enum-data/enum-data.vue'
export default {
import { type ItemType } from '@/components/enum-data/enum-data.vue'
export default {
data() {
return {
plain_boolean: false,
disabled_boolean: false,
size_enum: [{"value":0,"name":"default"},{"value":1,"name":"mini"}] as ItemType[],
default_style: false,
size_enum: [{ "value": 0, "name": "default" }, { "value": 1, "name": "mini" }] as ItemType[],
size_enum_current: 0,
type_enum: [{"value":0,"name":"default"},{"value":1,"name":"primary"},{"value":2,"name":"warn"}] as ItemType[],
type_enum_current: 0
type_enum: [{ "value": 0, "name": "default" }, { "value": 1, "name": "primary" }, { "value": 2, "name": "warn" }] as ItemType[],
type_enum_current: 0,
count: 0,
text: 'uni-app-x'
}
},
methods: {
button_click() { console.log("组件被点击时触发") },
button_click() {
console.log("组件被点击时触发")
this.count++
},
button_touchstart() { console.log("手指触摸动作开始") },
button_touchmove() { console.log("手指触摸后移动") },
button_touchcancel() { console.log("手指触摸动作被打断,如来电提醒,弹窗") },
......@@ -21,10 +27,11 @@ export default {
button_longpress() { console.log("如果一个组件被绑定了 longpress 事件,那么当用户长按这个组件时,该事件将会被触发。") },
change_plain_boolean(checked : boolean) { this.plain_boolean = checked },
change_disabled_boolean(checked : boolean) { this.disabled_boolean = checked },
change_default_style(checked : boolean) { this.default_style = checked },
radio_change_size_enum(checked : number) { this.size_enum_current = checked },
radio_change_type_enum(checked : number) { this.type_enum_current = checked }
}
}
}
</script>
<template>
......@@ -32,12 +39,17 @@ export default {
<scroll-view style="flex:1">
<!-- #endif -->
<view class="main">
<button :disabled="disabled_boolean" :size="size_enum[size_enum_current].name" :type="type_enum[type_enum_current].name" :plain="plain_boolean" @click="button_click" @touchstart="button_touchstart" @touchmove="button_touchmove" @touchcancel="button_touchcancel" @touchend="button_touchend" @tap="button_tap" @longpress="button_longpress">uni-app-x</button>
<button :disabled="disabled_boolean" :size="size_enum[size_enum_current].name"
:type="type_enum[type_enum_current].name" :plain="plain_boolean" @click="button_click"
@touchstart="button_touchstart" @touchmove="button_touchmove" @touchcancel="button_touchcancel"
@touchend="button_touchend" @tap="button_tap" @longpress="button_longpress" class="btn"
:style="default_style ? 'color: #cccccc': ''">{{text}}</button>
</view>
<view class="content nvue">
<view class="content">
<boolean-data :defaultValue="false" title="按钮是否镂空,背景色透明" @change="change_plain_boolean"></boolean-data>
<boolean-data :defaultValue="false" title="是否禁用" @change="change_disabled_boolean"></boolean-data>
<boolean-data :defaultValue="false" title="是否设置文字颜色" @change="change_default_style"></boolean-data>
<enum-data :items="size_enum" title="按钮的大小" @change="radio_change_size_enum"></enum-data>
<enum-data :items="type_enum" title="按钮的类型" @change="radio_change_type_enum"></enum-data>
</view>
......@@ -47,18 +59,17 @@ export default {
</template>
<style>
.main {
.main {
max-height: 500rpx;
padding: 10rpx 0;
border-bottom: 1px solid rgba(0,0,0,.06);
border-bottom: 1px solid rgba(0, 0, 0, .06);
flex-direction: row;
justify-content: center;
}
}
.main .list-item {
width:100%;
height:200rpx;
.main .list-item {
width: 100%;
height: 200rpx;
border: 1px solid #666;
}
}
</style>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册