提交 e5380be0 编写于 作者: H hdx

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

上级 9ef50c49
......@@ -361,7 +361,8 @@
{
"path": "pages/API/get-current-pages/get-current-pages",
"style": {
"navigationBarTitleText": "getCurrentPages"
"navigationBarTitleText": "getCurrentPages",
"enablePullDownRefresh": true
}
},
{
......
const HOME_PAGE_PATH = '/pages/tabBar/component'
const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages'
describe('getCurrentPages', () => {
let page
it('getCurrentPages', async () => {
// web 端等待应用首页加载完成
if (process.env.uniTestPlatformInfo.startsWith('web')) {
const waitTime = process.env.uniTestPlatformInfo.includes('safari')
? 5000
: 1000
await new Promise((resolve) => {
setTimeout(() => {
resolve()
}, waitTime)
})
}
page = await program.switchTab(HOME_PAGE_PATH)
await page.waitFor(1000)
page = await program.navigateTo(PAGE_PATH)
await page.waitFor(1000)
await page.callMethod('_getCurrentPages')
await page.waitFor(200)
const data = await page.data()
expect(data.checked).toBe(true)
})
const HOME_PAGE_PATH = '/pages/tabBar/component'
const PAGE_PATH = '/pages/API/get-current-pages/get-current-pages'
describe('getCurrentPages', () => {
let page
it('getCurrentPages', async () => {
// web 端等待应用首页加载完成
if (process.env.uniTestPlatformInfo.startsWith('web')) {
const waitTime = process.env.uniTestPlatformInfo.includes('safari') ?
5000 :
1000
await new Promise((resolve) => {
setTimeout(() => {
resolve()
}, waitTime)
})
}
page = await program.switchTab(HOME_PAGE_PATH)
await page.waitFor(1000)
page = await program.navigateTo(PAGE_PATH)
await page.waitFor(1000)
await page.callMethod('_getCurrentPages')
await page.waitFor(200)
const data = await page.data()
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>
<page-head title="getCurrentPages"></page-head>
<view class="uni-padding-wrap">
<button @click="_getCurrentPages">getCurrentPages</button>
<view v-if="pages.length" style="padding: 15px 0px">
<text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
<template v-for="(page, index) in pages" :key="page.route">
<text style="margin-top: 5px">index: {{ index }}, route: {{ page.route }}</text>
</template>
</view>
</view>
</template>
<script>
class Page {
constructor(public route : string) {
}
}
export default {
data() {
return {
checked: false,
pages: [] as Page[],
}
},
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
}
}
},
},
}
</script>
<template>
<page-head title="getCurrentPages"></page-head>
<view class="uni-padding-wrap">
<button @click="_getCurrentPages">getCurrentPages</button>
<view v-if="pages.length" style="padding: 15px 0px">
<text>当前页面栈中 {{ pages.length }} 个页面,列表如下:</text>
<template v-for="(page, index) in pages" :key="page.route">
<text style="margin-top: 5px">index: {{ index }}, route: {{ page.route }}</text>
</template>
</view>
<button class="btn btn-get-page-style" type="primary" @click="getPageStyle">getPageStyle</button>
<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>
<textarea class="textarea" :value="pageStyleText" :maxlength="-1" :auto-height="true"></textarea>
<text class="tips">
当前版本仅支持设置属性 enablePullDownRefresh
</text>
</view>
</template>
<script>
class Page {
constructor(public route : string) {
}
}
export default {
data() {
return {
checked: false,
pages: [] as Page[],
currentPageStyle: {} as UTSJSONObject
}
},
computed: {
pageStyleText() : string {
return JSON.stringify(this.currentPageStyle)
}
},
onPullDownRefresh() {
setTimeout(() => {
uni.stopPullDownRefresh()
}, 3000)
},
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.
先完成此消息的编辑!
想要评论请 注册