提交 ccb9fdfe 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

feat(dialogPage): 补充 dialogPage 方法示例及测试

上级 0afab4b3
<template> <template>
<view id="dialog1" class="dialog-container"> <view id="dialog1" class="dialog-container">
<view class="dialog-content"> <view class="dialog-content">
<text>title: {{title}}</text> <text>title: {{ title }}</text>
<text class="mt-10">onBackPress return true</text> <text class="mt-10">onBackPress return true</text>
<button class="mt-10" id="dialog1-go-next-page" @click="goNextPage">go next page</button> <button class="mt-10" id="dialog1-go-next-page" @click="goNextPage">
<button class="mt-10" id="dialog1-open-dialog2" @click="openDialog2">openDialog2</button> go next page
<button class="mt-10" id="dialog1-close-dialog" @click="closeDialog">closeDialog</button> </button>
<button class="mt-10" id="dialog1-close-this-dialog" @click="closeThisDialog">closeThisDialog</button> <button class="mt-10" id="dialog1-open-dialog2" @click="openDialog2">
openDialog2
</button>
<button class="mt-10" id="dialog1-close-dialog" @click="closeDialog">
closeDialog
</button>
<button class="mt-10" id="dialog1-close-this-dialog" @click="closeThisDialog">
closeThisDialog
</button>
<button class="mt-10" @click="checkGetParentPage">
check getParentPage
</button>
<button class="mt-10" @click="checkGetElementById">
check getElementById
</button>
<button class="mt-10" @click="toggleBackgroundColor">
toggleBackgroundColor
</button>
<button class="mt-10" id="dialog1-back" @click="back">back</button> <button class="mt-10" id="dialog1-back" @click="back">back</button>
<input class="uni-common-mt" style="border-width: 1px;border-style: solid;" :focus="true" value="DialogPage中焦点测试"/> <input class="uni-common-mt" style="border-width: 1px; border-style: solid" :focus="true"
value="DialogPage中焦点测试" />
</view> </view>
</view> </view>
</template> </template>
...@@ -23,6 +41,7 @@ ...@@ -23,6 +41,7 @@
data() { data() {
return { return {
title: 'dialog 1', title: 'dialog 1',
backgroundColorContent: 'transparent'
} }
}, },
onLoad(options : OnLoadOptions) { onLoad(options : OnLoadOptions) {
...@@ -137,6 +156,39 @@ ...@@ -137,6 +156,39 @@
} }
}) })
}, },
checkGetParentPage() : boolean {
const parentPage = this.$page.getParentPage()
console.log('checkGetParentPage', parentPage)
const res = parentPage != null
uni.showToast(res ? {
title: 'check success'
} : {
title: 'check fail',
icon: 'error'
})
return res
},
checkGetElementById() : boolean {
const page = this.$page
const element = page.getElementById('dialog1-go-next-page')
let res = element != null
// #ifndef APP-ANDROID
if (res) {
const elPage = element!.getPage()
console.log('elPage', elPage)
res = elPage === page
}
// #endif
console.log('check getElementById', res)
uni.showToast(res ? { title: 'check success' } : { title: 'check fail', icon: 'error' })
return res
},
toggleBackgroundColor() {
this.backgroundColorContent = this.backgroundColorContent == 'transparent' ? 'rgb(0, 122, 255)' : 'transparent'
this.$page.setPageStyle({
backgroundColorContent: this.backgroundColorContent
})
},
back() { back() {
uni.navigateBack() uni.navigateBack()
} }
......
...@@ -48,6 +48,18 @@ describe('dialog page', () => { ...@@ -48,6 +48,18 @@ describe('dialog page', () => {
expect(lifecycleNum).toBe(7) expect(lifecycleNum).toBe(7)
await page.callMethod('setLifeCycleNum', 0) await page.callMethod('setLifeCycleNum', 0)
}); });
it('check dialogPage methods', async () => {
expect(await page.callMethod('dialogPageCheckGetDialogPages')).toBe(true)
let dialogPageStyle = await page.callMethod('dialogPageGetPageStyle')
expect(dialogPageStyle.backgroundColorContent).not.toBe('red')
await page.callMethod('dialogPageSetPageStyle')
dialogPageStyle = await page.callMethod('dialogPageGetPageStyle')
expect(dialogPageStyle.backgroundColorContent).toBe('red')
expect(await page.callMethod('dialogPageCheckGetElementById')).toBe(true)
expect(await page.callMethod('dialogCheckGetAndroidView')).toBe(isAndroid)
expect(await page.callMethod('dialogCheckGetIOSView')).toBe(false)
expect(await page.callMethod('dialogCheckGetHTMLElement')).toBe(isWeb)
})
it('closeDialogPage', async () => { it('closeDialogPage', async () => {
await page.callMethod('closeDialog'); await page.callMethod('closeDialog');
...@@ -289,11 +301,14 @@ describe('dialog page', () => { ...@@ -289,11 +301,14 @@ describe('dialog page', () => {
await page.callMethod('jest_getTapPoint') await page.callMethod('jest_getTapPoint')
const point_x = await page.data('jest_click_x'); const point_x = await page.data('jest_click_x');
const point_y = await page.data('jest_click_y'); const point_y = await page.data('jest_click_y');
if (isAndroid){ if (isAndroid) {
await program.adbCommand("input tap" + " " + point_x + " " + point_y) await program.adbCommand("input tap" + " " + point_x + " " + point_y)
console.log("input tap" + " " + point_x + " " + point_y); console.log("input tap" + " " + point_x + " " + point_y);
} else { } else {
await program.tap({x: point_x, y: point_y}) await program.tap({
x: point_x,
y: point_y
})
} }
await page.waitFor(1000); await page.waitFor(1000);
......
...@@ -177,18 +177,18 @@ ...@@ -177,18 +177,18 @@
getLifeCycleNum(): number { getLifeCycleNum(): number {
return state.lifeCycleNum return state.lifeCycleNum
}, },
jest_OpenDialog1(){ jest_OpenDialog1() {
uni.openDialogPage({ uni.openDialogPage({
url: '/pages/API/dialog-page/dialog-1?name=dialog1' url: '/pages/API/dialog-page/dialog-1?name=dialog1'
}) })
}, },
jest_CloseDialog1(){ jest_CloseDialog1() {
uni.closeDialogPage({}) uni.closeDialogPage({})
}, },
jest_getTapPoint(){ jest_getTapPoint() {
const systemInfo = uni.getSystemInfoSync() const systemInfo = uni.getSystemInfoSync()
let ratio = 1 let ratio = 1
if (systemInfo.platform == 'android'){ if (systemInfo.platform == 'android') {
ratio = systemInfo.devicePixelRatio ratio = systemInfo.devicePixelRatio
} }
this.jest_click_x = systemInfo.screenWidth / 2 * ratio this.jest_click_x = systemInfo.screenWidth / 2 * ratio
...@@ -202,10 +202,61 @@ ...@@ -202,10 +202,61 @@
closeDialog2ForTest() { closeDialog2ForTest() {
uni.closeDialogPage({}); uni.closeDialogPage({});
}, },
setPageStyleForTest(style : UTSJSONObject) { setPageStyleForTest(style: UTSJSONObject) {
const pages = this.$page.getDialogPages(); const pages = this.$page.getDialogPages();
if (pages.length > 0) pages[pages.length - 1].setPageStyle(style); if (pages.length > 0) pages[pages.length - 1].setPageStyle(style);
},
getDialogPage(): UniPage | null {
const dialogPages = this.$page.getDialogPages()
return dialogPages.length > 0 ? dialogPages[0] : null
},
dialogPageCheckGetDialogPages(): boolean {
const dialogPage = this.getDialogPage() !
const dialogPages = dialogPage.getDialogPages()
const res = dialogPages.length == 0
return res
},
dialogPageGetPageStyle(): UTSJSONObject {
const dialogPage = this.getDialogPage() !
return dialogPage.getPageStyle()
},
dialogPageSetPageStyle() {
const dialogPage = this.getDialogPage() !
dialogPage.setPageStyle({
backgroundColorContent: 'red'
})
},
dialogPageCheckGetElementById(): boolean {
const dialogPage = this.getDialogPage() !
const element = dialogPage.getElementById('dialog1-go-next-page')
let res = element != null
// #ifndef APP-ANDROID
if (res) {
const elPage = element!.getPage()
console.log('elPage', elPage)
res = elPage === dialogPage
} }
// #endif
return res
},
dialogCheckGetAndroidView(): boolean {
const dialogPage = this.getDialogPage() !
const androidView = dialogPage.getAndroidView()
const res = androidView != null
return res
},
dialogCheckGetIOSView(): boolean {
const dialogPage = this.getDialogPage() !
const IOSView = dialogPage.getIOSView()
const res = IOSView != null
return res
},
dialogCheckGetHTMLElement(): boolean {
const dialogPage = this.getDialogPage() !
const HTMLView = dialogPage.getHTMLElement()
const res = HTMLView != null
return res
},
} }
} }
</script> </script>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册