提交 d71e2508 编写于 作者: H hdx

feat(pageStyle): 新增示例及自动化测试

上级 15b9ab2c
...@@ -361,7 +361,8 @@ ...@@ -361,7 +361,8 @@
{ {
"path": "pages/API/get-current-pages/get-current-pages", "path": "pages/API/get-current-pages/get-current-pages",
"style": { "style": {
"navigationBarTitleText": "getCurrentPages" "navigationBarTitleText": "getCurrentPages",
"enablePullDownRefresh": true
} }
}, },
{ {
......
const HOME_PAGE_PATH = '/pages/tabBar/component' const HOME_PAGE_PATH = '/pages/tabBar/component'
const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages' const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages'
describe('getCurrentPages', () => { describe('getCurrentPages', () => {
let page let page
it('getCurrentPages', async () => { it('getCurrentPages', async () => {
// web 端等待应用首页加载完成 // web 端等待应用首页加载完成
if (process.env.uniTestPlatformInfo.startsWith('web')) { if (process.env.uniTestPlatformInfo.startsWith('web')) {
const waitTime = process.env.uniTestPlatformInfo.includes('safari') const waitTime = process.env.uniTestPlatformInfo.includes('safari') ?
? 5000 5000 :
: 1000 1000
await new Promise((resolve) => { await new Promise((resolve) => {
setTimeout(() => { setTimeout(() => {
resolve() resolve()
}, waitTime) }, waitTime)
}) })
} }
page = await program.switchTab(HOME_PAGE_PATH) page = await program.switchTab(HOME_PAGE_PATH)
await page.waitFor(1000) await page.waitFor(1000)
page = await program.navigateTo(PAGE_PATH) page = await program.navigateTo(PAGE_PATH)
await page.waitFor(1000) await page.waitFor(1000)
await page.callMethod('_getCurrentPages') await page.callMethod('_getCurrentPages')
await page.waitFor(200) await page.waitFor(200)
const data = await page.data() const data = await page.data()
expect(data.checked).toBe(true) expect(data.checked).toBe(true)
}) })
it('getPageStyle', async () => {
await changeData(page)
const btn = await page.$('.btn-get-page-style')
await btn.tap()
await page.waitFor(100)
const {
currentPageStyle
} = await page.data()
expect(currentPageStyle['enablePullDownRefresh']).toBe(true)
})
it('setPageStyle', async () => {
await changeData(page)
const btn = await page.$('.btn-set-page-style-0')
await btn.tap()
await page.waitFor(100)
const {
currentPageStyle
} = await page.data()
expect(currentPageStyle['enablePullDownRefresh']).toBe(false)
})
}) })
<template> <template>
<page-head title="getCurrentPages"></page-head> <page-head title="getCurrentPages"></page-head>
<view class="uni-padding-wrap"> <view class="uni-padding-wrap">
<button @click="_getCurrentPages">getCurrentPages</button> <button @click="_getCurrentPages">getCurrentPages</button>
<view v-if="pages.length" style="padding: 15px 0px"> <view v-if="pages.length" style="padding: 15px 0px">
<text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text> <text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
<template v-for="(page, index) in pages" :key="page.route"> <template v-for="(page, index) in pages" :key="page.route">
<text style="margin-top: 5px">index: {{ index }}, route: {{ page.route }}</text> <text style="margin-top: 5px">index: {{ index }}, route: {{ page.route }}</text>
</template> </template>
</view> </view>
</view> <button class="btn btn-get-page-style" type="primary" @click="getPageStyle">getPageStyle</button>
</template> <button class="btn btn-set-page-style-1" type="default" @click="setPageStyle(true)">setPageStyle(true)</button>
<button class="btn btn-set-page-style-0" type="default" @click="setPageStyle(false)">setPageStyle(false)</button>
<script> <textarea class="textarea" :value="pageStyleText" :maxlength="-1" :auto-height="true"></textarea>
class Page { <text class="tips">
constructor(public route : string) { 当前版本仅支持设置属性 enablePullDownRefresh
} </text>
} </view>
</template>
export default {
data() { <script>
return { class Page {
checked: false, constructor(public route : string) {
pages: [] as Page[], }
} }
},
methods: { export default {
_getCurrentPages: function () { data() {
this.pages.length = 0 return {
const pages = getCurrentPages() checked: false,
this.pages.push(new Page(pages[0].route)) pages: [] as Page[],
if (this.pages[0].route.includes('/tabBar/')) { currentPageStyle: {} as UTSJSONObject
this.checked = true }
} },
for (let i = 1; i < pages.length; i++) { computed: {
this.pages.push(new Page(pages[i].route)) pageStyleText() : string {
if (pages[i].route.includes('/tabBar/')) { return JSON.stringify(this.currentPageStyle)
this.checked = false }
} },
} onPullDownRefresh() {
}, setTimeout(() => {
}, uni.stopPullDownRefresh()
} }, 3000)
</script> },
methods: {
_getCurrentPages: function () {
this.pages.length = 0
const pages = getCurrentPages()
this.pages.push(new Page(pages[0].route))
if (this.pages[0].route.includes('/tabBar/')) {
this.checked = true
}
for (let i = 1; i < pages.length; i++) {
this.pages.push(new Page(pages[i].route))
if (pages[i].route.includes('/tabBar/')) {
this.checked = false
}
}
},
getPageStyle() {
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
this.currentPageStyle = currentPage.$getPageStyle();
},
setPageStyle(epr : boolean) {
// 目前仅支持 enablePullDownRefresh
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
currentPage.$setPageStyle({
enablePullDownRefresh: epr
});
},
// getCurrentPage(): Page {
// const pages = getCurrentPages();
// const currentPage = pages[pages.length - 1];
// return currentPage;
// }
},
}
</script>
<style>
.btn {
margin-top: 10px;
}
.textarea {
margin-top: 5px;
padding: 5px;
background-color: #fff;
}
.tips {
font-size: 12px;
margin-top: 10px;
opacity: .8;
}
</style>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册