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

refactor: 重构 built in 目录并修复测试

上级 d4632f07
......@@ -122,19 +122,6 @@
}
},
// #endif
{
"path": "pages/built-in/component/keep-alive/keep-alive-options",
"style": {
"navigationBarTitleText": "keep-alive 选项式 API"
}
},
{
"path": "pages/built-in/component/keep-alive/keep-alive-composition",
"style": {
"navigationBarTitleText": "keep-alive 组合式 API"
}
},
{
"path": "pages/directive/v-html/v-html-options",
"style": {
......@@ -655,58 +642,84 @@
"enablePullDownRefresh": true
}
},
{
"path": "pages/built-in/component/keep-alive/keep-alive-options",
"style": {
"navigationBarTitleText": "keep-alive 选项式 API"
}
},
{
"path": "pages/built-in/component/keep-alive/keep-alive-composition",
"style": {
"navigationBarTitleText": "keep-alive 组合式 API"
}
},
{
"path": "pages/built-in/component/teleport/teleport-options",
"style": {
"navigationBarTitleText": "teleport 选项式 API",
"enablePullDownRefresh": false
}
},
{
"path": "pages/built-in/component/teleport/teleport-composition",
"style": {
"navigationBarTitleText": "teleport 组合式 API",
"enablePullDownRefresh": false
}
},
{
"path": "pages/built-in/component/slots/slots-composition",
"path": "pages/built-in/special-elements/slots/slots-composition",
"style": {
"navigationBarTitleText": "slots 组合式 API"
}
},
{
"path": "pages/built-in/component/slots/slots-options",
"path": "pages/built-in/special-elements/slots/slots-options",
"style": {
"navigationBarTitleText": "slots 选项式 API"
}
},
{
"path": "pages/built-in/component/template/template-options",
"path": "pages/built-in/special-elements/template/template-options",
"style": {
"navigationBarTitleText": "template 选项式 API"
}
},
{
"path": "pages/built-in/component/template/template-composition",
"path": "pages/built-in/special-elements/template/template-composition",
"style": {
"navigationBarTitleText": "template 组合式 API"
}
},
{
"path": "pages/built-in/component/template/template-map-style-options",
"path": "pages/built-in/special-elements/template/template-map-style-options",
"style": {
"navigationBarTitleText": "template-map-style 选项式 API"
}
},
{
"path": "pages/built-in/component/template/template-map-style-composition",
"path": "pages/built-in/special-elements/template/template-map-style-composition",
"style": {
"navigationBarTitleText": "template-map-style 组合式 API"
}
},
{
"path": "pages/rendering/unrecognized-component/unrecognized-component",
"path": "pages/built-in/special-elements/component/component-options",
"style": {
"navigationBarTitleText": "unrecognized-component"
"navigationBarTitleText": "component 选项式 API"
}
},
{
"path": "pages/built-in/component/component/component-options",
"path": "pages/built-in/special-elements/component/component-composition",
"style": {
"navigationBarTitleText": "component 选项式 API"
"navigationBarTitleText": "component 组合式 API"
}
},
{
"path": "pages/built-in/component/component/component-composition",
"path": "pages/rendering/unrecognized-component/unrecognized-component",
"style": {
"navigationBarTitleText": "component 组合式 API"
"navigationBarTitleText": "unrecognized-component"
}
},
{
......@@ -739,20 +752,6 @@
"navigationBarTitleText": "自定义组件中使用 class 定制另一个自定义组件根节点样式 组合式 API"
}
},
{
"path": "pages/built-in/component/teleport/teleport-options",
"style": {
"navigationBarTitleText": "teleport 选项式 API",
"enablePullDownRefresh": false
}
},
{
"path": "pages/built-in/component/teleport/teleport-composition",
"style": {
"navigationBarTitleText": "teleport 组合式 API",
"enablePullDownRefresh": false
}
},
{
"path": "pages/type/type",
"style": {
......
const OPTIONS_PAGE_PATH = '/pages/app-instance/globalProperties/globalProperties-options'
const COMPOSITION_PAGE_PATH = '/pages/app-instance/globalProperties/globalProperties-composition'
const COMPOSITION_PAGE_PATH = '/pages/app-instance/globalProperties/globalProperties-composition'
describe('globalProperties', () => {
let page = null
const testGlobalProperties = async (page) => {
let data = await page.data()
await page.waitFor(1000)
let data = await page.data()
await page.waitFor(1000)
expect(data.myGlobalProperties.str).toBe('default string')
expect(data.myGlobalProperties.num).toBe(0)
expect(data.myGlobalProperties.bool).toBe(false)
......@@ -54,7 +54,7 @@ describe('globalProperties', () => {
const image = await program.screenshot({
fullPage: true
});
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}
it('globalProperties options API', async () => {
......@@ -68,7 +68,7 @@ describe('globalProperties', () => {
})
it('globalProperties composition API', async () => {
page = await program.reLaunch(COMPOSITION_PAGE_PATH)
page = await program.reLaunch(COMPOSITION_PAGE_PATH)
// 等待 globalProperties-options resetGlobalProperties 完成
await page.waitFor(1500)
......
const PAGE_PATH_OPTIONS = '/pages/built-in-component/keep-alive/keep-alive-options'
const PAGE_PATH_COMPOSITION = '/pages/built-in-component/keep-alive/keep-alive-composition'
const PAGE_PATH_OPTIONS = '/pages/built-in/component/keep-alive/keep-alive-options'
const PAGE_PATH_COMPOSITION = '/pages/built-in/component/keep-alive/keep-alive-composition'
describe('keep-alive', () => {
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
......
const PAGE_PATH_OPTIONS = '/pages/built-in-component/teleport/teleport-options'
const PAGE_PATH_COMPONSITION = '/pages/built-in-component/teleport/teleport-composition'
const PAGE_PATH_OPTIONS = '/pages/built-in/component/teleport/teleport-options'
const PAGE_PATH_COMPONSITION = '/pages/built-in/component/teleport/teleport-composition'
describe('teleport', () => {
if (process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')) {
......@@ -14,7 +14,7 @@ describe('teleport', () => {
await page.waitFor('view')
await page.waitFor(500)
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
expect(image).toSaveImageSnapshot();
}
it('teleport Options API', async () => {
page = await program.reLaunch(PAGE_PATH_OPTIONS)
......
describe('/pages/rendering/template/template-map-style', () => {
let page
beforeAll(async () => {
page = await program.reLaunch('/pages/rendering/template/template-map-style')
await page.waitFor(1000)
})
it('init screen shot', async () => {
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
})
it('change isClassValid screen shot', async () => {
const btn = await page.$('#btn')
await btn.tap()
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
})
});
\ No newline at end of file
const PAGE_OPTIONS = '/pages/built-in/component/component/component-options'
const PAGE_COMPOSITION = '/pages/built-in/component/component/component-composition'
const PAGE_OPTIONS = '/pages/built-in/special-elements/component/component-options'
const PAGE_COMPOSITION = '/pages/built-in/special-elements/component/component-composition'
describe('built-in/component', () => {
let page
......
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
const PAGE_OPTIONS = '/pages/built-in/component/slots/slots-options'
const PAGE_COMPOSITION = '/pages/built-in/component/slots/slots-composition'
const PAGE_OPTIONS = '/pages/built-in/special-elements/slots/slots-options'
const PAGE_COMPOSITION = '/pages/built-in/special-elements/slots/slots-composition'
describe('built-in/component/slots', () => {
describe('built-in/special-elements/slots', () => {
let page;
const test = async () => {
......
<template>
<view class="page">
<template v-if="isShow">
<template v-if="dataInfo.isShow">
<view class="title">{{ title }}</view>
</template>
<view class="show-botton" @click="handleShow">{{ isShow ? '点击隐藏' : '点击显示' }}</view>
<view class="show-botton" @click="handleShow">{{ dataInfo.isShow ? '点击隐藏' : '点击显示' }}</view>
<template v-for="(item, index) in list" :key="index">
<view class="item">{{ index + 1 }}.{{ item.name }}</view>
</template>
......@@ -12,23 +12,16 @@
</template>
<script setup lang="uts">
type DataInfo = {
isShow: boolean
}
type ListItem = {
name: string
}
// 自动化测试拿不到 ref
defineOptions({
data() {
return {
isShow: false
}
},
methods: {
handleShow() {
this.isShow = !this.isShow
}
}
})
const dataInfo = reactive({
isShow: false
} as DataInfo)
const title = ref<string>('hello')
const list = ref<ListItem[]>([
......@@ -40,11 +33,16 @@ const list = ref<ListItem[]>([
}
] as ListItem[])
const handleShow = () => {
dataInfo.isShow = !dataInfo.isShow
}
const goMapStyle = () => {
uni.navigateTo({ url: '/pages/built-in/component/template/template-map-style-composition' })
}
defineExpose({
dataInfo,
goMapStyle
})
</script>
......
const OPTIONS_PAGE_PATH = '/pages/built-in/special-elements/template/template-map-style-options'
const COMPOSITION_PAGE_PATH = '/pages/built-in/special-elements/template/template-map-style-composition'
describe('/pages/built-in/special-elements/template-map-style', () => {
let page
const test = async (pagePath) => {
page = await program.reLaunch(pagePath)
await page.waitFor('view')
const initImage = await program.screenshot();
expect(initImage).toSaveImageSnapshot();
const btn = await page.$('#btn')
await btn.tap()
await page.waitFor(100)
const changedImage = await program.screenshot();
expect(changedImage).toSaveImageSnapshot();
}
it('template map style options API', async () => {
await test(OPTIONS_PAGE_PATH)
})
it('template map style composition API', async () => {
await test(COMPOSITION_PAGE_PATH)
})
});
\ No newline at end of file
<template>
<view class="page">
<template v-if="isShow">
<template v-if="dataInfo.isShow">
<view class="title">{{ title }}</view>
</template>
<view class="show-botton" @click="handleShow">{{ isShow ? '点击隐藏' : '点击显示' }}</view>
<view class="show-botton" @click="handleShow">{{ dataInfo.isShow ? '点击隐藏' : '点击显示' }}</view>
<template v-for="(item, index) in list" :key="index">
<view class="item">{{ index + 1 }}.{{ item.name }}</view>
</template>
......@@ -11,7 +11,10 @@
</view>
</template>
<script>
<script lang='uts'>
type DataInfo = {
isShow: boolean
}
type objType = {
name : string
}
......@@ -19,7 +22,9 @@ export default {
data() {
return {
title: "hello",
isShow: false,
dataInfo: {
isShow: false,
} as DataInfo,
list: [{
name: 'foo1'
},
......@@ -31,7 +36,7 @@ export default {
},
methods: {
handleShow() {
this.isShow = !this.isShow
this.dataInfo.isShow = !this.dataInfo.isShow
},
goMapStyle() {
uni.navigateTo({ url: '/pages/built-in/component/template/template-map-style-options' })
......
const PAGE_PATH_OPTIONS = '/pages/built-in/component/template/template-options'
const PAGE_PATH_COMPONSITION = '/pages/built-in/component/template/template-composition'
const PAGE_PATH_OPTIONS = '/pages/built-in/special-elements/template/template-options'
const PAGE_PATH_COMPOSITION = '/pages/built-in/special-elements/template/template-composition'
describe('built-in/component', () => {
describe('built-in/special-elements/component', () => {
let page
const test = async () => {
await page.waitFor('view')
expect.assertions(4);
const showBtn = await page.$('.show-botton')
await showBtn.tap()
expect((await page.data()).isShow).toBeTruthy()
const dataInfo = await page.data('dataInfo')
expect(dataInfo.isShow).toBeTruthy()
const getTitle = await page.$('.title')
expect(await getTitle.text()).toBe("hello")
const getShow = await page.$('.show-botton')
......@@ -20,7 +22,7 @@ describe('built-in/component', () => {
await test()
})
it('template Composition API', async () => {
page = await program.reLaunch(PAGE_PATH_COMPONSITION)
page = await program.reLaunch(PAGE_PATH_COMPOSITION)
await test()
})
});
\ No newline at end of file
......@@ -47,7 +47,7 @@ export default {
},
mounted(){
const rootElement = this.$refs['mixin-comp-root'] as UniElement
this.rootElementTitle = JSON.stringify(rootElement.getAttribute('title'))
this.rootElementTitle = rootElement.getAttribute('title')
},
watch: {
globalMixinOnloadMsg1(newVal: string) {
......
......@@ -17,7 +17,7 @@ describe('mixins', () => {
it('inheritAttrs', async () => {
const comp1RootElementTitleEl = await page.$('.root-element-title-1')
const comp1RootElementTitleText = await comp1RootElementTitleEl.text()
expect(comp1RootElementTitleText).toBe('rootElementTitle: ')
expect(comp1RootElementTitleText).toBe('rootElementTitle: null')
const comp2RootElementTitleEl = await page.$('.root-element-title-2')
const comp2RootElementTitleText = await comp2RootElementTitleEl.text()
expect(comp2RootElementTitleText).toBe('rootElementTitle: title')
......
......@@ -28,7 +28,6 @@
export default {
props: ['str', 'num', 'bool', 'obj', 'arr'],
mounted() {
console.log('this.$props is Map', this.$props, this.$props instanceof Map);
console.log('this.$props.str: ',this.$props['str']);
console.log('this.$props.num: ',this.$props['num']);
console.log('this.$props.bool: ',this.$props['bool']);
......
......@@ -11,6 +11,11 @@ const rootStr = ref('')
onMounted(() => {
const instance = getCurrentInstance()!.proxy!
// #ifdef APP-ANDROID
rootStr.value = (instance.$root!.$exposed['str'] as Ref<string>).value as string
// #endif
// #ifndef APP-ANDROID
rootStr.value = instance.$root!['str'] as string
// #endif
})
</script>
<template>
<view class="page">
<view class="mb-10 flex justify-between flex-row">
<text>root str in parent component: </text>
<text id="root-str-parent">{{ rootStr }}</text>
</view>
<child />
</view>
</template>
<script setup lang="uts">
import Child from './child-composition.uvue'
const str = ref('root component str')
const rootStr = ref('')
onReady(() => {
const instance = getCurrentInstance()!.proxy!
rootStr.value = (instance.$root!.$exposed['str'] as Ref<string>).value as string
})
defineExpose({
str
})
</script>
<template>
<view class="page">
<view class="mb-10 flex justify-between flex-row">
<text>root str in parent component: </text>
<text id="root-str-parent">{{ rootStr }}</text>
</view>
<Child />
</view>
</template>
<script setup lang="uts">
import Child from './child-composition.uvue'
const str = ref('root component str')
const rootStr = ref('')
onReady(() => {
const instance = getCurrentInstance()!.proxy!
// TODO: 确认 android 与 ios 的差异, ios 与标准 vue 相同
// #ifdef APP-ANDROID
rootStr.value = (instance.$root!.$exposed['str'] as Ref<string>).value as string
// #endif
// #ifndef APP-ANDROID
rootStr.value = instance.$root!['str'] as string
// #endif
})
defineExpose({
str
})
</script>
\ No newline at end of file
......@@ -10,7 +10,10 @@ describe('$root', () => {
return
}
let page
const test = async (page) => {
const test = async (pagePath) => {
page = await program.reLaunch(pagePath)
await page.waitFor('view')
const rootStrParent = await page.$('#root-str-parent')
expect(await rootStrParent.text()).toBe('root component str')
......@@ -19,16 +22,10 @@ describe('$root', () => {
}
it('$root 选项式 API', async () => {
page = await program.reLaunch(OPTIONS_PAGE_PATH)
await page.waitFor('view')
await test(page)
await test(OPTIONS_PAGE_PATH)
});
it('$root 组合式 API', async () => {
page = await program.reLaunch(COMPOSITION_PAGE_PATH)
await page.waitFor('view')
await test(page)
await test(COMPOSITION_PAGE_PATH)
})
})
......@@ -18,7 +18,7 @@
</view>
<!-- v-bind props -->
<Foo :title :num="dataInfo.fooProps.num" :obj="dataInfo.fooProps.obj" />
<Foo :title="dataInfo.fooProps.title" :num="dataInfo.fooProps.num" :obj="dataInfo.fooProps.obj" />
<!-- v-bind in style -->
<!-- #ifdef WEB -->
......@@ -50,13 +50,12 @@ export default {
components: { Foo },
data() {
return {
title: 'foo title',
dataInfo: {
fontSize: '20px',
backgroundColor: 'background-color: green',
border: 'border: 2px solid red',
fooProps: {
title: '',
title: 'foo title',
num: 1,
obj: {
name: 'foo obj name'
......
......@@ -4,6 +4,7 @@ const COMPOSITION_PAGE_PATH = '/pages/directive/v-bind/v-bind-composition'
describe('v-bind', () => {
let page
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isIos = platformInfo.startsWith('ios')
const isWeb = platformInfo.startsWith('web')
const isFirefox = platformInfo.indexOf('firefox') > -1
......
const OPTIONS_PAGE_PATH = '/pages/directive/v-html/v-html-options'
const COMPOSITION_PAGE_PATH = '/pages/directive/v-html/v-html-composition'
// TODO: ios 暂不支持
// TODO: ios 暂不支持
describe('v-html', () => {
let page
const test = async () => {
const image = await program.screenshot()
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
}
it('v-html options API', async () => {
......
......@@ -8,13 +8,13 @@ describe('自定义组件中使用 class 定制另一个自定义组件根节点
page = await program.reLaunch(PAGE_PATH)
await page.waitFor('view')
const image = await program.screenshot()
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
})
it('set-custom-child-component-root-node-class-options Screenshot', async () => {
page = await program.reLaunch(PAGE_PATH_COMPOSITION)
await page.waitFor('view')
const image = await program.screenshot()
expect(image).toMatchImageSnapshot()
expect(image).toSaveImageSnapshot()
})
})
......@@ -863,93 +863,105 @@ export default {
},
{
id: 'built-in',
name: '内置组件',
name: '内置',
pages: [
{
id: 'component/keep-alive',
name: 'keep-alive',
id:'component',
name: '组件',
children: [
{
id: 'keep-alive-options',
name: 'keep-alive 选项式 API',
url: 'keep-alive-options'
},
id: 'keep-alive',
name: 'keepAlive',
children: [
{
id: 'keep-alive-options',
name: 'keepAlive 选项式 API',
url: 'keep-alive-options'
},
{
id: 'keep-alive-composition',
name: 'keep-alive 组合式 API',
url: 'keep-alive-composition'
}
]
},
{
id: 'component/teleport',
name: 'teleport',
children: [
{
id: 'teleport-options',
name: 'teleport 选项式 API',
url: 'teleport-options'
{
id: 'keep-alive-composition',
name: 'keepAlive 组合式 API',
url: 'keep-alive-composition'
}
]
},
{
id: 'teleport-composition',
name: 'teleport 组合式 API',
url: 'teleport-composition'
}
]
},
{
id: 'component/component',
name: 'component',
children: [
{
id: 'component-options',
name: 'component 选项式 API',
url: 'component-options'
},
id: 'teleport',
name: 'Teleport',
children: [
{
id: 'teleport-options',
name: 'Teleport 选项式 API',
url: 'teleport-options'
},
{
id: 'component-composition',
name: 'component 组合式 API',
url: 'component-composition'
}
]
},
{
id: 'component/slots',
name: 'slot',
children: [
{
id: 'slots-options',
name: 'slots 选项式 API',
url: 'slots-options'
{
id: 'teleport-composition',
name: 'Teleport 组合式 API',
url: 'teleport-composition'
}
]
},
{
id: 'slots-composition',
name: 'slots 组合式 API',
url: 'slots-composition'
}
]
},
{
id: 'component/template',
name: 'template',
id:'special-elements',
name: '特殊元素',
children: [
{
id: 'template-options',
name: 'template 选项式 API',
url: 'template-options'
id: 'component',
name: 'component',
children: [
{
id: 'component-options',
name: 'component 选项式 API',
url: 'component-options'
},
{
id: 'component-composition',
name: 'component 组合式 API',
url: 'component-composition'
}
]
},
{
id: 'slots',
name: 'slot',
children: [
{
id: 'slots-options',
name: 'slots 选项式 API',
url: 'slots-options'
},
{
id: 'slots-composition',
name: 'slots 组合式 API',
url: 'slots-composition'
}
]
},
{
id: 'template-composition',
name: 'template 组合式 API',
url: 'template-composition'
id: 'template',
name: 'template',
children: [
{
id: 'template-options',
name: 'template 选项式 API',
url: 'template-options'
},
{
id: 'template-composition',
name: 'template 组合式 API',
url: 'template-composition'
}
]
}
]
}
},
] as Page[]
},
{
......
const PAGE_PATH = '/pages/reactivity/utilities/to-value/to-value'
const PAGE_PATH = '/pages/reactivity/utilities/to-value/to-value'
const platformInfo = process.env.uniTestPlatformInfo.toLowerCase()
const isWeb = platformInfo.startsWith('web')
describe('toValue', () => {
let page = null
......@@ -24,7 +26,10 @@ describe('toValue', () => {
const incrementBtn = await page.$('#increment-btn')
await incrementBtn.tap()
expect(await objNum.text()).toBe('1')
expect(await toValueObjNum.text()).toBe('1')
expect(await objNum.text()).toBe('1')
if(!isWeb){
// 数据更新成功,但因为 web 端 text 为组件,所以视图未更新
expect(await toValueObjNum.text()).toBe('1')
}
})
})
\ No newline at end of file
......@@ -43,7 +43,7 @@ const obj = reactive({
num: 0
} as Obj)
let toValueObjNum = toValue(() : number => obj.num)
let toValueObjNum = toValue(() : number => 0)
const increment = () => {
obj.num++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册