提交 03dcd92d 编写于 作者: 辛宝Otto's avatar 辛宝Otto 🥊

test: 补充 progress/picker-view 事件测试

上级 d9f88214
...@@ -4,21 +4,26 @@ function getData(key = '') { ...@@ -4,21 +4,26 @@ function getData(key = '') {
resolve(key ? data[key] : data) resolve(key ? data[key] : data)
}) })
} }
const PAGE_PATH = '/pages/component/picker-view/picker-view' const PAGE_PATH = '/pages/component/picker-view/picker-view'
let page let page
beforeAll(async () => { beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH) page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view') await page.waitFor('view')
await page.callMethod('setEventCallbackNum', 0)
})
afterEach(async () => {
await page.callMethod('setEventCallbackNum', 0)
}) })
describe('PickerView.uvue', () => { describe('PickerView.uvue', () => {
it('value', async () => { it('value', async () => {
const el = await page.$('.picker-view') const el = await page.$('.picker-view')
await page.callMethod('setValue') await page.callMethod('setValue')
await page.waitFor(1000) await page.waitFor(1000)
const newValue1 = await el.property('value') const newValue1 = await el.property('value')
// TODO // TODO
expect(newValue1.toString()).toEqual('0,0,0') expect(newValue1.toString()).toEqual('0,0,0')
if (process.env.UNI_PLATFORM === 'app-android') { if (process.env.UNI_PLATFORM === 'app-android') {
...@@ -26,8 +31,8 @@ describe('PickerView.uvue', () => { ...@@ -26,8 +31,8 @@ describe('PickerView.uvue', () => {
} }
await page.callMethod('setValue1') await page.callMethod('setValue1')
await page.waitFor(1000) await page.waitFor(1000)
const newValue2 = await el.property('value') const newValue2 = await el.property('value')
// TODO // TODO
expect(newValue2.toString()).toEqual('10,10,10') expect(newValue2.toString()).toEqual('10,10,10')
if (process.env.UNI_PLATFORM === 'app-android') { if (process.env.UNI_PLATFORM === 'app-android') {
...@@ -62,21 +67,39 @@ describe('PickerView.uvue', () => { ...@@ -62,21 +67,39 @@ describe('PickerView.uvue', () => {
maskBottomStyle: 'background: #ffffff;', maskBottomStyle: 'background: #ffffff;',
}) })
expect(await el.attribute('mask-bottom-style')).toBe('background: #ffffff;') expect(await el.attribute('mask-bottom-style')).toBe('background: #ffffff;')
})
it('reopen-picker-view-page', async () => {
page = await program.switchTab('/pages/tabBar/component')
await page.waitFor(500)
page = await program.navigateTo(PAGE_PATH)
await page.waitFor(500)
const date = new Date()
const {
year,
month,
day
} = await page.data()
expect(year).toEqual(date.getFullYear())
expect(month).toEqual(date.getMonth() + 1)
expect(day).toEqual(date.getDate())
}) })
})
it('reopen-picker-view-page', async () => {
page = await program.switchTab('/pages/tabBar/component')
await page.waitFor(500)
page = await program.navigateTo(PAGE_PATH)
await page.waitFor(500)
const date = new Date()
const {
year,
month,
day
} = await page.data()
expect(year).toEqual(date.getFullYear())
expect(month).toEqual(date.getMonth() + 1)
expect(day).toEqual(date.getDate())
})
it('trigger UniPickerViewChangeEvent', async () => {
// if web skip todo
if (
process.env.uniTestPlatformInfo.startsWith('web')
) {
expect(1).toBe(1)
return
}
const el = await page.$('.picker-view')
await page.callMethod('setValue')
await page.waitFor(1000)
const eventCallbackNum = await page.callMethod('getEventCallbackNum')
// 3 times 3*3
expect(eventCallbackNum).toBe(9)
})
})
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
</view> </view>
</template> </template>
<script lang="uts"> <script lang="uts">
import { state, setEventCallbackNum } from '@/store/index.uts'
export default { export default {
data() { data() {
const date = new Date() const date = new Date()
...@@ -56,8 +57,25 @@ ...@@ -56,8 +57,25 @@
maskBottomStyle: '' maskBottomStyle: ''
} }
}, },
methods: { methods: {
bindChange(e : UniPickerViewChangeEvent) { // 自动化测试
getEventCallbackNum() : number {
return state.eventCallbackNum
},
// 自动化测试
setEventCallbackNum(num : number) {
setEventCallbackNum(num)
},
bindChange(e : UniPickerViewChangeEvent) {
// 自动化测试
console.log(e.target?.tagName,e.type);
if ((e.target?.tagName ?? '').includes('PICKER-VIEW')) {
this.setEventCallbackNum(state.eventCallbackNum + 1)
}
if (e.type === 'change') {
this.setEventCallbackNum(state.eventCallbackNum + 2)
}
const val = e.detail.value const val = e.detail.value
this.result = val this.result = val
this.year = this.years[val[0]] this.year = this.years[val[0]]
......
...@@ -11,6 +11,10 @@ beforeAll(async () => { ...@@ -11,6 +11,10 @@ beforeAll(async () => {
await page.waitFor(2000); await page.waitFor(2000);
}) })
beforeEach(async () => {
await page.callMethod('setEventCallbackNum', 0)
})
describe('Progress.uvue', () => { describe('Progress.uvue', () => {
it('percent', async () => { it('percent', async () => {
await page.callMethod('setProgress') await page.callMethod('setProgress')
...@@ -80,4 +84,21 @@ describe('Progress.uvue', () => { ...@@ -80,4 +84,21 @@ describe('Progress.uvue', () => {
}) })
expect(await el.attribute('background-color')).toEqual('#007aff') expect(await el.attribute('background-color')).toEqual('#007aff')
}) })
it('trigger UniProgressActiveendEvent', async () => {
if (
process.env.uniTestPlatformInfo.startsWith('web')
) {
expect(1).toBe(1)
return
}
await page.setData({
pgList: [21, 40, 60, 80]
})
// 动画执行
await page.waitFor(1000);
const eventCallbackNum = await page.callMethod('getEventCallbackNum')
expect(eventCallbackNum).toBe(3)
})
}) })
<script> <script>
import { state, setEventCallbackNum } from '@/store/index.uts'
import { ItemType } from '@/components/enum-data/enum-data' import { ItemType } from '@/components/enum-data/enum-data'
export default { export default {
data() { data() {
...@@ -25,6 +26,15 @@ ...@@ -25,6 +26,15 @@
} }
}, },
methods: { methods: {
// 自动化测试
getEventCallbackNum() : number {
return state.eventCallbackNum
},
// 自动化测试
setEventCallbackNum(num : number) {
setEventCallbackNum(num)
},
setProgress() { setProgress() {
this.pgList = [20, 40, 60, 80] as number[] this.pgList = [20, 40, 60, 80] as number[]
}, },
...@@ -32,6 +42,13 @@ ...@@ -32,6 +42,13 @@
this.pgList = [0, 0, 0, 0] as number[] this.pgList = [0, 0, 0, 0] as number[]
}, },
activeend(e : UniProgressActiveendEvent) { activeend(e : UniProgressActiveendEvent) {
// 自动化测试
if ((e.target?.tagName ?? '').includes('PROGRESS')) {
this.setEventCallbackNum(state.eventCallbackNum + 1)
}
if (e.type === 'activeend') {
this.setEventCallbackNum(state.eventCallbackNum + 2)
}
this.curPercent = e.detail.curPercent this.curPercent = e.detail.curPercent
}, },
progress_touchstart() { console.log("手指触摸动作开始") }, progress_touchstart() { console.log("手指触摸动作开始") },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册