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

refactor: 处理小程序兼容问题

上级 70b54085
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
isWeixin = platformInfo == 'mp-weixin' const isMP = platformInfo.startsWith('mp')
describe('dialog page', () => { describe('dialog page', () => {
if (process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') { if (process.env.UNI_AUTOMATOR_APP_WEBVIEW == 'true') {
...@@ -8,8 +8,8 @@ describe('dialog page', () => { ...@@ -8,8 +8,8 @@ describe('dialog page', () => {
}) })
return return
} }
if (isWeixin) { if (isMP) {
it('skip app-webview', () => { it('skip mp', () => {
expect(1).toBe(1) expect(1).toBe(1)
}) })
return return
......
...@@ -3,6 +3,7 @@ jest.setTimeout(20000) ...@@ -3,6 +3,7 @@ jest.setTimeout(20000)
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isWeb = platformInfo.startsWith('web') const isWeb = platformInfo.startsWith('web')
const isAndroid = platformInfo.startsWith('android') const isAndroid = platformInfo.startsWith('android')
const isMP = platformInfo.startsWith('mp')
const FIRST_PAGE_PATH = '/pages/API/dialog-page/dialog-page' const FIRST_PAGE_PATH = '/pages/API/dialog-page/dialog-page'
const NEXT_PAGE_PATH = '/pages/API/dialog-page/next-page' const NEXT_PAGE_PATH = '/pages/API/dialog-page/next-page'
...@@ -13,6 +14,12 @@ describe('dialog page', () => { ...@@ -13,6 +14,12 @@ describe('dialog page', () => {
}) })
return return
} }
if (isMP) {
it('skip mp', () => {
expect(1).toBe(1)
})
return
}
let page; let page;
let initLifeCycleNum; let initLifeCycleNum;
...@@ -51,7 +58,7 @@ describe('dialog page', () => { ...@@ -51,7 +58,7 @@ describe('dialog page', () => {
it('check dialogPage methods', async () => { it('check dialogPage methods', async () => {
expect(await page.callMethod('dialogPageCheckGetDialogPages')).toBe(true) expect(await page.callMethod('dialogPageCheckGetDialogPages')).toBe(true)
let dialogPageStyle = await page.callMethod('dialogPageGetPageStyle') let dialogPageStyle = await page.callMethod('dialogPageGetPageStyle')
expect(dialogPageStyle.backgroundColorContent).not.toBe('red') expect(dialogPageStyle.backgroundColorContent).not.toBe('red')
await page.callMethod('dialogPageSetPageStyle') await page.callMethod('dialogPageSetPageStyle')
dialogPageStyle = await page.callMethod('dialogPageGetPageStyle') dialogPageStyle = await page.callMethod('dialogPageGetPageStyle')
expect(dialogPageStyle.backgroundColorContent).toBe('red') expect(dialogPageStyle.backgroundColorContent).toBe('red')
......
const PAGE_PATH = '/pages/API/get-app/get-app' const PAGE_PATH = '/pages/API/get-app/get-app'
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase() const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android') const isAndroid = platformInfo.startsWith('android')
const isMP = platformInfo.startsWith('mp')
describe('getApp', () => { describe('getApp', () => {
let page = null let page = null
...@@ -49,8 +50,10 @@ describe('getApp', () => { ...@@ -49,8 +50,10 @@ describe('getApp', () => {
expect(newLifeCycleNum - oldLifeCycleNum).toBe(100) expect(newLifeCycleNum - oldLifeCycleNum).toBe(100)
await page.callMethod('setLifeCycleNum', oldLifeCycleNum) await page.callMethod('setLifeCycleNum', oldLifeCycleNum)
}) })
it('getAndroidApplication', async () => { if (!isMP) {
const res = await page.callMethod('getAndroidApplication') it('getAndroidApplication', async () => {
expect(res).toBe(isAndroid) const res = await page.callMethod('getAndroidApplication')
}) expect(res).toBe(isAndroid)
})
}
}) })
...@@ -38,11 +38,13 @@ ...@@ -38,11 +38,13 @@
<button class="uni-common-mt" @click="_increasetLifeCycleNum"> <button class="uni-common-mt" @click="_increasetLifeCycleNum">
increase lifeCycleNum increase lifeCycleNum
</button> </button>
<text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text> <text class="uni-common-mt">lifeCycleNum: {{ lifeCycleNum }}</text>
<!-- #ifndef MP -->
<button class="uni-common-mt" @click="getAndroidApplication"> <button class="uni-common-mt" @click="getAndroidApplication">
getAndroidApplication getAndroidApplication
</button> </button>
<text class="uni-common-mt">androidApplication is null: {{ androidApplication == null }}</text> <text class="uni-common-mt">androidApplication is null: {{ androidApplication == null }}</text>
<!-- #endif -->
</view> </view>
</view> </view>
<!-- #ifdef APP --> <!-- #ifdef APP -->
...@@ -172,12 +174,14 @@ ...@@ -172,12 +174,14 @@
// 自动化测试 // 自动化测试
setLifeCycleNum(num : number) { setLifeCycleNum(num : number) {
setLifeCycleNum(num) setLifeCycleNum(num)
}, },
// #ifndef MP
getAndroidApplication() : boolean { getAndroidApplication() : boolean {
const app = getApp() const app = getApp()
this.androidApplication = app.getAndroidApplication() this.androidApplication = app.getAndroidApplication()
return this.androidApplication !== null return this.androidApplication !== null
} }
// #endif
}, },
} }
</script> </script>
......
...@@ -93,12 +93,12 @@ ...@@ -93,12 +93,12 @@
} }
}, },
onLoad(options : OnLoadOptions) { onLoad(options : OnLoadOptions) {
// #ifndef APP-ANDROID // #ifdef APP-IOS || WEB
if (options instanceof UTSJSONObject) { if (options instanceof UTSJSONObject) {
this.checked = true this.checked = true
} }
// #endif // #endif
// #ifdef APP-ANDROID // #ifndef APP-IOS || WEB
this.checked = true this.checked = true
// #endif // #endif
this.getPageStyle(); this.getPageStyle();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册