提交 223f14e3 编写于 作者: 杜庆泉's avatar 杜庆泉

Merge branch 'master' of http://git.dcloud.io/uni-app-x/hello-uniapp-x into master

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/checkbox/checkbox')
await page.waitFor(1000)
})
describe('Checkbox.uvue', () => {
it('change', async () => {
const cb = await page.$('.cb')
const cb1 = await page.$('.cb1')
const cb2 = await page.$('.cb2')
expect(await getData('value')).toEqual([])
await cb1.tap()
expect(await getData('value')).toEqual(["cb", "cb1"])
await cb.tap()
expect(await getData('value')).toEqual(["cb1"])
await cb2.tap()
expect(await getData('value')).toEqual(["cb1"])
})
it('length', async () => {
const checkboxGroupElements = await page.$$('.checkbox-group')
expect(checkboxGroupElements.length).toBe(3)
const checkboxElements = await page.$$('.checkbox')
expect(checkboxElements.length).toBe(11)
})
it('text', async () => {
const cb = await page.$('.cb')
expect(await cb.text()).toEqual('选中')
await page.setData({
text: 'checked'
})
expect(await cb.text()).toEqual('checked')
})
it('checked', async () => {
const cb = await page.$('.cb')
expect(await cb.property('checked')).toBe(true)
await page.setData({
checked: false
})
await page.waitFor(500)
expect(await cb.property('checked')).toBe(false)
})
it('color', async () => {
const cb = await page.$('.cb')
expect(await cb.property('color')).toBe('#007aff')
await page.setData({
color: '#63acfc'
})
await page.waitFor(500)
expect(await cb.property('color')).toBe('#63acfc')
})
it('disabled', async () => {
const cb = await page.$('.cb2')
expect(await cb.property('disabled')).toBe(true)
await page.setData({
disabled: false
})
await page.waitFor(500)
expect(await cb.property('disabled')).toBe(false)
})
})
\ No newline at end of file
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
</text> </text>
</view> </view>
<view> <view>
<checkbox-group class="uni-flex uni-row"> <checkbox-group class="uni-flex uni-row checkbox-group" @change="testChange">
<checkbox value="cb1" :checked="true" style="margin-right: 30rpx;">选中</checkbox> <checkbox value="cb" :checked="checked" :color="color" style="margin-right: 30rpx;"
<checkbox value="cb">未选中</checkbox> class="checkbox cb">{{text}}</checkbox>
<checkbox value="cb1" style="margin-right: 30rpx;" class="checkbox cb1">未选中</checkbox>
<checkbox value="cb2" :disabled="disabled" class="checkbox cb2">禁用</checkbox>
</checkbox-group> </checkbox-group>
</view> </view>
<view class="uni-title uni-common-mt"> <view class="uni-title uni-common-mt">
...@@ -19,11 +21,11 @@ ...@@ -19,11 +21,11 @@
</text> </text>
</view> </view>
<view> <view>
<checkbox-group class="uni-flex uni-row"> <checkbox-group class="uni-flex uni-row checkbox-group">
<checkbox value="cb1" :checked="true" color="#FFCC33" <checkbox value="cb1" :checked="true" color="#FFCC33"
style="transform:scale(0.7); margin-right: 30rpx;">选中 style="transform:scale(0.7); margin-right: 30rpx;" class="checkbox">选中
</checkbox> </checkbox>
<checkbox value="cb" color="#FFCC33" style="transform:scale(0.7)">未选中</checkbox> <checkbox value="cb" color="#FFCC33" style="transform:scale(0.7)" class="checkbox">未选中</checkbox>
</checkbox-group> </checkbox-group>
</view> </view>
</view> </view>
...@@ -39,9 +41,9 @@ ...@@ -39,9 +41,9 @@
</view> </view>
</view> </view>
<view class="uni-list"> <view class="uni-list">
<checkbox-group @change="checkboxChange"> <checkbox-group @change="checkboxChange" class="checkbox-group">
<checkbox class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value" <checkbox class="uni-list-cell uni-list-cell-pd checkbox" v-for="(item, index) in items"
:value="item.value" :checked="item.checked" :key="item.value" :value="item.value" :checked="item.checked"
:class="index < items.length - 1 ? 'uni-list-cell-line': ''"> :class="index < items.length - 1 ? 'uni-list-cell-line': ''">
{{item.name}} {{item.name}}
</checkbox> </checkbox>
...@@ -89,7 +91,13 @@ ...@@ -89,7 +91,13 @@
name: '法国', name: '法国',
checked: false checked: false
} }
] as ItemType[] ] as ItemType[],
text: '选中',
value: [] as string[],
disabled: true,
checked: true,
color: '#007aff'
} }
}, },
methods: { methods: {
...@@ -104,6 +112,9 @@ ...@@ -104,6 +112,9 @@
item.checked = false item.checked = false
} }
} }
},
testChange: function (e : CheckboxGroupChangeEvent) {
this.value = e.detail.value
} }
} }
} }
......
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/radio/radio')
await page.waitFor(1000)
})
describe('Radio.uvue', () => {
it('change', async () => {
const radio = await page.$('.r')
const radio1 = await page.$('.r1')
const radio2 = await page.$('.r2')
expect(await getData('value')).toEqual("")
await radio1.tap()
expect(await getData('value')).toEqual("r1")
await radio.tap()
expect(await getData('value')).toEqual("r")
await radio2.tap()
expect(await getData('value')).toEqual("r")
})
it('length', async () => {
const radioGroupElements = await page.$$('.radio-group')
expect(radioGroupElements.length).toBe(3)
const radioElements = await page.$$('.radio')
expect(radioElements.length).toBe(11)
})
it('text', async () => {
const radio = await page.$('.r')
expect(await radio.text()).toEqual('选中')
await page.setData({
text: 'checked'
})
expect(await radio.text()).toEqual('checked')
})
it('checked', async () => {
const radio = await page.$('.r')
expect(await radio.property('checked')).toBe(true)
await page.setData({
checked: false
})
await page.waitFor(500)
expect(await radio.property('checked')).toBe(false)
})
it('color', async () => {
const radio = await page.$('.r')
expect(await radio.property('color')).toBe('#007aff')
await page.setData({
color: '#63acfc'
})
await page.waitFor(500)
expect(await radio.property('color')).toBe('#63acfc')
})
it('disabled', async () => {
const radio = await page.$('.r2')
expect(await radio.property('disabled')).toBe(true)
await page.setData({
disabled: false
})
await page.waitFor(500)
expect(await radio.property('disabled')).toBe(false)
})
})
\ No newline at end of file
...@@ -7,10 +7,12 @@ ...@@ -7,10 +7,12 @@
默认样式 默认样式
</text> </text>
</view> </view>
<view class="uni-flex uni-row"> <radio-group class="uni-flex uni-row radio-group" @change="testChange">
<radio value="r1" :checked="true" style="margin-right: 30rpx;">选中</radio> <radio value="r" :checked="checked" :color="color" style="margin-right: 30rpx;" class="radio r">{{text}}
<radio value="r2">未选中</radio> </radio>
</view> <radio value="r1" style="margin-right: 30rpx;" class="radio r1">未选中</radio>
<radio value="r2" :disabled="disabled" class="radio r2">禁用</radio>
</radio-group>
</view> </view>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<view class="uni-title uni-common-mt"> <view class="uni-title uni-common-mt">
...@@ -18,11 +20,12 @@ ...@@ -18,11 +20,12 @@
不同颜色和尺寸的radio 不同颜色和尺寸的radio
</text> </text>
</view> </view>
<view class="uni-flex uni-row"> <radio-group class="uni-flex uni-row radio-group">
<radio value="r1" :checked="true" color="#FFCC33" style="transform:scale(0.7); margin-right: 30rpx;">选中 <radio value="r1" :checked="true" color="#FFCC33" style="transform:scale(0.7); margin-right: 30rpx;"
class="radio">选中
</radio> </radio>
<radio value="r2" color="#FFCC33" style="transform:scale(0.7)">未选中</radio> <radio value="r2" color="#FFCC33" style="transform:scale(0.7)" class="radio">未选中</radio>
</view> </radio-group>
</view> </view>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<view class="uni-title uni-common-mt"> <view class="uni-title uni-common-mt">
...@@ -32,8 +35,8 @@ ...@@ -32,8 +35,8 @@
</view> </view>
</view> </view>
<view class="uni-list"> <view class="uni-list">
<radio-group @change="radioChange"> <radio-group @change="radioChange" class="radio-group">
<radio class="uni-list-cell uni-list-cell-pd" v-for="(item, index) in items" :key="item.value" <radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item.value"
:class="index < items.length - 1 ? 'uni-list-cell-line': ''" :value="item.value" :class="index < items.length - 1 ? 'uni-list-cell-line': ''" :value="item.value"
:checked="index === current"> :checked="index === current">
{{item.name}} {{item.name}}
...@@ -76,7 +79,13 @@ ...@@ -76,7 +79,13 @@
name: '法国' name: '法国'
}, },
] as ItemType[], ] as ItemType[],
current: 0 current: 0,
value: '',
text: '选中',
disabled: true,
checked: true,
color: '#007aff'
} }
}, },
methods: { methods: {
...@@ -87,6 +96,9 @@ ...@@ -87,6 +96,9 @@
break; break;
} }
} }
},
testChange(e : RadioGroupChangeEvent) {
this.value = e.detail.value
} }
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册