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

refactor: 兼容 web 端

上级 3e119088
......@@ -14,8 +14,8 @@
},
null: null as string | null,
arr: [] as number[],
set: new Set<string>(),
map: new Map<string, any>(),
mySet: new Set<string>(),
myMap: new Map<string, any>(),
func: (): string => {
return 'globalData func'
}
......
......@@ -8,7 +8,7 @@ describe('getApp', () => {
})
it('globalData', async () => {
await page.callMethod('getGlobalData')
let data = await page.data()
let data = await page.data()
expect(data.originGlobalData.str).toBe('default globalData str')
expect(data.originGlobalData.num).toBe(0)
expect(data.originGlobalData.bool).toBe(false)
......@@ -19,11 +19,11 @@ describe('getApp', () => {
})
expect(data.originGlobalData.arr).toEqual([])
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(data.originGlobalData.set).toEqual([])
expect(data.originGlobalData.mySet).toEqual([])
} else {
expect(data.originGlobalData.set).toEqual({})
expect(data.originGlobalData.mySet).toEqual({})
}
expect(data.originGlobalData.map).toEqual({})
expect(data.originGlobalData.myMap).toEqual({})
expect(data.originGlobalDataFuncRes).toBe('globalData func')
await page.callMethod('setGlobalData')
data = await page.data()
......@@ -37,18 +37,18 @@ describe('getApp', () => {
})
expect(data.newGlobalData.arr).toEqual([1, 2, 3])
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(data.newGlobalData.set).toEqual(['a', 'b', 'c'])
expect(data.newGlobalData.mySet).toEqual(['a', 'b', 'c'])
} else {
expect(data.originGlobalData.set).toEqual({})
expect(data.originGlobalData.mySet).toEqual({})
}
if (process.env.uniTestPlatformInfo.startsWith('android')) {
expect(data.newGlobalData.map).toEqual({
expect(data.newGlobalData.myMap).toEqual({
'a': 1,
'b': 2,
'c': 3
})
} else {
expect(data.originGlobalData.map).toEqual({})
expect(data.originGlobalData.myMap).toEqual({})
}
expect(data.newGlobalDataFuncRes).toBe('new globalData func')
})
......@@ -59,4 +59,4 @@ describe('getApp', () => {
expect(newLifeCycleNum - oldLifeCycleNum).toBe(100)
await page.callMethod('setLifeCycleNum', oldLifeCycleNum)
})
})
\ No newline at end of file
})
......@@ -14,11 +14,11 @@
<text class="uni-common-mt">globalData object: {{ originGlobalData.obj }}</text>
<text class="uni-common-mt">globalData null: {{ originGlobalData.null }}</text>
<text class="uni-common-mt">globalData array: {{ originGlobalData.arr }}</text>
<text class="uni-common-mt">globalData Set: {{ originGlobalData.set }}</text>
<text class="uni-common-mt">globalData Map: {{ originGlobalData.map }}</text>
<text class="uni-common-mt">globalData Set: {{ originGlobalData.mySet }}</text>
<text class="uni-common-mt">globalData Map: {{ originGlobalData.myMap }}</text>
<text class="uni-common-mt">globalData func 返回值: {{ originGlobalDataFuncRes }}</text>
</template>
<button @click="setGlobalData" class="uni-common-mt">set globalData</button>
<button @click="setGlobalData" class="uni-common-mt">mySet globalData</button>
<template v-if="newGlobalData.bool">
<text class="uni-common-mt bold">更新后的 globalData:</text>
<text class="uni-common-mt">globalData string: {{ newGlobalData.str }}</text>
......@@ -27,8 +27,8 @@
<text class="uni-common-mt">globalData object: {{ newGlobalData.obj }}</text>
<text class="uni-common-mt">globalData null: {{ newGlobalData.null }}</text>
<text class="uni-common-mt">globalData array: {{ newGlobalData.arr }}</text>
<text class="uni-common-mt">globalData Set: {{ newGlobalData.set }}</text>
<text class="uni-common-mt">globalData Map: {{ newGlobalData.map }}</text>
<text class="uni-common-mt">globalData Set: {{ newGlobalData.mySet }}</text>
<text class="uni-common-mt">globalData Map: {{ newGlobalData.myMap }}</text>
<text class="uni-common-mt">globalData func 返回值: {{ newGlobalDataFuncRes }}</text>
</template>
<view class="uni-common-mt hr"></view>
......@@ -53,8 +53,8 @@
obj : UTSJSONObject,
null : string | null,
arr : number[],
set : Set<string>,
map : Map<string, any>,
mySet : Set<string>,
myMap : Map<string, any>,
func : () => string
}
import { state, setLifeCycleNum } from '@/store/index.uts'
......@@ -73,8 +73,8 @@
} as UTSJSONObject,
null: null,
arr: [] as number[],
set: new Set<string>(),
map: new Map<string, any>(),
mySet: new Set<string>(),
myMap: new Map<string, any>(),
func: () : string => ''
} as MyGlobalData,
originGlobalDataFuncRes: '',
......@@ -89,8 +89,8 @@
} as UTSJSONObject,
null: null,
arr: [] as number[],
set: new Set<string>(),
map: new Map<string, any>(),
mySet: new Set<string>(),
myMap: new Map<string, any>(),
func: () : string => ''
} as MyGlobalData,
newGlobalDataFuncRes: '',
......@@ -109,8 +109,8 @@
this.originGlobalData.obj = app.globalData.obj
this.originGlobalData.null = app.globalData.null
this.originGlobalData.arr = app.globalData.arr
this.originGlobalData.set = app.globalData.set
this.originGlobalData.map = app.globalData.map
this.originGlobalData.mySet = app.globalData.mySet
this.originGlobalData.myMap = app.globalData.myMap
this.originGlobalData.func = app.globalData.func
this.originGlobalDataFuncRes = this.originGlobalData.func()
},
......@@ -127,8 +127,8 @@
}
app.globalData.null = 'not null'
app.globalData.arr = [1, 2, 3]
app.globalData.set = new Set(['a', 'b', 'c'])
app.globalData.map = new Map([
app.globalData.mySet = new Set(['a', 'b', 'c'])
app.globalData.myMap = new Map([
['a', 1],
['b', 2],
['c', 3]
......@@ -143,8 +143,8 @@
this.newGlobalData.obj = app.globalData.obj
this.newGlobalData.null = app.globalData.null
this.newGlobalData.arr = app.globalData.arr
this.newGlobalData.set = app.globalData.set
this.newGlobalData.map = app.globalData.map
this.newGlobalData.mySet = app.globalData.mySet
this.newGlobalData.myMap = app.globalData.myMap
this.newGlobalData.func = app.globalData.func
this.newGlobalDataFuncRes = this.newGlobalData.func()
},
......
......@@ -4,6 +4,17 @@ 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)
......
......@@ -24,7 +24,7 @@ export default {
getLaunchOptionsSync() {
const launchOptions = uni.getLaunchOptionsSync()
this.launchOptionsPath = launchOptions.path
if (launchOptions.path == this.homePagePath) {
if (launchOptions.path === this.homePagePath || `/${launchOptions.path}` === this.homePagePath) {
this.checked = true
}
},
......
......@@ -37,7 +37,7 @@
uni.loadFontFace({
global: true,
family: 'UniFontFamily',
source: '/static/font/uni.ttf',
source: "url('/static/font/uni.ttf')",
success() {
console.log('global loadFontFace uni.ttf success')
},
......@@ -48,7 +48,7 @@
uni.loadFontFace({
family: 'AlimamaDaoLiTiTTF',
source:
'https://native-res.dcloud.net.cn/uni-app-x/static/font/AlimamaDaoLiTi.ttf',
"url('https://native-res.dcloud.net.cn/uni-app-x/static/font/AlimamaDaoLiTi.ttf')",
success() {
console.log('loadFontFace Remote AlimamaDaoLiTi.ttf success')
},
......@@ -58,7 +58,7 @@
})
uni.loadFontFace({
family: 'AlimamaDaoLiTiOTF',
source: '/static/font/AlimamaDaoLiTi.otf',
source: "url('/static/font/AlimamaDaoLiTi.otf')",
success() {
console.log('loadFontFace AlimamaDaoLiTi.otf success')
},
......@@ -68,7 +68,7 @@
})
uni.loadFontFace({
family: 'AlimamaDaoLiTiWOFF',
source: '/static/font/AlimamaDaoLiTi.woff',
source: "url('/static/font/AlimamaDaoLiTi.woff')",
success() {
console.log('loadFontFace AlimamaDaoLiTi.woff success')
},
......@@ -78,7 +78,7 @@
})
uni.loadFontFace({
family: 'AlimamaDaoLiTiWOFF2',
source: '/static/font/AlimamaDaoLiTi.woff2',
source: "url('/static/font/AlimamaDaoLiTi.woff2')",
success() {
console.log('loadFontFace AlimamaDaoLiTi.woff2 success')
},
......@@ -105,4 +105,4 @@
.line-height-40 {
line-height: 40px;
}
</style>
\ No newline at end of file
</style>
......@@ -9,7 +9,7 @@ describe("onLoad", () => {
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
await page.waitFor('view');
await page.callMethod("navigateToOnLoadWithType", "adjustData");
await page.waitFor(100);
await page.waitFor(1000);
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
});
......@@ -17,17 +17,19 @@ describe("onLoad", () => {
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
await page.waitFor('view');
await page.callMethod("navigateToOnLoadWithType", "navigateTo");
await page.waitFor(100);
await page.waitFor(1000);
page = await program.currentPage();
expect(page.path).toBe(TARGET_PAGE_PATH.substring(1));
});
it("navigateBack", async () => {
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
await page.waitFor('view');
await page.callMethod("navigateToOnLoadWithType", "navigateBack");
page = await program.currentPage();
await page.waitFor('view');
expect(page.path).toBe(INTERMEDIATE_PAGE_PATH.substring(1));
if (process.env.uniTestPlatformInfo.startsWith('android')) {
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
await page.waitFor('view');
await page.callMethod("navigateToOnLoadWithType", "navigateBack");
await page.waitFor('view');
page = await program.currentPage();
expect(page.path).toBe(INTERMEDIATE_PAGE_PATH.substring(1));
}
});
it("redirectTo", async () => {
page = await program.reLaunch(INTERMEDIATE_PAGE_PATH);
......@@ -126,4 +128,4 @@ describe("onLoad", () => {
failureThresholdType: "percent",
});
});
});
});
<template>
<view class="uni-padding-wrap">
<page-head title="onLoad 生命周期调用 uni api 测试" />
<text v-if="isTrue">v-if with true</text>
<text v-if="isFalse">v-if with false</text>
<text v-show="isTrue">v-show with true</text>
<text v-show="isFalse">v-show with false</text>
<text>msg: {{ msg }}</text>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
isTrue: false,
isFalse: true,
msg: 'default msg'
}
},
onLoad(options: OnLoadOptions) {
const type = options.get('type')
switch (type) {
case 'adjustData':
this.adjustData()
break;
case 'navigateTo':
this.navigateTo()
break;
case 'navigateBack':
this.navigateBack()
break;
case 'redirectTo':
this.redirectTo()
break;
case 'reLaunch':
this.reLaunch()
break;
case 'switchTab':
this.switchTab()
break;
case 'showToast':
this.showToast()
break;
case 'showLoading':
this.showLoading()
break;
case 'showModal':
this.showModal()
break;
case 'showActionSheet':
this.showActionSheet()
break;
}
},
methods: {
adjustData(){
this.isTrue = true
this.isFalse = false
this.msg = 'new msg'
},
navigateTo(){
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page-3'
})
},
navigateBack(){
uni.navigateBack()
},
redirectTo(){
uni.redirectTo({
url: '/pages/API/navigator/new-page/new-page-3'
})
},
reLaunch(){
uni.reLaunch({
url: '/pages/API/navigator/new-page/new-page-3'
})
},
switchTab(){
uni.switchTab({
url: '/pages/tabBar/component'
})
},
showToast(){
uni.showToast({
title: 'test title',
icon: 'success',
duration: 2000
})
},
showLoading(){
uni.showLoading({
title: 'test title',
})
},
showModal(){
uni.showModal({
title: 'test title',
content: 'test content',
})
},
showActionSheet(){
uni.showActionSheet({
title: 'test title',
itemList: ['1', '2', '3']
})
}
}
}
</script>
<template>
<view class="uni-padding-wrap">
<page-head title="onLoad 生命周期调用 uni api 测试" />
<text v-if="isTrue">v-if with true</text>
<text v-if="isFalse">v-if with false</text>
<text v-show="isTrue">v-show with true</text>
<text v-show="isFalse">v-show with false</text>
<text>msg: {{ msg }}</text>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
isTrue: false,
isFalse: true,
msg: 'default msg'
}
},
onLoad(options : OnLoadOptions) {
const type = options['type']
switch (type) {
case 'adjustData':
this.adjustData()
break;
case 'navigateTo':
this.navigateTo()
break;
case 'navigateBack':
this.navigateBack()
break;
case 'redirectTo':
this.redirectTo()
break;
case 'reLaunch':
this.reLaunch()
break;
case 'switchTab':
this.switchTab()
break;
case 'showToast':
this.showToast()
break;
case 'showLoading':
this.showLoading()
break;
case 'showModal':
this.showModal()
break;
case 'showActionSheet':
this.showActionSheet()
break;
}
},
// #ifdef WEB
onUnload() {
// web 端页面销毁前,关闭 modal 和 actionsheet
const modalBtn = document.querySelector('.uni-modal__btn')
if (modalBtn) {
modalBtn.click()
}
const actionSheetBtn = document.querySelector('.uni-actionsheet__action .uni-actionsheet__cell')
if (actionSheetBtn) {
actionSheetBtn.click()
}
},
// #endif
methods: {
adjustData() {
this.isTrue = true
this.isFalse = false
this.msg = 'new msg'
},
navigateTo() {
uni.navigateTo({
url: '/pages/API/navigator/new-page/new-page-3'
})
},
navigateBack() {
uni.navigateBack()
},
redirectTo() {
uni.redirectTo({
url: '/pages/API/navigator/new-page/new-page-3'
})
},
reLaunch() {
uni.reLaunch({
url: '/pages/API/navigator/new-page/new-page-3'
})
},
switchTab() {
uni.switchTab({
url: '/pages/tabBar/component'
})
},
showToast() {
uni.showToast({
title: 'test title',
icon: 'success',
duration: 2000
})
},
showLoading() {
uni.showLoading({
title: 'test title',
})
},
showModal() {
uni.showModal({
title: 'test title',
content: 'test content'
})
},
showActionSheet() {
uni.showActionSheet({
title: 'test title',
itemList: ['1', '2', '3']
})
}
}
}
</script>
......@@ -76,7 +76,12 @@ export default {
this.validateGeneralAttrText = '基础属性 id 验证失败'
return
}
// #ifdef APP-ANDROID
if (!generalTarget.classList.includes('general-class')) {
// #endif
// #ifdef WEB
if (!Array.from(generalTarget.classList).includes('general-class')) {
// #endif
this.validateGeneralAttrText = '基础属性 class 验证失败'
return
}
......
const PAGE_PATH = '/pages/component/general-event/general-event'
describe('event trigger sequence', () => {
let page
let el
beforeAll(async () => {
page = await program.navigateTo(PAGE_PATH)
await page.waitFor('view')
el = await page.$('.target')
})
it('touch', async () => {
await el.touchstart({
touches: [
{
identifier: 1,
pageX: 100,
pageY: 100,
},
],
changedTouches: [
{
identifier: 1,
pageX: 100,
pageY: 100,
},
],
})
await el.touchmove({
touches: [
{
identifier: 1,
pageX: 100,
pageY: 100,
},
],
changedTouches: [
{
identifier: 1,
pageX: 101,
pageY: 101,
},
],
})
await el.touchend({
touches: [],
changedTouches: [
{
identifier: 1,
pageX: 101,
pageY: 101,
},
],
})
const data = await page.data()
expect(data.onTouchStartTime).toBeLessThanOrEqual(data.onTouchMoveTime);
expect(data.onTouchMoveTime).toBeLessThanOrEqual(data.onTouchEndTime);
})
it('click', async () => {
await el.tap()
const data = await page.data()
expect(data.onTapTime).toBeLessThanOrEqual(data.onClickTime)
})
it('longPress', async () => {
await el.longpress()
const data = await page.data()
expect(data.onLongPressTime).toBeGreaterThan(0)
})
const PAGE_PATH = '/pages/component/general-event/general-event'
describe('event trigger sequence', () => {
let page
let el
beforeAll(async () => {
page = await program.navigateTo(PAGE_PATH)
await page.waitFor('view')
el = await page.$('.target')
})
it('touch', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
await el.touchstart({
touches: [{
identifier: 1,
pageX: 100,
pageY: 100,
}, ],
changedTouches: [{
identifier: 1,
pageX: 100,
pageY: 100,
}, ],
})
await el.touchmove({
touches: [{
identifier: 1,
pageX: 100,
pageY: 100,
}, ],
changedTouches: [{
identifier: 1,
pageX: 101,
pageY: 101,
}, ],
})
await el.touchend({
touches: [],
changedTouches: [{
identifier: 1,
pageX: 101,
pageY: 101,
}, ],
})
const data = await page.data()
expect(data.onTouchStartTime).toBeLessThanOrEqual(data.onTouchMoveTime);
expect(data.onTouchMoveTime).toBeLessThanOrEqual(data.onTouchEndTime);
}
})
it('click', async () => {
await el.tap()
const data = await page.data()
expect(data.onTapTime).toBeLessThanOrEqual(data.onClickTime)
})
it('longPress', async () => {
if (process.env.uniTestPlatformInfo.startsWith('android')) {
await el.longpress()
const data = await page.data()
expect(data.onLongPressTime).toBeGreaterThan(0)
}
})
})
......@@ -153,7 +153,13 @@
{
name: 'element元素',
url: 'get-element-by-id',
api: ["getElementById"]
api: ["getElementById"],
// #ifdef APP-ANDROID
enable: true,
// #endif
// #ifndef APP-ANDROID
enable: false,
// #endif
},
{
name: 'element draw',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册