提交 e2e798ad 编写于 作者: DCloud-yyl's avatar DCloud-yyl

Merge branch 'dev' into alpha

# Conflicts:
#	pages/API/nodes-info/nodes-info.uvue
#	pages/component/view/view-draw.uvue
#	pages/template/long-list/long-list.uvue
#	pages/template/pull-zoom-image/pull-zoom-image.uvue
#	pages/template/swiper-list/swiper-list.uvue
#	pages/template/swiper-list2/swiper-list2.uvue
......@@ -83,7 +83,7 @@
.uni-input {
height: 50rpx;
padding: 15rpx 25rpx;
line-height: 50rpx;
/* line-height: 50rpx; */
font-size: 28rpx;
background: #FFF;
flex: 1;
......
<script lang="uts">
import {type PropType} from 'vue'
export type ItemType = { value : number; name : string }
export default {
......@@ -22,7 +24,7 @@
_change(e : RadioGroupChangeEvent) {
const selected = this.items.find((item: ItemType) : boolean => {
return item.name === e.detail.value
}) as ItemType | null
})
if (selected !== null) {
this.current = selected.value
this.$emit('change', this.current)
......
<template name="page-head">
<view class="common-page-head">
<view class="common-page-head-title-box">
<text class="common-page-head-title">{{title}}</text>
</view>
<view class="common-page-head">
<view class="common-page-head-title-box">
<text class="common-page-head-title">{{title}}</text>
</view>
</view>
</template>
<script>
export default {
name: "page-head",
props: {
title: {
type: String,
default: ""
}
}
<script lang="uts">
export default {
name: "page-head",
props: {
title: {
type: String,
default: ""
}
}
}
</script>
<style>
.common-page-head {
padding: 35rpx;
flex-direction: row;
justify-content: center;
}
.common-page-head {
padding: 35rpx;
flex-direction: row;
justify-content: center;
}
.common-page-head-title-box {
padding: 0 40rpx;
height: 88rpx;
border-bottom: 2rpx solid #D8D8D8;
}
.common-page-head-title-box {
padding: 0 40rpx;
height: 88rpx;
border-bottom: 2rpx solid #D8D8D8;
}
.common-page-head-title {
line-height: 88rpx;
font-size: 30rpx;
color: #BEBEBE;
}
.common-page-head-title {
line-height: 88rpx;
font-size: 30rpx;
color: #BEBEBE;
}
</style>
\ No newline at end of file
......@@ -4,7 +4,7 @@
</view>
</template>
<script>
<script lang="uts">
/**
* @description u-link是一个外部网页超链接组件,在小程序内打开内部web-view组件或复制url,在app内打开外部浏览器,在h5端打开新网页
* @property {String} href 点击后打开的外部网页url,小程序中必须以https://开头
......
<template>
<view class="uni-collapse-item">
<view class="uni-collapse-item__title" @click="openCollapse(!this.is_open)">
<view class="uni-collapse-item__title" @click="openCollapse(!is_open)">
<text class="uni-collapse-item__title-text" :class="{'is-disabled':disabled,'open--active':is_open}">{{title}}</text>
<view class="down_arrow" :class="{'down_arrow--active': is_open}"></view>
</view>
......@@ -12,7 +12,7 @@
</view>
</template>
<script>
<script lang="uts">
import { $dispatch } from './util.uts'
export default {
name: "UniCollapseItem",
......@@ -35,8 +35,8 @@
return {
height: 0,
is_open: this.open as boolean,
boxNode: null as INode | null,
contentNode: null as INode | null,
boxNode: null as Element | null,
contentNode: null as Element | null,
};
},
watch: {
......@@ -51,8 +51,8 @@
$dispatch(this, 'UniCollapse', 'init', this)
},
mounted() {
this.boxNode = this.$refs['boxRef'] as INode;
this.contentNode = this.$refs['contentRef'] as INode;
this.boxNode = this.$refs['boxRef'] as Element;
this.contentNode = this.$refs['contentRef'] as Element;
// this.openCollapse(this.open)
},
methods: {
......
// import { ComponentPublicInstance } from 'vue'
import { ComponentPublicInstance } from 'vue'
// 查找父组件实例
export function $dispatch(
......
......@@ -5,8 +5,8 @@
</view>
</template>
<script>
// import { ComponentPublicInstance } from 'vue'
<script lang="uts">
import { ComponentPublicInstance } from 'vue'
export default {
name: "UniCollapse",
props: {
......
@font-face {
font-family: "UniIconsLight";
src: url('./uniicons.ttf') format('truetype');
}
.uni-icons {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.uniui-back:before {
content: "\e600";
}
<template>
<view class="uni-navbar">
<view class="uni-navbar-inner" :style="navbarStyle">
<view class="left-content" @click="back">
<text class="uni-icons">{{unicode}}</text>
</view>
<view class="uni-navbar-content" :class="{'is-left':isLeft}">
<slot>{{title}}</slot>
</view>
<view class="right-content">
<slot name="right"></slot>
</view>
</view>
</view>
</template>
<script>
import iconpath from './uniicons.ttf'
export default {
name: "uni-navbar",
props: {
title: {
type: String,
default: ''
},
isLeft: {
type: Boolean,
default: false
}
},
data() {
return {
statusBarHeight: 0
};
},
computed: {
navbarStyle() : string {
return `margin-top:${this.statusBarHeight}px`
},
unicode() : string {
return '\ue600'
}
},
created() {
uni.loadFontFace({
global: false,
family: 'UniIconsFontFamily',
source: iconpath,
success() { },
fail(err) {
console.log(err);
},
})
const sys = uni.getSystemInfoSync()
const statusBarHeight = sys.statusBarHeight
this.statusBarHeight = statusBarHeight
},
mounted() {
// TODO 暂时加定时器,否则不生效
setTimeout(() => {
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#ffffff'
})
}, 100)
},
methods: {
back() {
uni.navigateBack({})
}
},
}
</script>
<style>
.uni-icons {
font-family: "UniIconsFontFamily" !important;
font-size: 22px;
font-style: normal;
color: #333;
}
.uni-navbar {
border: 1px #eee solid;
background-color: #fff;
}
.uni-navbar-inner {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-between;
height: 45px;
}
.left-content,
.right-content {
display: flex;
justify-content: center;
align-items: center;
width: 45px;
height: 100%;
}
.uni-navbar-content {
position: absolute;
height: 100%;
top: 0;
bottom: 0;
left: 45px;
right: 45px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
.is-left {
justify-content: flex-start;
}
</style>
<template>
<view class="uni-navbar">
<view class="uni-navbar-inner" :style="navbarStyle">
<view class="left-content" @click="back">
<text class="uni-icons uniui-back"></text>
</view>
<view class="uni-navbar-content">
<slot>{{title}}</slot>
</view>
<view class="right-content">
<slot name="right"></slot>
</view>
</view>
</view>
</template>
<script>
export default {
name: "uni-navbar",
props: {
title: {
type: String,
default: ''
}
},
data() {
return {
statusBarHeight: 0
};
},
computed: {
navbarStyle() {
return `margin-top:${this.statusBarHeight}px`
},
},
created() {
const sys = uni.getSystemInfoSync()
const statusBarHeight = sys.statusBarHeight
this.statusBarHeight = statusBarHeight
},
methods: {
back() {
uni.navigateBack({})
}
},
}
</script>
<style>
@import './uni-icons.css';
.uni-icons {
font-family: UniIconsLight;
text-decoration: none;
text-align: center;
font-size: 22px;
font-style: normal;
color: #333;
}
.uni-navbar {
border: 1px #eee solid;
background-color: #fff;
}
.uni-navbar-inner {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-between;
height: 45px;
}
.left-content,
.right-content {
display: flex;
justify-content: center;
align-items: center;
width: 45px;
height: 100%;
}
.uni-navbar-content {
position: absolute;
height: 100%;
top: 0;
bottom: 0;
left: 45px;
right: 45px;
display: flex;
justify-content: center;
align-items: center;
}
</style>
无法预览此类型文件
......@@ -6,13 +6,14 @@ const {
const hbuilderx_version = process.env.HX_Version
const uniTestPlatformInfo = process.env.uniTestPlatformInfo ? process.env.uniTestPlatformInfo.replace(/\s/g,'_') : ''
const folderName = `__image_snapshots__/${hbuilderx_version}/__${uniTestPlatformInfo}__`
const baseFolderName = `__image_snapshots__/base`
expect.extend({
toMatchImageSnapshot: configureToMatchImageSnapshot({
customSnapshotIdentifier(args) {
return args.currentTestName.replace(/\//g, '-').replace(' ', '-');
},
customSnapshotsDir: path.join(__dirname, folderName),
customSnapshotsDir: path.join(__dirname, baseFolderName),
customDiffDir: path.join(__dirname, `${folderName}/`, 'diff'),
}),
});
\ No newline at end of file
module.exports = {
testTimeout: 10000,
testTimeout: 30000,
reporters: ['default'],
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
moduleFileExtensions: ['js', 'json'],
rootDir: __dirname,
testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)"],
testMatch: ["<rootDir>/pages/API/storage/storage.test.js"],
testPathIgnorePatterns: ['/node_modules/'],
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
}
......@@ -2,8 +2,8 @@
"name" : "hello-uniapp x",
"appid" : "__UNI__3584C99",
"description" : "",
"versionName" : "1.0.5",
"versionCode" : 105,
"versionName" : "1.0.10",
"versionCode" : 10010,
"uni-app-x" : {},
/* 快应用特有相关 */
"quickapp" : {},
......@@ -27,5 +27,10 @@
"uniStatistics" : {
"enable" : false
},
"app": {
"duts": [
"uni-facialRecognitionVerify"
]
},
"vueVersion" : "3"
}
......@@ -243,6 +243,13 @@
"navigationBarTitleText": "设置导航条颜色"
}
},
{
"path": "pages/API/set-navigation-bar-color/set-custom-navigation-bar-color",
"style": {
"navigationBarTitleText": "设置自定义导航栏颜色",
"navigationStyle": "custom"
}
},
{
"path": "pages/API/navigator/new-page/new-page-1",
"style": {
......@@ -263,6 +270,12 @@
"enablePullDownRefresh": true
}
},
{
"path": "pages/API/get-element-by-id/get-element-by-id",
"style": {
"navigationBarTitleText": "获取节点"
}
},
{
"path": "pages/API/nodes-info/nodes-info",
"style": {
......@@ -288,7 +301,7 @@
}
},
{
"path": "pages/API/show-loading/show-loading",
"path": "pages/API/loading/loading",
"style": {
"navigationBarTitleText": "加载提示框"
}
......@@ -336,24 +349,48 @@
"navigationBarTitleText": "background-image"
}
},
{
"path": "pages/CSS/border/border-bottom",
"style": {
"navigationBarTitleText": "border-bottom"
}
},
{
"path": "pages/CSS/border/border-color",
"style": {
"navigationBarTitleText": "border-color"
}
},
{
"path": "pages/CSS/border/border-left",
"style": {
"navigationBarTitleText": "border-left"
}
},
{
"path": "pages/CSS/border/border-radius",
"style": {
"navigationBarTitleText": "border-radius"
}
},
{
"path": "pages/CSS/border/border-right",
"style": {
"navigationBarTitleText": "border-right"
}
},
{
"path": "pages/CSS/border/border-style",
"style": {
"navigationBarTitleText": "border-style"
}
},
{
"path": "pages/CSS/border/border-top",
"style": {
"navigationBarTitleText": "border-top"
}
},
{
"path": "pages/CSS/border/border-width",
"style": {
......@@ -479,12 +516,12 @@
"style": {
"navigationBarTitleText": "width"
}
},
{
"path": "pages/CSS/layout/z-index",
"style": {
"navigationBarTitleText": "z-index"
}
},
{
"path": "pages/CSS/layout/z-index",
"style": {
"navigationBarTitleText": "z-index"
}
},
{
"path": "pages/CSS/layout/visibility",
......@@ -667,7 +704,13 @@
}
},
{
"path": "pages/API/call-function/call-function",
"path": "pages/API/unicloud-call-function/unicloud-call-function",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/API/unicloud-import-object/unicloud-import-object",
"style": {
"navigationBarTitleText": ""
}
......@@ -709,11 +752,17 @@
}
},
{
"path": "pages/API/save-image-to-album/save-image-to-album",
"path": "pages/API/save-image-to-photos-album/save-image-to-photos-album",
"style": {
"navigationBarTitleText": "保存图片到相册"
}
},
{
"path": "pages/API/choose-image/choose-image",
"style": {
"navigationBarTitleText": "图片"
}
},
{
"path": "pages/component/scroll-view/scroll-view-refresher",
"style": {
......@@ -762,18 +811,6 @@
"navigationBarTitleText": "模板"
}
},
{
"path": "pages/component/long-list/long-list",
"style": {
"navigationBarTitleText": "长列表示例"
}
},
{
"path": "pages/component/long-list/detail/detail",
"style": {
"navigationBarTitleText": "详情示例"
}
},
{
"path": "pages/template/swiper-list/swiper-list",
"style": {
......@@ -875,9 +912,40 @@
{
"path": "pages/template/pull-zoom-image/pull-zoom-image",
"style": {
"enablePullDownRefresh": false,
"navigationStyle": "custom"
}
},
{
"path": "pages/API/unicloud-file-api/unicloud-file-api",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/API/unicloud-database/unicloud-database",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/template/navbar-lite/navbar-lite",
"style": {
"navigationBarTitleText": "自定义导航栏",
"navigationStyle": "custom"
}
},
{
"path": "pages/template/custom-tab-bar/custom-tab-bar",
"style": {
"navigationBarTitleText": "自定义TabBar"
}
}, {
"path": "pages/API/facial-recognition-verify/facial-recognition-verify",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
],
"globalStyle": {
......@@ -929,4 +997,4 @@
"query": "" //启动参数,在页面的onLoad函数里面得到
}]
}
}
}
\ No newline at end of file
......@@ -82,9 +82,11 @@
if (this.itemContentLarge) {
itemInfo = ['两个黄鹂鸣翠柳,一行白鹭上青天。窗含西岭千秋雪,门泊东吴万里船', '水光潋滟晴方好,山色空蒙雨亦奇。 欲把西湖比西子,淡妆浓抹总相宜', '']
} else if (this.itemNumLargeSelect) {
}
if (this.itemNumLargeSelect) {
// 大量选项测试,不能超过6个元素 https://uniapp.dcloud.net.cn/api/ui/prompt.html#showactionsheet
itemInfo = []
itemInfo = []
for (var i = 1; i <= 10; i++) {
itemInfo.push('两个黄鹂鸣翠柳,一行白鹭上青天');
}
......
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-common-mt">
<view class="uni-list">
<view class="uni-list-cell cell-pd">
<view class="uni-list-cell-left uni-label">
图片来源
</view>
<view class="uni-list-cell-right" @click="chooseImageSource">
<text class="click-t">{{sourceType[sourceTypeIndex]}}</text>
</view>
</view>
<view class="uni-list-cell cell-pd">
<view class="uni-list-cell-left uni-label">
图片质量
</view>
<view class="uni-list-cell-right" @click="chooseImageType">
<text class="click-t">{{sizeType[sizeTypeIndex]}}</text>
</view>
</view>
<view class="uni-list-cell cell-pd">
<view class="uni-list-cell-left uni-label">
数量限制
</view>
<view class="uni-list-cell-right">
<input class="click-t" :value="countIndex+1" type="number" :maxlength="1" @confirm="chooseImageCount" confirm-type="done" />
</view>
</view>
<view class="uni-list-cell cell-pd">
<view class="uni-list-cell-left uni-label">
图像裁剪
</view>
<view class="uni-list-cell-right">
<switch :checked="isCrop" @change="switchCrop"></switch>
</view>
</view>
<view ref="cropOptionNode" class="crop-option" :style="{'height':isCrop?'200px':'0px'}">
<view class="uni-list-cell cell-pd">
<view class="uni-list-cell-left item_width">
图片质量(%)
</view>
<view class="uni-list-cell-right">
<input :value="cropPercent" @confirm="cropPercentConfim" type="number" />
</view>
</view>
<view class="uni-list-cell cell-pd">
<view class="uni-list-cell-left item_width">
裁剪宽度(px)
</view>
<view class="uni-list-cell-right">
<input :value="cropWidth" @confirm="cropWidthConfim" type="number" />
</view>
</view>
<view class="uni-list-cell cell-pd">
<view class="uni-list-cell-left item_width">
裁剪高度(px)
</view>
<view class="uni-list-cell-right">
<input :value="cropHeight" @confirm="cropHeightConfim" type="number" />
</view>
</view>
<view class="uni-list-cell cell-pd">
<view class="uni-list-cell-left item_width">
保留原宽高
</view>
<view class="uni-list-cell-right">
<switch :checked="cropResize" @change="cropResizeChange"></switch>
</view>
</view>
</view>
</view>
<view class="uni-list list-pd" style="padding: 30rpx;">
<view class="uni-flex" style="margin-bottom: 20rpx;">
<view class="uni-list-cell-left">点击可预览选好的图片</view>
<view style="margin-left: auto;">
<text class="click-t">{{imageList.length}}/{{countIndex+1}}</text>
</view>
</view>
<view class="uni-flex" style="flex-wrap: wrap;">
<view v-for="(image,index) in imageList" :key="index" class="uni-uploader__input-box" style="border: 0rpx;">
<image style="width: 208rpx; height: 208rpx;" :src="image" :data-src="image" @tap="previewImage(index)"></image>
<image src="/static/plus.png" class="image-remove" @click="removeImage(index)"></image>
</view>
<image class="uni-uploader__input-box" @tap="chooseImage" src="/static/plus.png"></image>
</view>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
var sourceTypeArray = [
['camera'],
['album'],
['camera', 'album']
]
var sizeTypeArray = [
['compressed'],
['original'],
['compressed', 'original']
]
export default {
data() {
return {
title: 'choose/previewImage',
imageList: [] as Array<string>,
sourceTypeIndex: 2,
sourceType: ['拍照', '相册', '拍照或相册'],
sizeTypeIndex: 2,
sizeType: ['压缩', '原图', '压缩或原图'],
countIndex: 8,
count: [1, 2, 3, 4, 5, 6, 7, 8, 9],
isCrop: false,
cropPercent: 80,
cropWidth: 100,
cropHeight: 100,
cropResize: false
}
},
onUnload() {
this.imageList = [];
this.sourceTypeIndex = 2
this.sourceType = ['拍照', '相册', '拍照或相册']
this.sizeTypeIndex = 2
this.sizeType = ['压缩', '原图', '压缩或原图']
this.countIndex = 8
},
methods: {
cropHeightConfim(e : InputConfirmEvent) {
let value = parseInt(e.detail.value)
if (value > 0) {
this.cropHeight = value
} else {
uni.showToast({
position: "bottom",
title: "裁剪高度需要大于0"
})
}
},
cropWidthConfim(e : InputConfirmEvent) {
let value = parseInt(e.detail.value)
if (value > 0) {
this.cropWidth = value
} else {
uni.showToast({
position: "bottom",
title: "裁剪宽度需要大于0"
})
}
},
cropPercentConfim(e : InputConfirmEvent) {
let value = parseInt(e.detail.value)
if (value > 0 && value <= 100) {
this.cropPercent = value
} else {
uni.showToast({
position: "bottom",
title: "请输入0~100之间的值"
})
}
},
cropResizeChange(e : SwitchChangeEvent) {
this.cropResize = e.detail.value
},
switchCrop(e : SwitchChangeEvent) {
this.isCrop = e.detail.value
},
removeImage(index : number) {
this.imageList.splice(index, 1)
},
chooseImageSource() {
uni.showActionSheet({
itemList: ['拍照', '相册', '拍照或相册'],
success(e) {
this.sourceTypeIndex = e.tapIndex!
}
})
},
chooseImageType() {
uni.showActionSheet({
itemList: ['压缩', '原图', '压缩或原图'],
success(e) {
this.sizeTypeIndex = e.tapIndex!
}
})
},
chooseImageCount(event : InputConfirmEvent) {
let count = parseInt(event.detail.value) - 1
if (count < 0) {
uni.showToast({
position: "bottom",
title: "图片数量应该大于0"
})
return
}
this.countIndex = count
},
chooseImage: function () {
// var cropOption:ChooseImageCropOptions|null = this.isCrop ? null : new ChooseImageCropOptions( )
if (this.imageList.length >= 9) {
uni.showToast({
position: "bottom",
title: "已经有9张图片了,请删除部分图片之后重新选择"
})
return
}
uni.chooseImage({
sourceType: sourceTypeArray[this.sourceTypeIndex],
sizeType: sizeTypeArray[this.sizeTypeIndex],
crop: this.isCrop ? { "quality": this.cropPercent, "width": this.cropWidth, "height": this.cropHeight, "resize": this.cropResize } as ChooseImageCropOptions : null,
count: this.imageList.length + this.count[this.countIndex] > 9 ? 9 - this.imageList.length : this.count[this.countIndex],
success: (res) => {
this.imageList = this.imageList.concat(res.tempFilePaths);
},
fail: (err) => {
console.log("err: ", JSON.stringify(err));
}
})
},
previewImage: function (index : number) {
uni.previewImage({
current: index,
urls: this.imageList
})
}
}
}
</script>
<style>
.cell-pd {
padding: 22rpx 30rpx;
}
.click-t {
color: darkgray;
}
.list-pd {
margin-top: 50rpx;
}
.uni-uploader__input-box {
margin: 10rpx;
width: 208rpx;
height: 208rpx;
border: 2rpx solid #D9D9D9;
}
.uni-uploader__input {
position: absolute;
z-index: 1;
top: 0;
left: 0;
width: 100%;
height: 100%;
opacity: 0;
}
.image-remove {
transform: rotate(45deg);
width: 50rpx;
height: 50rpx;
position: absolute;
top: 0;
right: 0;
border-radius: 25rpx;
background-color: rgba(200, 200, 200, 0.8);
}
.item_width {
width: 260rpx;
}
.crop-option {
border-top-color: lightgray;
border-width: 1rpx;
padding: 20rpx;
transition: height;
transition-duration: 300;
}
</style>
\ No newline at end of file
const PAGE_PATH = '/pages/API/download-file/download-file'
describe('ExtApi-DownloadFile', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_downloadFile');
await page.waitFor(500);
res = await page.data('jest_result');
});
it('Check ', async () => {
expect(res).toBe(true);
});
});
......@@ -21,14 +21,15 @@
<!-- #endif -->
</template>
<script>
import DownloadTask from 'uts.sdk.modules.DCloudUniNetwork.DownloadTask';
export default {
data() {
return {
title: 'downloadFile',
imageSrc: '',
task: null as DownloadTask | null,
pageVisible: false
pageVisible: false,
//自动化测试例专用
jest_result: false
}
},
onLoad() {
......@@ -67,7 +68,19 @@ export default {
console.log("progress : ", update.progress);
}
})
}
},
//自动化测试例专用
jest_downloadFile(){
uni.downloadFile({
url: "https://web-assets.dcloud.net.cn/unidoc/zh/uni-app.png",
success() {
this.jest_result = true
},
fail: () => {
this.jest_result = false
}
});
}
}
}
</script>
......
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<input class="uni-input uni-input-default" type="text" v-model="realName" name="real-name" id="real-name" placeholder="姓名" />
</view>
<view class="uni-btn-v uni-common-mt">
<input class="uni-input uni-input-default" type="text" v-model="idCard" name="id-card" id="id-card" placeholder="身份证号" />
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="facialRecognition">开始人脸识别</button>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: '实人认证',
realName: '',
idCard: ''
}
},
onReady() {
uni.showModal({
title: '提示',
content: '注意:目前uni-app x内使用实人认证功能需要打包自定义基座。',
showCancel: false
})
},
methods: {
facialRecognition() {
const realName = this.realName.trim()
const idCard = this.idCard.trim()
if (realName == '' || idCard == '') {
uni.showModal({
title: '错误',
content: '姓名和身份证号不可为空',
showCancel: false
})
return
}
const testFacialCo = uniCloud.importObject('facial-recognition-co')
const metaInfo = uni.getFacialRecognitionMetaInfo();
testFacialCo.getCertifyId({
realName,
idCard,
metaInfo
})
.then<string>((res : UTSJSONObject) : Promise<string> => {
const certifyId = res['certifyId'] as string
return new Promise((
resolve : (res : string) => void,
reject : (err : Error) => void
) => {
uni.startFacialRecognitionVerify({
certifyId,
success() {
resolve(certifyId)
},
fail(err) {
reject(new Error(err.errMsg))
}
})
})
})
.then<UTSJSONObject>((certifyId : string) : Promise<UTSJSONObject> => {
return testFacialCo.getAuthResult(certifyId)
})
.then<void>((res : UTSJSONObject) => {
console.log('res', res)
})
.catch<void>((err : any | null) => {
console.error('error', err)
})
}
}
}
</script>
<style>
</style>
const PAGE_PATH = '/pages/API/get-app-authorize-setting/get-app-authorize-setting'
describe('ExtApi-GetAppAuthorizeSetting', () => {
let page;
let res;
let commonSupportList = [
'authorized', 'denied', 'not determined', 'config error'
]
let locationAccuracySupportList = [
'reduced', 'full', 'unsupported'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getAppAuthorizeSetting();
});
it('Check cameraAuthorized', async () => {
expect(commonSupportList).toContain(res.cameraAuthorized)
});
it('Check locationAuthorized', async () => {
expect(commonSupportList).toContain(res.locationAuthorized)
});
it('Check locationAccuracy', async () => {
expect(locationAccuracySupportList).toContain(res.locationAccuracy)
});
it('Check microphoneAuthorized', async () => {
expect(commonSupportList).toContain(res.microphoneAuthorized)
});
it('Check notificationAuthorized', async () => {
expect(commonSupportList).toContain(res.notificationAuthorized)
});
});
const PAGE_PATH = '/pages/API/get-app-base-info/get-app-base-info'
describe('ExtApi-GetAppBaseInfo', () => {
let page;
let res;
const stringProperties = [
'appId', 'appName', 'appVersion', 'appVersionCode', 'appLanguage',
'language', 'version', 'uniCompileVersion', 'uniPlatform', 'uniRuntimeVersion',
]
const numberProperties = [
'uniCompileVersionCode', 'uniRuntimeVersionCode'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getAppBaseInfo();
});
it('Check properties', async () => {
for (const key in res) {
const value = res[key];
console.log("key :",key , "value :", value);
if (stringProperties.indexOf(key) != -1) {
expect(value).not.toBeNull();
expect(value).not.toBe("");
}
if (numberProperties.indexOf(key) != -1) {
expect(value).not.toBeNull();
expect(value).toBeGreaterThanOrEqual(3.90);
}
}
});
});
......@@ -37,17 +37,17 @@
methods: {
getAppBaseInfo: function () {
const res = uni.getAppBaseInfo();
//类型对象暂时不支持forin或Object.keys(), 临时通过字符串进行转化。
const json = JSON.stringify(res);
const result = JSON.parse<Map<string, any>>(json);
this.items = [] as Item[];
result?.forEach((value, key) => {
const item = {
label: key,
value: "" + value
} as Item;
this.items.push(item);
})
this.items = [] as Item[];
for(const key in res){
const value = res[key];
if(value != null){
const item = {
label: key,
value: "" + ((typeof value == "object")? JSON.stringify(value) : value)
} as Item;
this.items.push(item);
}
}
}
}
}
......
const PAGE_PATH = '/pages/API/get-battery-info/get-battery-info'
describe('ExtApi-GetBatteryInfo', () => {
let page;
let res;
const numberProperties = [
'level'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getBatteryInfo();
});
it('Check properties', async () => {
for (const key in res) {
const value = res[key];
expect(value).not.toBeNull();
if (numberProperties.indexOf(key) != -1) {
expect(value).toBeGreaterThanOrEqual(0.1);
}
}
});
});
const PAGE_PATH = '/pages/API/get-device-info/get-device-info'
describe('ExtApi-GetDeviceInfo', () => {
let page;
let res;
const stringProperties = [
'brand', 'deviceBrand', 'deviceId', 'model', 'deviceModel',
'deviceType', 'devicePixelRatio', 'system', 'platform', 'uniRuntimeVersion',
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getDeviceInfo();
});
it('Check properties', async () => {
for (const key in res) {
const value = res[key];
console.log("key :",key , "value :", value);
if (stringProperties.indexOf(key) != -1) {
expect(value).not.toBeNull();
expect(value).not.toBe("");
}
if (key == 'deviceOrientation') {
expect(value).not.toBeNull();
expect(['portrait', 'landscape']).toContain(value);
}
}
});
});
......@@ -55,18 +55,18 @@ export default {
},
methods: {
getDeviceInfo: function () {
const res = uni.getDeviceInfo();
//类型对象暂时不支持forin或Object.keys(), 临时通过字符串进行转化。
const json = JSON.stringify(res);
const result = JSON.parse<Map<string, any>>(json);
this.items = [] as Item[];
result?.forEach((value, key) => {
const item = {
label: key,
value: "" + value
} as Item;
this.items.push(item);
})
const res = uni.getDeviceInfo();
this.items = [] as Item[];
for(const key in res){
const value = res[key];
if(value != null){
const item = {
label: key,
value: "" + ((typeof value == "object")? JSON.stringify(value) : value)
} as Item;
this.items.push(item);
}
}
}
}
}
......
const PAGE_PATH = "/pages/API/get-element-by-id/get-element-by-id";
let page;
describe("getElementById", () => {
beforeAll(async () => {
page = await program.navigateTo(PAGE_PATH);
await page.waitFor(1000);
});
it("getElementByNotExistId", async () => {
const res = await page.callMethod("getElementByNotExistId");
expect(!!res).toBe(false);
});
it("changeStyle", async () => {
await page.callMethod("changePageHeadBackgroundColor");
await page.callMethod("changeTextColor");
await page.callMethod("changeViewStyle");
const image = await program.screenshot();
expect(image).toMatchImageSnapshot();
});
});
<template>
<view>
<page-head id="page-head" title="getElementById"></page-head>
<view class="uni-padding-wrap">
<text id="text">this is text</text>
<view id="view" class="uni-common-mt" style="border: 1px solid red"
>this is view</view
>
<button class="uni-btn" @click="changePageHeadBackgroundColor">
修改 page-head 背景色
</button>
<button class="uni-btn" @click="changeTextColor">
修改 text 字体颜色
</button>
<button class="uni-btn" @click="changeViewStyle">
修改 view 宽高及背景色
</button>
</view>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
checked: false,
homePagePath: '/pages/tabBar/component',
launchOptionsPath: '',
}
},
methods: {
getElementByNotExistId(): Element | null {
return uni.getElementById('not-exist-id')
},
changePageHeadBackgroundColor(){
const pageHead = uni.getElementById('page-head')!
pageHead.style.setProperty('backgroundColor', 'red')
},
changeTextColor(){
const text = uni.getElementById('text')!
text.style.setProperty('color', 'red')
},
changeViewStyle(){
const view = uni.getElementById('view')!
view.style.setProperty('width', '90%')
view.style.setProperty('height', '50px')
view.style.setProperty('backgroundColor', '#007AFF')
}
}
}
</script>
<template>
<view>
<page-head title="getLaunchOptionsSync"></page-head>
<button @click="getLaunchOptionsSync">getLaunchOptionsSync</button>
<view
v-if="launchOptionsPath.length > 0"
class="uni-common-pl uni-common-mt"
>
<text>应用启动路径:</text>
<text style="margin-top: 5px">{{ launchOptionsPath }}</text>
<view class="uni-padding-wrap">
<button @click="getLaunchOptionsSync">getLaunchOptionsSync</button>
<view v-if="launchOptionsPath.length > 0" class="uni-common-mt">
<text>应用启动路径:</text>
<text style="margin-top: 5px">{{ launchOptionsPath }}</text>
</view>
</view>
</view>
</template>
......@@ -22,7 +21,7 @@ export default {
}
},
methods: {
getLaunchOptionsSync: function () {
getLaunchOptionsSync() {
const launchOptions = uni.getLaunchOptionsSync()
this.launchOptionsPath = launchOptions.path
if (launchOptions.path == this.homePagePath) {
......
......@@ -6,7 +6,7 @@
真机运行标准基座仅包含系统定位,即system。\n
部分手机因gms兼容不好可能导致无法定位。\n
gcj国标、逆地理信息等功能需三方sdk定位。如果需要类似能力可以下载腾讯定位插件,打包自定义基座。参考示例:</text>
<u-link :href="'https://gitcode.net/dcloud/uni-api/'" :text="'https://gitcode.net/dcloud/uni-api/'" :inWhiteList="true"></u-link>
<u-link :href="'https://ext.dcloud.net.cn/plugin?id=14569'" :text="'https://ext.dcloud.net.cn/plugin?id=14569'" :inWhiteList="true"></u-link>
</view>
<view class="uni-padding-wrap uni-common-mt">
......
const PAGE_PATH = '/pages/API/get-network-type/get-network-type'
describe('ExtApi-GetNetworkType', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_getNetworkType');
await page.waitFor(200);
res = await page.data('jest_result');
});
it('Check ', async () => {
expect(res).toBe(true);
});
});
......@@ -3,10 +3,10 @@
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view style="background:#FFFFFF; padding:40rpx;">
<view class="uni-hello-text uni-center">网络状态</view>
<view class="uni-center">网络状态</view>
<view v-if="hasNetworkType == false">
<view class="uni-h2 uni-center uni-common-mt">未获取</view>
<view class="uni-hello-text uni-center uni-common-mt">请点击下面按钮获取网络状态</view>
<view class="uni-center uni-common-mt">请点击下面按钮获取网络状态</view>
</view>
<view v-if="hasNetworkType == true">
<view class="uni-h2 uni-center uni-common-mt">{{networkType}}</view>
......@@ -27,7 +27,9 @@
hasNetworkType: false,
networkType: '',
connectedWifi: '',
pageVisible: false
pageVisible: false,
//自动化测试例专用
jest_result:false,
}
},
onLoad() {
......@@ -60,11 +62,22 @@
this.hasNetworkType = false;
this.networkType = '';
this.connectedWifi = '';
},
},
//自动化测试例专用
jest_getNetworkType(){
uni.getNetworkType({
success: () => {
this.jest_result = true;
},
fail: () => {
this.jest_result = false;
}
})
}
}
}
</script>
<style>
</style>
\ No newline at end of file
</style>
const PAGE_PATH = '/pages/API/get-system-info/get-system-info'
describe('ExtApi-GetSystemInfo', () => {
let page;
let res;
const stringProperties = [
'appId', 'appLanguage', 'appName', 'appVersion', 'appVersionCode',
'brand', 'deviceId', 'deviceBrand', 'deviceModel', 'deviceType', 'language',
'model', 'version', 'osName', 'osVersion', 'osLanguage', 'platform', 'system', 'ua', 'uniCompileVersion',
'uniPlatform', 'uniRuntimeVersion', 'romName', 'romVersion',
]
const numberProperties = [
'osAndroidAPILevel', 'devicePixelRatio', 'pixelRatio', 'screenWidth', 'screenHeight', 'statusBarHeight',
'windowWidth',
'windowHeight', 'windowTop', 'windowBottom', 'screenTop',
'uniCompileVersionCode', 'uniRuntimeVersionCode'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await page.callMethod('jest_getSystemInfo')
});
it('Check GetSystemInfoSync', async () => {
for (const key in res) {
const value = res[key];
console.log("key :",key , "value :", value);
if (stringProperties.indexOf(key) != -1) {
expect(value).not.toBeNull();
expect(value).not.toBe("");
}
if (numberProperties.indexOf(key) != -1) {
expect(value).not.toBeNull();
expect(value).toBeGreaterThanOrEqual(0);
}
if (key == 'deviceOrientation') {
expect(['portrait', 'landscape']).toContain(value);
}
}
});
});
......@@ -28,8 +28,11 @@
</view>
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<button type="primary" @tap="getSystemInfo">
获取设备系统信息
<button type="primary" @tap="getSystemInfoSync">
同步获取设备系统信息
</button>
<button type="primary" @tap="getSystemInfo" style="margin-top: 20px;">
异步获取设备系统信息
</button>
</view>
</view>
......@@ -54,23 +57,41 @@ export default {
onUnload: function () {
},
methods: {
getSystemInfo: function () {
getSystemInfo: function () {
uni.getSystemInfo({
success: (res) => {
//类型对象暂时不支持forin或Object.keys(), 临时通过字符串进行转化。
const json = JSON.stringify(res);
const result = JSON.parse<Map<string, any>>(json);
this.items = [] as Item[];
result?.forEach((value, key) => {
const item = {
label: key,
value: "" + value
} as Item;
this.items.push(item);
})
success: (res) => {
this.items = [] as Item[];
for(const key in res){
const value = res[key];
if(value != null){
const item = {
label: key,
value: "" + ((typeof value == "object")? JSON.stringify(value) : value)
} as Item;
this.items.push(item);
}
}
},
})
}
},
getSystemInfoSync: function () {
this.items = [] as Item[];
const res = uni.getSystemInfoSync()
for(const key in res){
const value = res[key];
if(value != null){
const item = {
label: key,
value: "" + ((typeof value == "object")? JSON.stringify(value) : value)
} as Item;
this.items.push(item);
}
}
},
//自动化测试例专用
jest_getSystemInfo():GetSystemInfoResult{
return uni.getSystemInfoSync();
},
}
}
</script>
......
const PAGE_PATH = '/pages/API/get-system-setting/get-system-setting'
describe('ExtApi-GetSystemSetting', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await uni.getSystemSetting()
});
it('Check GetSystemSetting', async () => {
for (const key in res) {
const value = res[key];
if (res['bluetoothEnabled'] == undefined) {
expect(res['bluetoothError']).not.toBe("")
} else {
expect(res['bluetoothError'] == undefined).toBe(true)
}
if (res['wifiEnabled'] == undefined) {
expect(res['wifiError']).not.toBe("")
} else {
expect(res['wifiError'] == undefined).toBe(true)
}
if (key == 'deviceOrientation') {
expect(['portrait', 'landscape']).toContain(value);
}
}
});
});
......@@ -61,9 +61,9 @@
getSystemSetting: function () {
const res = uni.getSystemSetting();
this.bluetoothEnabled = (res.bluetoothEnabled ?? false) ? "开启" : "关闭";
this.locationEnabled = (res.locationEnabled ?? false) ? "开启" : "关闭";
this.locationEnabled = res.locationEnabled ? "开启" : "关闭";
this.wifiEnabled = (res.wifiEnabled ?? false) ? "开启" : "关闭";
this.deviceOrientation = res.deviceOrientation ?? "";
this.deviceOrientation = res.deviceOrientation
}
}
}
......
const PAGE_PATH = '/pages/API/get-window-info/get-window-info'
describe('ExtApi-GetWindowInfo', () => {
let page;
let res;
const numberProperties = [
'pixelRatio', 'screenWidth', 'screenHeight', 'statusBarHeight',
'windowWidth',
'windowHeight', 'windowTop', 'windowBottom', 'screenTop'
]
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
res = await page.callMethod('jest_getWindowInfo')
});
it('Check GetWindowInfo', async () => {
for (const key in res) {
const value = res[key];
expect(value).not.toBeNull();
if (numberProperties.indexOf(key) != -1) {
expect(value).toBeGreaterThanOrEqual(0);
}
}
});
});
......@@ -37,18 +37,22 @@
methods: {
getWindowInfo: function () {
const res = uni.getWindowInfo();
//类型对象暂时不支持forin或Object.keys(), 临时通过字符串进行转化。
const json = JSON.stringify(res);
const result = JSON.parse<Map<string, any>>(json);
this.items = [] as Item[];
result?.forEach((value, key) => {
const item = {
label: key,
value: "" + value
} as Item;
this.items.push(item);
})
}
this.items = [] as Item[];
for(const key in res){
const value = res[key];
if(value != null){
const item = {
label: key,
value: "" + ((typeof value == "object")? JSON.stringify(value) : value)
} as Item;
this.items.push(item);
}
}
},
//自动化测试例专用
jest_getWindowInfo():GetWindowInfoResult{
return uni.getWindowInfo();
},
}
}
</script>
......
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-list">
<view class="uni-list-cell uni-list-cell-pd">
<view class="uni-list-cell-db">是否显示透明蒙层-屏蔽点击事件</view>
<switch :checked="maskSelect" @change="maskChange" />
</view>
<view class="uni-padding-wrap">
<view class="uni-title uni-common-mt">
<text class="uni-title-text"> 设置标题 </text>
</view>
</view>
<view class="uni-list uni-common-pl">
<radio-group @change="radioChange" class="radio-group">
<radio class="uni-list-cell uni-list-cell-pd radio" v-for="(item, index) in items" :key="item.value"
:class="index < items.length - 1 ? 'uni-list-cell-line' : ''" :value="item.value"
:checked="index === current">
{{ item.name }}
</radio>
</radio-group>
</view>
</view>
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<button class="uni-btn-v" type="primary" @click="showLoading">显示 loading 提示框</button>
<!-- #ifndef MP-ALIPAY -->
<button class="uni-btn-v" @click="hideLoading">隐藏 loading 提示框</button>
<!-- #endif -->
</view>
</view>
</view>
</template>
<script lang="uts">
type ItemType = {
value : string
name : string
}
export default {
data() {
return {
title: 'loading',
items: [
{
value: 'null',
name: '无标题',
},
{
value: '三秒后自动关闭',
name: '普通标题',
},
{
value: '超长文本内容,测试超出范围-超长文本内容,测试超出范围-三秒后自动关闭',
name: '长标题',
},
] as ItemType[],
current: 0,
maskSelect: false,
titleSelect: "null"
}
},
methods: {
radioChange(e : RadioGroupChangeEvent) {
const selected = this.items.find((item) : boolean => {
return item.value == e.detail.value
})
if (selected != null) {
this.titleSelect = selected.value
}
},
maskChange: function (e : SwitchChangeEvent) {
this.maskSelect = e.detail.value
},
showLoading: function () {
console.log(this.titleSelect)
if (this.titleSelect == "null") {
uni.showLoading({
title: "",
mask: this.maskSelect
});
} else {
uni.showLoading({
title: this.titleSelect,
mask: this.maskSelect
});
}
// #ifdef MP-ALIPAY
this._showTimer && clearTimeout(this._showTimer);
this._showTimer = setTimeout(() => {
this.hideLoading();
}, 3000)
// #endif
// #ifdef APP-PLUS
setTimeout(function () {
this.hideLoading();
}, 3000);
// #endif
},
hideLoading: function () {
uni.hideLoading();
}
}
// #ifdef MP-ALIPAY
,
onUnload() {
// 页面卸载的时候,手动关闭loading
this._showTimer && clearTimeout(this._showTimer);
}
// #endif
}
</script>
\ No newline at end of file
jest.setTimeout(30000)
const PAGE_PATH = '/pages/API/navigator/new-page/new-page-2'
const INTERMEDIATE_PAGE_PATH = '/pages/API/navigator/navigator'
let page
......
......@@ -12,7 +12,7 @@
</template>
<script lang="uts">
import { State, state, setLifeCycleNum } from '@/store/index.uts'
import { state, setLifeCycleNum } from '@/store/index.uts'
export default {
data() {
......@@ -20,7 +20,7 @@ export default {
isScrolled: false,
}
},
onLoad(_ : OnLoadOptions) {
onLoad(_ : Map<string, string>) {
// 自动化测试
setLifeCycleNum(state.lifeCycleNum + 100)
},
......@@ -77,7 +77,7 @@ export default {
},
scrollToBottom() {
uni.pageScrollTo({
scrollTop: 2000,
scrollTop: 2000
})
},
},
......
......@@ -39,24 +39,51 @@
</template>
<script>
type NodeInfoType = {
left : number | null,
top : number | null,
right : number | null,
bottom : number | null,
width : number | null,
height : number | null,
}
export default {
data() {
return {
title: 'createSelectorQuery',
nodeInfoList: [] as NodeInfo[],
nodeInfoList: [] as NodeInfoType[],
}
},
methods: {
getNodeInfo() {
uni.createSelectorQuery().select('.rect1').boundingClientRect().exec((ret) => {
this.nodeInfoList.length = 0
this.nodeInfoList.push(ret[0] as NodeInfo)
const i = ret[0] as NodeInfo
this.nodeInfoList.push({
left: i.left,
top: i.top,
right: i.right,
bottom: i.bottom,
width: i.width,
height: i.height,
} as NodeInfoType)
})
},
getAllNodeInfo() {
uni.createSelectorQuery().selectAll('.rect').boundingClientRect().exec((ret) => {
this.nodeInfoList.length = 0
this.nodeInfoList.push(...(ret[0] as NodeInfo[]))
const array = ret[0] as NodeInfo[]
array.forEach((i) => {
this.nodeInfoList.push({
left: i.left,
top: i.top,
right: i.right,
bottom: i.bottom,
width: i.width,
height: i.height,
} as NodeInfoType)
})
})
}
}
......@@ -110,4 +137,4 @@
font-weight: bold;
line-height: 2;
}
</style>
</style>
\ No newline at end of file
......@@ -6,22 +6,23 @@ describe('page-scroll-to', () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
})
// TODO
it('scroll-to', async () => {
const btnScrollTo = await page.$('.btn-scrollTo')
await btnScrollTo.tap()
await page.waitFor(50)
// const scrollTop = await page.scrollTop()
// expect(scrollTop).toBe(100)
await page.waitFor(300)
const scrollTop = await page.scrollTop()
expect(scrollTop).toBe(100)
})
// it('scroll-to-element', async () => {
// const btnScrollTo = await page.$('.btn-scrollToElement')
// const scrollToElement = await page.$('.custom-element')
it('scroll-to-element', async () => {
const btnScrollTo = await page.$('.btn-scrollToElement')
const scrollToElement = await page.$('.custom-element')
await btnScrollTo.tap()
await page.waitFor(300)
// await btnScrollTo.tap()
// await page.waitFor(50)
// const offset = await scrollToElement.offset()
// expect(offset.top).toBe(0)
// })
})
\ No newline at end of file
const offset = await scrollToElement.offset()
expect(offset.top >= 1188).toBe(true)
})
})
......@@ -27,7 +27,7 @@
<!-- #endif -->
</template>
<script lang="uts">
<script>
export default {
data() {
return {
......
const PAGE_PATH = '/pages/API/request/request'
const methodMap = {
"GET": "/api/http/method/get",
"POST": "/api/http/method/post",
"PUT": "/api/http/method/put",
"DELETE": "/api/http/method/delete",
"PATCH": "/api/http/method/patch",
"OPTIONS": "/api/http/method/options",
"HEAD": "/api/http/method/head"
}
async function request(page, method, header, data, url) {
if (url == null) {
url = methodMap[method]
}
await page.setData({
url: url,
method: method,
data: data,
header: header
})
res = await page.callMethod('jest_request')
await page.waitFor(200);
res = await page.data('jest_result');
expect(res).toBe(true)
}
describe('ExtApi-Request', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
});
beforeEach(async () => {
await page.setData({
jest_result: false,
data: null,
header: null
})
});
it('Check GET', async () => {
await request(page, 'GET');
});
it('Check POST ContentType Json', async () => {
await request(page, 'POST', {
"Content-Type": "application/json"
}, {
"hello": "world"
}, "/api/http/contentType/json");
});
it('Check POST ContentType Form', async () => {
await request(page, 'POST', {
"Content-Type": "application/x-www-form-urlencoded"
}, "hello=world", "/api/http/contentType/xWwwFormUrlencoded");
});
it('Check PUT', async () => {
await request(page, 'PUT');
});
it('Check DELETE', async () => {
await request(page, 'DELETE');
});
it('Check PATCH', async () => {
await request(page, 'PATCH');
});
it('Check OPTIONS', async () => {
await request(page, 'OPTIONS');
});
it('Check HEAD', async () => {
await request(page, 'HEAD');
});
});
<template>
<view style="flex: 1;">
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-textarea uni-common-mt" style="border-width: 2rpx;border-radius: 4rpx;">
<textarea :value="res"></textarea>
</view>
<view>
<text>地址 : {{ host + url}}</text>
<text>请求方式 : {{method}}</text>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="sendRequest">发起请求</button>
</view>
</view>
<scroll-view style="flex: 1;" show-scrollbar="true">
<view style="padding: 20rpx;">
<text>设置请求方式</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('GET')">GET</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('POST')">POST</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PUT')">PUT</button>
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('DELETE')">DELETE</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PATCH')">PATCH</button>
<button style="padding: 5rpx;margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('OPTIONS')">OPTIONS</button>
<button style="padding: 5rpx;" type="primary" size="mini"
@click="changeMethod('HEAD')">HEAD</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求返回错误码的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in errorCodeUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求不同header的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in headerUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求不同content-type的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in contentTypeUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="flex: 1;">
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-common-mt" style="border-width: 2rpx;border-radius: 4rpx;">
<textarea :value="res" class="uni-textarea"></textarea>
</view>
<view>
<text>地址 : {{ host + url}}</text>
<text>请求方式 : {{method}}</text>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="sendRequest">发起请求</button>
</view>
</view>
<scroll-view style="flex: 1;" show-scrollbar="true">
<view style="padding: 20rpx;">
<text>设置请求方式</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('GET')">GET</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('POST')">POST</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PUT')">PUT</button>
<button style="padding: 5rpx; margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('DELETE')">DELETE</button>
<button style="padding: 5rpx; margin-right: 10rpx; " type="primary" size="mini"
@click="changeMethod('PATCH')">PATCH</button>
<button style="padding: 5rpx;margin-right: 10rpx;" type="primary" size="mini"
@click="changeMethod('OPTIONS')">OPTIONS</button>
<button style="padding: 5rpx;" type="primary" size="mini" @click="changeMethod('HEAD')">HEAD</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求返回错误码的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in errorCodeUrls" :key="index"
@click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求不同header的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in headerUrls" :key="index"
@click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>请求不同content-type的接口(默认为GET)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in contentTypeUrls"
:key="index" @click="changeUrl(item)">{{item}}</button>
</view>
</view>
<view style="padding: 20rpx;">
<text>POST请求(有body)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in postUrls"
:key="index" @click="changeUrlFromPost(item)">{{item}}</button>
</view>
</view>
</scroll-view>
</view>
<view style="padding: 20rpx;">
<text>POST请求(有body)</text>
<view class="uni-common-pb"></view>
<view style="flex-direction: row;flex-wrap: wrap;">
<button style="padding: 5rpx;" type="primary" size="mini" v-for="(item, index) in postUrls" :key="index"
@click="changeUrlFromPost(item)">{{item}}</button>
</view>
</view>
</scroll-view>
</view>
</template>
<script>
import RequestTask from 'uts.sdk.modules.DCloudUniNetwork.RequestTask';
const duration = 2000
const methodMap = {
"GET": "/api/http/method/get",
"POST": "/api/http/method/post",
"PUT": "/api/http/method/put",
"DELETE": "/api/http/method/delete",
"PATCH": "/api/http/method/patch",
"OPTIONS": "/api/http/method/options",
"HEAD": "/api/http/method/head"
}
const duration = 2000
const methodMap = {
"GET": "/api/http/method/get",
"POST": "/api/http/method/post",
"PUT": "/api/http/method/put",
"DELETE": "/api/http/method/delete",
"PATCH": "/api/http/method/patch",
"OPTIONS": "/api/http/method/options",
"HEAD": "/api/http/method/head"
}
export default {
data() {
return {
title: 'request',
res: '',
task: null as RequestTask | null,
pageVisible: false,
host: "http://request.dcloud.net.cn",
url: "/api/http/method/get",
method: "GET",
data: null as any | null,
header: null as UTSJSONObject | null,
errorCodeUrls: [
"/api/http/statusCode/200",
"/api/http/statusCode/204",
"/api/http/statusCode/301",
"/api/http/statusCode/302",
"/api/http/statusCode/307",
"/api/http/statusCode/400",
"/api/http/statusCode/401",
"/api/http/statusCode/403",
"/api/http/statusCode/404",
"/api/http/statusCode/405",
"/api/http/statusCode/500",
"/api/http/statusCode/502",
"/api/http/statusCode/503",
"/api/http/statusCode/504",
],
headerUrls: [
"/api/http/header/ua",
"/api/http/header/referer",
"/api/http/header/requestCookie",
"/api/http/header/setCookie",
"/api/http/header/deleteCookie"
],
contentTypeUrls: [
"/api/http/contentType/text/plain",
"/api/http/contentType/text/html",
"/api/http/contentType/text/xml",
"/api/http/contentType/image/gif",
"/api/http/contentType/image/jpeg",
"/api/http/contentType/image/png",
"/api/http/contentType/application/json",
"/api/http/contentType/application/octetStream",
],
postUrls: [
"/api/http/contentType/json",
"/api/http/contentType/xWwwFormUrlencoded",
],
}
},
onLoad() {
this.pageVisible = true;
},
onUnload() {
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
},
methods: {
changeMethod(e : string) {
this.method = e;
this.url = methodMap[e] as string;
this.data = null;
this.header = null;
},
changeUrl(e : string) {
this.method = "GET";
this.url = e;
this.data = null;
this.header = null;
},
changeUrlFromPost(e : string) {
this.method = "POST";
this.url = e;
switch (e) {
case "/api/http/contentType/json":
this.header = {
"Content-Type": "application/json"
};
this.data = {
"hello": "world"
};
break;
case "/api/http/contentType/xWwwFormUrlencoded":
this.header = {
"Content-Type": "application/x-www-form-urlencoded"
};
this.data = "hello=world";
break;
}
},
sendRequest() {
uni.showLoading({
title: "请求中..."
})
this.task = uni.request({
url: this.host + this.url,
// dataType: "json",
// responseType: "json",
method: this.method,
data: this.data,
header: this.header,
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success(res) {
if (this.pageVisible) {
console.log('request success', JSON.stringify(res.data))
uni.showToast({
title: '请求成功',
icon: 'success',
mask: true,
duration: duration
});
this.res = '请求结果 : ' + JSON.stringify(res);
}
},
fail(err) {
if (this.pageVisible) {
console.log('request fail', err);
uni.showModal({
content: err.errMsg,
showCancel: false
});
}
},
complete() {
uni.hideLoading()
},
});
}
}
}
</script>
\ No newline at end of file
export default {
data() {
return {
title: 'request',
res: '',
task: null as RequestTask | null,
pageVisible: false,
host: "http://request.dcloud.net.cn",
url: "/api/http/method/get",
method: "GET" as RequestMethod | null,
data: null as any | null,
header: null as UTSJSONObject | null,
errorCodeUrls: [
"/api/http/statusCode/200",
"/api/http/statusCode/204",
"/api/http/statusCode/301",
"/api/http/statusCode/302",
"/api/http/statusCode/307",
"/api/http/statusCode/400",
"/api/http/statusCode/401",
"/api/http/statusCode/403",
"/api/http/statusCode/404",
"/api/http/statusCode/405",
"/api/http/statusCode/500",
"/api/http/statusCode/502",
"/api/http/statusCode/503",
"/api/http/statusCode/504",
],
headerUrls: [
"/api/http/header/ua",
"/api/http/header/referer",
"/api/http/header/requestCookie",
"/api/http/header/setCookie",
"/api/http/header/deleteCookie"
],
contentTypeUrls: [
"/api/http/contentType/text/plain",
"/api/http/contentType/text/html",
"/api/http/contentType/text/xml",
"/api/http/contentType/image/gif",
"/api/http/contentType/image/jpeg",
"/api/http/contentType/image/png",
"/api/http/contentType/application/json",
"/api/http/contentType/application/octetStream",
],
postUrls: [
"/api/http/contentType/json",
"/api/http/contentType/xWwwFormUrlencoded",
],
//自动化测试例专用
jest_result: false
}
},
onLoad() {
this.pageVisible = true;
},
onUnload() {
this.pageVisible = false;
uni.hideLoading();
this.task?.abort();
},
methods: {
changeMethod(e : RequestMethod) {
this.method = e;
this.url = methodMap[e] as string;
this.data = null;
this.header = null;
},
changeUrl(e : string) {
this.method = "GET";
this.url = e;
this.data = null;
this.header = null;
},
changeUrlFromPost(e : string) {
this.method = "POST";
this.url = e;
switch (e) {
case "/api/http/contentType/json":
this.header = {
"Content-Type": "application/json"
};
this.data = {
"hello": "world"
};
break;
case "/api/http/contentType/xWwwFormUrlencoded":
this.header = {
"Content-Type": "application/x-www-form-urlencoded"
};
this.data = "hello=world";
break;
}
},
sendRequest() {
uni.showLoading({
title: "请求中..."
})
this.task = uni.request({
url: this.host + this.url,
// dataType: "json",
// responseType: "json",
method: this.method,
data: this.data,
header: this.header,
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success(res) {
if (this.pageVisible) {
console.log('request success', JSON.stringify(res.data))
uni.showToast({
title: '请求成功',
icon: 'success',
mask: true,
duration: duration
});
this.res = '请求结果 : ' + JSON.stringify(res);
}
},
fail(err) {
if (this.pageVisible) {
console.log('request fail', err);
uni.showModal({
content: err.errMsg,
showCancel: false
});
}
},
complete() {
uni.hideLoading()
},
});
},
//自动化测试例专用
jest_request() {
uni.request({
url: this.host + this.url,
// dataType: "json",
// responseType: "json",
method: this.method,
data: this.data,
header: this.header,
timeout: 6000,
sslVerify: false,
withCredentials: false,
firstIpv4: false,
success() {
this.jest_result = true;
},
fail() {
this.jest_result = false;
},
});
}
}
}
</script>
const CURRENT_PAGE_PATH =
"/pages/API/set-navigation-bar-color/set-custom-navigation-bar-color";
describe("setCustomNavigationBarColor", () => {
let page;
let originLifeCycleNum;
beforeAll(async () => {
page = await program.navigateTo(CURRENT_PAGE_PATH);
await page.waitFor(1000);
originLifeCycleNum = await page.callMethod("getLifeCycleNum");
});
afterAll(async () => {
await page.callMethod("setLifeCycleNum", originLifeCycleNum);
const lifeCycleNum = await page.callMethod("getLifeCycleNum");
expect(lifeCycleNum).toBe(originLifeCycleNum);
});
it("setNavigationBarColor2", async () => {
await page.callMethod("setNavigationBarColor2");
const image = await program.screenshot({adb: true, area:{x:1000, y: 0, width: 80, height: 88}});
expect(image).toMatchImageSnapshot();
});
it("setNavigationBarColor1", async () => {
await page.callMethod("setNavigationBarColor1");
const image = await program.screenshot({adb: true, area:{x:1000, y: 0, width: 80, height: 88}});
expect(image).toMatchImageSnapshot();
});
});
<template>
<view>
<view class="custom-navigation">
<text
class="back-icon"
@click="back"
:style="`color:${navigationBarTextColor}`"
>{{ backIcon }}</text
>
<text class="title" :style="`color:${navigationBarTextColor}`"
>自定义导航栏</text
>
</view>
<page-head title="setCustomNavigationBarColor"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="setNavigationBarColor1" class="uni-btn">
设置自定义导航栏前景色白色
</button>
<button @tap="setNavigationBarColor2" class="uni-btn">
设置自定义导航栏前景色黑色
</button>
</view>
</view>
</template>
<script lang="uts">
import { state, setLifeCycleNum } from '@/store/index.uts'
export default {
data() {
return {
backIcon: '\ue582',
navigationBarTextColor: '#fff'
}
},
onShow(){
uni.loadFontFace({
family: 'UniFontFamily',
source: 'static/font/uni.ttf'
})
},
methods: {
back(){
uni.navigateBack()
},
setNavigationBarColor1() {
uni.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: '#0000',
success() {
this.navigationBarTextColor = '#fff'
console.log('setNavigationBarColor success')
},
fail() {
console.log('setNavigationBarColor success')
},
complete() {
console.log('setNavigationBarColor success')
}
})
},
setNavigationBarColor2() {
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#0000',
success() {
this.navigationBarTextColor = '#000'
console.log('setNavigationBarColor success')
},
fail() {
console.log('setNavigationBarColor success')
},
complete() {
console.log('setNavigationBarColor success')
}
})
},
// 自动化测试
getLifeCycleNum(): number {
return state.lifeCycleNum
},
// 自动化测试
setLifeCycleNum(num: number) {
setLifeCycleNum(num)
},
},
}
</script>
<style>
.custom-navigation {
padding-top: 40px;
padding-bottom: 10px;
background-color: #007aff;
}
.custom-navigation > .title {
margin: 0 auto;
}
.custom-navigation > .back-icon {
position: absolute;
font-family: UniFontFamily;
font-size: 20px;
left: 10px;
}
</style>
......@@ -4,7 +4,6 @@ const CURRENT_PAGE_PATH =
describe('setNavigationBarColor', () => {
let page
let originLifeCycleNum
let lifeCycleNum
beforeAll(async () => {
page = await program.navigateTo(CURRENT_PAGE_PATH)
await page.waitFor(1000)
......@@ -13,7 +12,7 @@ describe('setNavigationBarColor', () => {
afterAll(async () => {
await page.callMethod('setLifeCycleNum', originLifeCycleNum)
lifeCycleNum = await page.callMethod('getLifeCycleNum')
const lifeCycleNum = await page.callMethod('getLifeCycleNum')
expect(lifeCycleNum).toBe(originLifeCycleNum)
})
......
......@@ -8,19 +8,17 @@
<button @tap="setNavigationBarColor2" class="uni-btn">
设置导航条背景红色,标题黑色
</button>
<button @tap="goCustomNavigation" class="uni-btn">
跳转自定义导航栏页面
</button>
</view>
</view>
</template>
<script lang="uts">
import { State, state, setLifeCycleNum } from '@/store/index.uts'
import { state, setLifeCycleNum } from '@/store/index.uts'
export default {
data() {
return {
_state: state as State
}
},
methods: {
setNavigationBarColor1() {
uni.setNavigationBarColor({
......@@ -28,36 +26,30 @@ export default {
backgroundColor: '#00ff00',
success() {
console.log('setNavigationBarColor success')
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail() {
console.log('setNavigationBarColor success')
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete() {
console.log('setNavigationBarColor success')
setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
setNavigationBarColor2() {
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#ff0000',
success() {
console.log('setNavigationBarColor success')
setLifeCycleNum(state.lifeCycleNum + 1)
},
fail() {
console.log('setNavigationBarColor success')
setLifeCycleNum(state.lifeCycleNum - 1)
},
complete() {
console.log('setNavigationBarColor success')
setLifeCycleNum(state.lifeCycleNum + 1)
}
})
},
setNavigationBarColor2() {
uni.setNavigationBarColor({
frontColor: '#000000',
backgroundColor: '#ff0000',
success() {
console.log('setNavigationBarColor success')
},
fail() {
console.log('setNavigationBarColor success')
},
complete() {
console.log('setNavigationBarColor success')
}
})
},
// 自动化测试
getLifeCycleNum(): number {
return state.lifeCycleNum
......@@ -66,6 +58,11 @@ export default {
setLifeCycleNum(num: number) {
setLifeCycleNum(num)
},
goCustomNavigation(){
uni.navigateTo({
url: '/pages/API/set-navigation-bar-color/set-custom-navigation-bar-color'
})
}
},
}
</script>
......
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-list">
<view class="uni-list-cell uni-list-cell-pd">
<view class="uni-list-cell-db">是否显示透明蒙层-屏蔽点击事件</view>
<switch :checked="maskSelect" @change="maskChange"/>
</view>
<view class="uni-padding-wrap">
<view class="uni-title uni-common-mt">
<text class="uni-title-text"> 设置标题 </text>
</view>
</view>
<view class="uni-list uni-common-pl">
<radio-group @change="radioChange" class="radio-group">
<radio
class="uni-list-cell uni-list-cell-pd radio"
v-for="(item, index) in items"
:key="item.value"
:class="index < items.length - 1 ? 'uni-list-cell-line' : ''"
:value="item.value"
:checked="index === current"
>
{{ item.name }}
</radio>
</radio-group>
</view>
</view>
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<button class="uni-btn-v" type="primary" @click="showLoading">显示 loading 提示框</button>
<!-- #ifndef MP-ALIPAY -->
<button class="uni-btn-v" @click="hideLoading">隐藏 loading 提示框</button>
<!-- #endif -->
</view>
</view>
</view>
</template>
<script lang="uts">
type ItemType = {
value: string
name: string
}
export default {
data() {
return {
title: 'loading',
items: [
{
value: 'null',
name: '无标题',
},
{
value: '三秒后自动关闭',
name: '普通标题',
},
{
value: '超长文本内容,测试超出范围-超长文本内容,测试超出范围-三秒后自动关闭',
name: '长标题',
},
] as ItemType[],
current: 0,
maskSelect:false,
titleSelect:"null"
}
},
methods: {
radioChange(e: RadioGroupChangeEvent) {
const selected = this.items.find((item): boolean => {
return item.value == e.detail.value
})
if(selected != null){
this.titleSelect = selected!!.value
}
},
maskChange: function (e : SwitchChangeEvent) {
this.maskSelect = e.detail.value
},
showLoading: function() {
console.log(this.titleSelect)
if(this.titleSelect == "null"){
// 测试空的情况 todo
uni.showLoading({
title: "",
mask:this.maskSelect
});
}else{
uni.showLoading({
title: this.titleSelect,
mask:this.maskSelect
});
}
// #ifdef MP-ALIPAY
this._showTimer && clearTimeout(this._showTimer);
this._showTimer = setTimeout(() => {
this.hideLoading();
}, 3000)
// #endif
// #ifdef APP-PLUS
setTimeout(function() {
this.hideLoading();
}, 3000);
// #endif
},
hideLoading: function() {
uni.hideLoading();
}
}
// #ifdef MP-ALIPAY
,
onUnload() {
// 页面卸载的时候,手动关闭loading
this._showTimer && clearTimeout(this._showTimer);
}
// #endif
}
</script>
\ No newline at end of file
const PAGE_PATH = '/pages/API/storage/storage'
describe('ExtApi-StorageInfoTest', () => {
let page;
function getData(key = '') {
return new Promise(async (resolve, reject) => {
const data = await page.data()
resolve(key ? data[key] : data)
})
}
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
});
it('Check async properties', async () => {
// 异步存储测试
await page.setData({
key: "autotest_key_mock",
data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。"
})
await page.waitFor(600)
const btnSetStorageButtonInfo = await page.$('.btn-setstorageAsync')
await btnSetStorageButtonInfo.tap()
await page.waitFor(600)
const btnGetStorageButtonInfo = await page.$('.btn-getstorageAsync')
await btnGetStorageButtonInfo.tap()
await page.waitFor(600)
expect(await getData('apiGetData')).toEqual("长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。")
await page.setData({
key: "autotest_key_mock",
data:1100.8989
})
await page.waitFor(600)
await btnSetStorageButtonInfo.tap()
await page.waitFor(600)
await btnGetStorageButtonInfo.tap()
await page.waitFor(600)
expect(await getData('apiGetData')).toEqual(1100.8989)
await page.setData({
key: "autotest_key_mock",
data:123456789
})
await page.waitFor(600)
await btnSetStorageButtonInfo.tap()
await page.waitFor(600)
await btnGetStorageButtonInfo.tap()
await page.waitFor(600)
expect(await getData('apiGetData')).toEqual(123456789)
let userObj = {
name:"zhangsan",
age:12
}
await page.setData({
key: "autotest_key_mock",
data:userObj
})
await page.waitFor(600)
await btnSetStorageButtonInfo.tap()
await page.waitFor(600)
await btnGetStorageButtonInfo.tap()
await page.waitFor(600)
expect(await getData('apiGetData')).toEqual(userObj)
await page.setData({
key: "autotest_key_mock",
data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。"
})
await page.waitFor(600)
const btnSetStorageButtonInfo2 = await page.$('.btn-setstorageSync')
await btnSetStorageButtonInfo2.tap()
await page.waitFor(600)
const btnGetStorageButtonInfo2 = await page.$('.btn-getstorageSync')
await btnGetStorageButtonInfo2.tap()
await page.waitFor(600)
expect(await getData('apiGetData')).toEqual("长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。")
});
it('Check sync properties', async () => {
await page.setData({
key: "autotest_key_mock",
data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。"
})
await page.waitFor(600)
const btnSetStorageButtonInfo = await page.$('.btn-setstorageSync')
await btnSetStorageButtonInfo.tap()
await page.waitFor(600)
const btnGetStorageButtonInfo = await page.$('.btn-getstorageSync')
await btnGetStorageButtonInfo.tap()
await page.waitFor(600)
expect(await getData('apiGetData')).toEqual("长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。")
});
});
......@@ -84,12 +84,12 @@
<view class="uni-btn-v">
<button
type="primary"
class="uni-btn btn-setstorage"
class="uni-btn btn-setstorageAsync"
@tap="setStorage"
>
存储数据-异步
</button>
<button class="uni-btn" @tap="getStorage">读取数据-异步</button>
<button class="uni-btn btn-getstorageAsync" @tap="getStorage">读取数据-异步</button>
<button class="uni-btn" @tap="removeStorage">移除数据-异步</button>
<button class="uni-btn" @tap="clearStorage">清理数据-异步</button>
</view>
......@@ -97,12 +97,12 @@
<view class="uni-btn-v">
<button
type="primary"
class="uni-btn btn-setstorage"
class="uni-btn btn-setstorageSync"
@tap="setStorageSync"
>
存储数据-同步
</button>
<button class="uni-btn" @tap="getStorageSync">读取数据-同步</button>
<button class="uni-btn btn-getstorageSync" @tap="getStorageSync">读取数据-同步</button>
<button class="uni-btn" @tap="removeStorageSync">
移除数据-同步
</button>
......@@ -123,7 +123,8 @@ export default {
return {
title: 'get/set/clearStorage',
key: '',
data: '' as any,
data: '' as any,
apiGetData:'' as any|null,
storageInfo: '',
}
},
......@@ -189,13 +190,15 @@ export default {
content: 'key 不能为空',
showCancel: false,
})
} else {
} else {
let that = this
uni.getStorage({
key: key,
success: (res) => {
success: (res) => {
that.apiGetData = res.data
uni.showModal({
title: '读取数据成功',
content: "data: '" + res.data + "'",
content: "data: '" + JSON.stringify(that.apiGetData) + "'",
showCancel: false,
})
},
......@@ -218,10 +221,10 @@ export default {
showCancel: false,
})
} else {
let ret = uni.getStorageSync(key)
this.apiGetData = uni.getStorageSync(key)
uni.showModal({
title: '读取数据成功',
content: "data: '" + ret + "'",
content: "data: '" + JSON.stringify(apiGetData) + "'",
showCancel: false,
})
}
......
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<button class="uni-btn-v" type="default" @tap="toast1Tap">点击弹出默认toast</button>
<button class="uni-btn-v" type="default" @tap="toastTapIconError">点击弹出设置icon的toast</button>
<button class="uni-btn-v" type="default" @tap="toast2Tap">点击弹出设置duration的toast</button>
<button class="uni-btn-v" type="default" @tap="toast3Tap">点击弹出显示loading的toast</button>
<!-- #ifndef MP-ALIPAY -->
<button class="uni-btn-v" type="default" @tap="toast4Tap">点击弹出显示自定义图片的toast</button>
<!-- #endif -->
<!-- #ifdef APP-PLUS -->
<button class="uni-btn-v" type="default" @tap="toast5Tap">点击显示无图标的居底toast</button>
<!-- #endif -->
<button class="uni-btn-v" type="default" @tap="hideToast">点击隐藏toast</button>
</view>
<text>{{exeRet}}</text>
</view>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap">
<view class="uni-btn-v">
<button class="uni-btn-v" type="default" @tap="toast1Tap">点击弹出默认toast</button>
<button class="uni-btn-v" type="default" @tap="toastTapIconError">点击弹出设置icon的toast</button>
<button class="uni-btn-v" type="default" @tap="toast2Tap">点击弹出设置duration的toast</button>
<button class="uni-btn-v" type="default" @tap="toast3Tap">点击弹出显示loading的toast</button>
<!-- #ifndef MP-ALIPAY -->
<button class="uni-btn-v" type="default" @tap="toast4Tap">点击弹出显示自定义图片的toast</button>
<!-- #endif -->
<!-- #ifdef APP-PLUS -->
<button class="uni-btn-v" type="default" @tap="toast5Tap">点击显示无图标的居底toast</button>
<!-- #endif -->
<button class="uni-btn-v" type="default" @tap="hideToast">点击隐藏toast</button>
</view>
<text>{{exeRet}}</text>
</view>
</view>
</template>
<script lang="uts">
export default {
data() {
return {
title: 'toast',
exeRet:'',
_showTimer: 0
}
},
// #ifdef MP-ALIPAY
onUnload() {
clearTimeout(this._showTimer);
},
// #endif
methods: {
toast1Tap: function () {
uni.showToast({
title: "默认",
success:function(res){
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail:function(res){
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
toastTapIconError: function () {
uni.showToast({
title: "默认",
icon:'error',
success:function(res){
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail:function(res){
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
toast2Tap: function () {
uni.showToast({
title: "duration 3000",
duration: 3000,
success:function(res){
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail:function(res){
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
toast3Tap: function () {
uni.showToast({
title: "loading",
icon: "loading",
duration: 5000,
success:function(res){
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail:function(res){
this.exeRet = "fail:" + JSON.stringify(res)
},
})
// #ifdef MP-ALIPAY
this._showTimer = setTimeout(() => {
// icon 是 loading 时,showToast 实际执行的是 showLoading
my.hideLoading()
// 执行完所有代码再清除定时器
clearTimeout(this._showTimer);
}, 3000)
// #endif
},
toast4Tap: function () {
uni.showToast({
title: "logo",
image: "/static/uni.png",
success:function(res){
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail:function(res){
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
// #ifdef APP-PLUS
toast5Tap: function () {
uni.showToast({
title: "显示一段轻提示",
position: 'bottom',
success:function(res){
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail:function(res){
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
// #endif
hideToast: function () {
uni.hideToast()
}
}
export default {
data() {
return {
title: 'toast',
exeRet: ''
}
},
methods: {
toast1Tap: function () {
uni.showToast({
title: "默认",
success: function (res) {
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail: function (res) {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
toastTapIconError: function () {
uni.showToast({
title: "默认",
icon: 'error',
success: function (res) {
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail: function (res) {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
toast2Tap: function () {
uni.showToast({
title: "duration 3000",
duration: 3000,
success: function (res) {
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail: function (res) {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
toast3Tap: function () {
uni.showToast({
title: "loading",
icon: "loading",
duration: 5000,
success: function (res) {
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail: function (res) {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
toast4Tap: function () {
uni.showToast({
title: "logo",
image: "/static/uni.png",
success: function (res) {
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail: function (res) {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
// #ifdef APP-PLUS
toast5Tap: function () {
uni.showToast({
title: "显示一段轻提示",
position: 'bottom',
success: function (res) {
this.exeRet = "success:" + JSON.stringify(res) + new Date()
},
fail: function (res) {
this.exeRet = "fail:" + JSON.stringify(res)
},
})
},
// #endif
hideToast: function () {
uni.hideToast()
}
}
</script>
\ No newline at end of file
}
</script>
const PAGE_PATH = '/pages/API/unicloud-call-function/unicloud-call-function'
describe('unicloud-call-function', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
await page.setData({
isUniTest: true
})
})
it('callFunction', async () => {
await page.callMethod('callFunction')
await page.waitFor(3000)
const {
callFunctionResult,
callFunctionError
} = await page.data()
console.error(callFunctionResult)
console.error(callFunctionError)
expect(callFunctionResult['showMessage']).toBe("Hello uniCloud function")
expect(callFunctionResult['event']['num']).toBe(1)
expect(callFunctionResult['event']['str']).toBe('ABC')
})
})
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
......@@ -10,7 +10,7 @@
</view>
</view>
</view>
<!-- #ifdef APP -->
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
......@@ -18,14 +18,33 @@
export default {
data() {
return {
title: 'uniCloud.callFunction'
title: '请求云函数',
callFunctionResult: {},
callFunctionError: {},
isUniTest: false
}
},
onLoad() {
},
onUnload() {
if(this.isUniTest){
uni.hideToast()
}
},
methods: {
notify(content : string, title : string) {
if (!this.isUniTest) {
uni.showModal({
title,
content,
showCancel: false
})
} else {
uni.showToast({
title: content
})
}
},
callFunction: function () {
uni.showLoading({
title: '加载中...'
......@@ -35,24 +54,21 @@
data: {
num: 1,
str: 'ABC'
} as UTSJSONObject
}
}).then<void>(res => {
const result = res.result
this.callFunctionResult = result
console.log(JSON.stringify(result))
uni.hideLoading()
uni.showModal({
title: '提示',
content: result['showMessage'] as string,
showCancel: false
})
}).catch<void>((err: any | null) => {
this.notify(result['showMessage'] as string, '提示')
}).catch<void>((err : any | null) => {
const error = err as UniCloudError
this.callFunctionError = {
errCode: error.errCode,
errMsg: error.errMsg
}
uni.hideLoading()
uni.showModal({
title: '错误',
content: error.errMsg,
showCancel: false
})
this.notify(error.errMsg, '错误')
})
}
}
......@@ -60,4 +76,4 @@
</script>
<style>
</style>
</style>
\ No newline at end of file
const PAGE_PATH = '/pages/API/unicloud-database/unicloud-database'
describe('unicloud-database', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
await page.setData({
isUniTest: true
})
})
it('databaseBasic', async () => {
await page.callMethod('dbRemove')
await page.waitFor(3000)
await page.callMethod('dbAdd')
await page.waitFor(1500)
await page.callMethod('dbBatchAdd')
await page.waitFor(1500)
await page.callMethod('dbGet')
await page.waitFor(1500)
await page.callMethod('dbGetWithCommand')
await page.waitFor(1500)
await page.callMethod('dbUpdate')
await page.waitFor(1500)
await page.callMethod('dbRemove')
await page.waitFor(1500)
const {
addId,
batchAddIds,
batchAddinserted,
updateUpdated,
getData,
getWithCommandData,
removeDeleted,
} = await page.data()
expect(addId !== '').toBe(true)
expect(batchAddIds.length).toBe(2)
expect(batchAddinserted).toBe(2)
expect(getData.length).toBe(2)
expect(getWithCommandData.length).toBe(1)
expect(updateUpdated).toBe(3)
expect(removeDeleted).toBe(3)
})
it('databaseLookup', async () => {
await page.callMethod('dbLookupInit')
await page.waitFor(3000)
await page.callMethod('dbLookup')
await page.waitFor(1500)
const {
lookupData
} = await page.data()
expect(lookupData.length).toBe(2)
expect(lookupData[0]['foreign_id'].length).toBe(1)
expect(lookupData[1]['foreign_id'].length).toBe(1)
})
});
\ No newline at end of file
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="dbAdd">新增单条数据</button>
<button type="primary" @click="dbBatchAdd">新增多条数据</button>
<button type="primary" @click="dbUpdate">更新数据</button>
<button type="primary" @click="dbGet">where传字符串获取数据</button>
<button type="primary" @click="dbGetWithCommand">where传对象获取数据</button>
<button type="primary" @click="dbRemove">删除数据</button>
<button type="primary" @click="dbLookupInit">初始化联表查询数据</button>
<button type="primary" @click="dbLookup">联表查询</button>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: 'ClientDB',
addId: '',
batchAddIds: [] as Array<string>,
batchAddinserted: 0,
updateUpdated: 0,
getData: [] as Array<UTSJSONObject>,
getWithCommandData: [] as Array<UTSJSONObject>,
removeDeleted: 0,
lookupData: [] as Array<UTSJSONObject>,
isUniTest: false
}
},
onLoad() {
},
onUnload() {
if(this.isUniTest){
uni.hideToast()
}
},
methods: {
notify(content : string, title : string) {
if (!this.isUniTest) {
uni.showModal({
title,
content,
showCancel: false
})
} else {
uni.showToast({
title: content
})
}
},
dbAdd: function () {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.add({
num: 1,
tag: 'default-tag',
date: new Date(),
point: new db.Geo.Point(116, 38)
})
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.addId = res.id
this.notify(`新增成功,id: ${res.id}`, '提示')
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
this.notify(error.errMsg, '错误')
})
},
dbBatchAdd() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.add([{
num: 2,
tag: 'default-tag',
}, {
num: 3,
tag: 'default-tag',
}])
.then<void>((res) => {
uni.hideLoading()
console.log(res)
console.log('JSON.stringify(res.inserted)', JSON.stringify(res.inserted))
this.batchAddIds = res.ids
this.batchAddinserted = res.inserted
this.notify(`新增成功条数${res.inserted}, id列表: ${res.ids.join(',')}`, '提示')
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
this.notify(error.errMsg, '错误')
})
},
dbGet() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where(
'tag == "default-tag"'
)
.field('num, tag')
.orderBy('num desc')
.skip(1)
.limit(2)
.get()
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.getData = res.data
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
this.notify(error.errMsg, '错误')
})
},
dbGetWithCommand() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where({
num: db.command.gt(1)
})
.field('num, tag')
.orderBy('num desc')
.skip(1)
.limit(2)
.get()
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.getWithCommandData = res.data
this.notify(`获取成功,取到了${res.data.length}条数据`, '提示')
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
this.notify(error.errMsg, '错误')
})
},
dbUpdate() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where(
'tag == "default-tag"'
)
.update({
num: 4
})
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.updateUpdated = res.updated
this.notify(`更新成功,更新了${res.updated}条数据`, '提示')
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
this.notify(error.errMsg, '错误')
})
},
dbRemove() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('type')
.where(
'tag == "default-tag"'
)
.remove()
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.removeDeleted = res.deleted
this.notify(`删除成功,删掉了${res.deleted}条数据`, '提示')
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
this.notify(error.errMsg, '错误')
})
},
dbLookupInit() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
db.collection('local')
.where('tag == "default-tag"')
.remove()
.then(() : Promise<UniCloudDBRemoveResult> => {
return db.collection('foreign')
.where('tag == "default-tag"')
.remove()
})
.then(() : Promise<UniCloudDBBatchAddResult> => {
return db.collection('local')
.add([{
id: "local_1",
name: "local_1_name",
tag: "default-tag",
foreign_id: "foreign_1"
}, {
id: "local_2",
name: "local_2_name",
tag: "default-tag",
foreign_id: "foreign_2"
}])
})
.then(() : Promise<UniCloudDBBatchAddResult> => {
return db.collection('foreign')
.add([{
id: "foreign_1",
name: "foreign_1_name",
tag: "default-tag"
}, {
id: "foreign_2",
name: "foreign_2_name",
tag: "default-tag"
}])
})
.then<void>((_) : void => {
uni.hideLoading()
this.notify('数据初始化成功', '提示')
})
.catch<void>((err : any | null) => {
uni.hideLoading()
console.error(err)
const error = err as UniCloudError
this.notify(error.errMsg, '错误')
})
},
dbLookup() {
uni.showLoading({
title: '加载中...'
})
const db = uniCloud.databaseForJQL()
const local = db.collection('local')
.where('tag == "default-tag"')
.getTemp()
const foreign = db.collection('foreign')
.where('tag == "default-tag"')
.getTemp()
db.collection(local, foreign)
.get()
.then<void>(res => {
uni.hideLoading()
console.log(res)
this.lookupData = res.data
this.notify(`联表查询成功,取到了${res.data.length}条数据`, '提示')
})
.catch<void>((err : any | null) => {
uni.hideLoading()
const error = err as UniCloudError
this.notify(error.errMsg, '错误')
})
}
}
}
</script>
<style>
</style>
\ No newline at end of file
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<button type="primary" @click="uploadFile">选择文件上传</button>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: '云存储'
}
},
onLoad() {
},
onUnload() {
},
methods: {
uploadFile: function () {
uni.chooseImage({
count: 1,
success(res) : void {
uni.showLoading({
title: '上传中...'
})
const tempFilePath = res.tempFilePaths[0]
uniCloud.uploadFile({
filePath: tempFilePath,
cloudPath: 'test.jpg'
})
.then<void>(function (res) {
uni.hideLoading()
console.log(res)
uni.showModal({
content: '上传成功',
showCancel: false
});
})
.catch<void>(function (err : any | null) {
uni.hideLoading()
const error = err as UniCloudError
uni.showModal({
content: '上传失败,' + error.errMsg,
showCancel: false
});
})
// .finally((_: number) : void => {
// uni.hideLoading()
// })
},
fail(err) : void {
console.error('chooseImage fail: ', err)
}
})
}
}
}
</script>
<style>
</style>
\ No newline at end of file
const PAGE_PATH = '/pages/API/unicloud-import-object/unicloud-import-object'
describe('unicloud-import-object', () => {
let page
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
await page.setData({
isUniTest: true
})
})
it('importObject', async () => {
await page.callMethod('addTodo')
await page.callMethod('fail')
await page.callMethod('success')
await page.waitFor(3000)
const {
todoTitle,
todoContent,
returnTodoTitle,
returnTodoContent,
failErrCode,
successErrCode,
} = await page.data()
expect(returnTodoTitle).toBe(todoTitle)
expect(returnTodoContent).toBe(todoContent)
expect(failErrCode).toBe('TEST_ERROR_CODE')
expect(successErrCode).toBe(0)
})
});
\ No newline at end of file
<template>
<!-- #ifdef APP -->
<scroll-view style="flex:1">
<!-- #endif -->
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="addTodo">添加Todo</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="randomFail">随机触发失败重试</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="fail">云对象失败调用</button>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="success">云对象成功调用</button>
</view>
</view>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
title: '请求云对象',
todoTitle: '学习编程',
todoContent: '熟悉uts语法',
returnTodoTitle: '',
returnTodoContent: '',
failErrCode: '',
successErrCode: -1,
isUniTest: false
}
},
onUnload() {
if(this.isUniTest){
uni.hideToast()
}
},
methods: {
notify(content : string, title : string) {
if (!this.isUniTest) {
uni.showModal({
title,
content,
showCancel: false
})
} else {
uni.showToast({
title: content
})
}
},
addTodo() {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
const title = this.todoTitle
const content = this.todoContent
todo.add(title, content).then<void>((res : UTSJSONObject) : void => {
this.returnTodoTitle = res['title'] as string
this.returnTodoContent = res['content'] as string
this.notify(res['showMessage'] as string, '提示')
}).catch<void>((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
})
},
randomFail() {
const todoObj = uniCloud.importObject('todo', {
errorOptions: {
retry: true
}
})
todoObj.randomFail().then<void>((res : UTSJSONObject) : void => {
this.notify(res['showMessage'] as string, '提示')
}).catch<void>((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
})
},
fail() {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
todo.fail().then<void>((res : UTSJSONObject) : void => {
this.notify('todo.fail应调用失败,此处错误的触发了成功回调', '错误')
console.log('todo.fail: ', res);
}).catch<void>((err : any | null) : void => {
const error = err as UniCloudError
this.failErrCode = error.errCode as string
console.error(error)
if (this.isUniTest) {
uni.showToast({
title: err.errMsg
})
}
})
},
success() {
const todo = uniCloud.importObject('todo', {
customUI: this.isUniTest
})
todo.success().then<void>((res : UTSJSONObject) : void => {
this.successErrCode = res['errCode'] as number
this.notify(res['showMessage'] as string, '提示')
}).catch<void>((err : any | null) : void => {
const error = err as UniCloudError
console.error(error)
})
}
}
}
</script>
<style>
</style>
\ No newline at end of file
const PAGE_PATH = '/pages/API/upload-file/upload-file'
describe('ExtApi-UploadFile', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_uploadFile');
await page.waitFor(500);
res = await page.data('jest_result');
});
it('Check ', async () => {
expect(res).toBe(true);
});
});
......@@ -23,14 +23,15 @@
<!-- #endif -->
</template>
<script>
import UploadTask from 'uts.sdk.modules.DCloudUniNetwork.UploadTask';
export default {
data() {
return {
title: 'uploadFile',
imageSrc: '',
task: null as UploadTask | null,
pageVisible: false
pageVisible: false,
//自动化测试例专用
jest_result:false,
}
},
onLoad() {
......@@ -53,7 +54,7 @@ export default {
var imageSrc = res.tempFilePaths[0]
uni.showLoading({
title: '上传中'
})
})
this.task = uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc,
......@@ -89,7 +90,25 @@ export default {
console.log('chooseImage fail', err)
}
})
}
},
//自动化测试例专用
jest_uploadFile(){
const imageSrc = "/static/uni.png";
this.task = uni.uploadFile({
url: 'https://unidemo.dcloud.net.cn/upload', //仅为示例,非真实的接口地址
filePath: imageSrc,
name: 'file',
formData: {
'user': 'test'
},
success: () => {
this.jest_result = true;
},
fail: () => {
this.jest_result = false;
},
})
}
}
}
</script>
......
......@@ -137,7 +137,7 @@ export default {
uni.sendSocketMessage({
data:
'from ' +
platform +
this.platform +
' : ' +
parseInt((Math.random() * 10000).toString()).toString(),
success(res: any) {
......
const PAGE_PATH = '/pages/API/websocket-socketTask/websocket-socketTask'
describe('ExtApi-WebSocket', () => {
let page;
let res;
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600);
await page.callMethod('jest_connectSocket');
await page.waitFor(500);
res = await page.data('jest_result');
});
it('Check ', async () => {
expect(res).toBe(2);
});
});
......@@ -35,7 +35,9 @@ export default {
socketTask: null as SocketTask | null,
msg: '',
platform: '',
pageVisible: false,
pageVisible: false,
//自动化测试例专用
jest_result: 0,
}
},
computed: {
......@@ -135,16 +137,16 @@ export default {
}
})
},
send() {
send() {
const data =
'from ' +
platform +
this.platform +
' : ' +
parseInt(Math.random() * 10000 + '').toString()
this.socketTask?.send({
data,
success(res: any) {
console.log(res)
console.log(res)
},
fail(err: any) {
console.log(err)
......@@ -162,7 +164,38 @@ export default {
console.log('uni.closeSocket fail', err)
},
} as CloseSocketOptions)
},
},
//自动化测试例专用
jest_connectSocket(){
this.socketTask = uni.connectSocket({
url: 'ws://websocket.dcloud.net.cn',
success:(_) => {
this.jest_result++
},
fail:(_) => {
this.jest_result = 0
},
})
this.socketTask?.onOpen((_) => {
const data =
'from ' +
this.platform +
' : ' +
parseInt(Math.random() * 10000 + '').toString()
this.socketTask?.send({
data,
success(_) {
this.jest_result++
},
fail(_) {
this.jest_result = 0
},
} as SendSocketMessageOptions)
})
this.socketTask?.onError((_) => {
this.jest_result = 0;
})
}
},
}
</script>
......
<template>
<view style="flex-grow: 1;">
<view>
<text>border-bottom: 10rpx dashed blue</text>
<view class="common" style="border-bottom: 10rpx dashed blue;"></view>
</view>
</view>
</template>
<script>
</script>
<style>
.common {
width: 500rpx;
height: 500rpx;
background-color: gray;
}
</style>
\ No newline at end of file
......@@ -7,7 +7,7 @@
<text>border-color: red</text>
<view
class="common"
style="border-width: 10rpx; border-color: red"
style="border-width: 10rpx; border-color: red; border-style: solid;"
></view>
</view>
......@@ -15,7 +15,7 @@
<text>border-left-color: red</text>
<view
class="common"
style="border-left-width: 10rpx; border-left-color: red"
style="border-left-width: 10rpx; border-left-color: red; border-left-style:solid;"
></view>
</view>
......@@ -23,7 +23,7 @@
<text>border-top-color: green</text>
<view
class="common"
style="border-top-width: 10rpx; border-top-color: green"
style="border-top-width: 10rpx; border-top-color: green; border-top-style: solid;"
></view>
</view>
......@@ -31,7 +31,7 @@
<text>border-right-color: yellow</text>
<view
class="common"
style="border-right-width: 10rpx; border-right-color: yellow"
style="border-right-width: 10rpx; border-right-color: yellow; border-right-style: solid;"
></view>
</view>
......@@ -39,7 +39,7 @@
<text>border-bottom-color: blue</text>
<view
class="common"
style="border-bottom-width: 10rpx; border-bottom-color: blue"
style="border-bottom-width: 10rpx; border-bottom-color: blue; border-bottom-style: solid; "
></view>
</view>
</view>
......
<template>
<view style="flex-grow: 1;">
<view>
<text>border-left: 10rpx solid blue</text>
<view class="common" style="border-left: 10rpx solid blue;"></view>
</view>
</view>
</template>
<script>
</script>
<style>
.common {
width: 500rpx;
height: 500rpx;
background-color: gray;
}
</style>
\ No newline at end of file
<template>
<view style="flex-grow: 1;">
<view>
<text>border-right: 10rpx solid blue</text>
<view class="common" style="border-right: 10rpx solid blue;"></view>
</view>
</view>
</template>
<script>
</script>
<style>
.common {
width: 500rpx;
height: 500rpx;
background-color: gray;
}
</style>
\ No newline at end of file
<template>
<view style="flex-grow: 1;">
<view>
<text>border-top: 10rpx dashed blue</text>
<view class="common" style="border-top: 10rpx dashed blue;"></view>
</view>
</view>
</template>
<script>
</script>
<style>
.common {
width: 500rpx;
height: 500rpx;
background-color: gray;
}
</style>
\ No newline at end of file
......@@ -5,27 +5,27 @@
<view style="flex-grow: 1">
<view>
<text>border-width: 10rpx</text>
<view class="common" style="border-width: 10rpx"></view>
<view class="common" style="border-width: 10rpx; border-style: solid;"></view>
</view>
<view>
<text>border-left-width: 10rpx</text>
<view class="common" style="border-left-width: 10rpx"></view>
<view class="common" style="border-left-width: 10rpx; border-left-style: solid; "></view>
</view>
<view>
<text>border-top-width: 20rpx</text>
<view class="common" style="border-top-width: 20rpx"></view>
<view class="common" style="border-top-width: 20rpx; border-top-style: solid; "></view>
</view>
<view>
<text>border-right-width: 30rpx</text>
<view class="common" style="border-right-width: 30rpx"></view>
<view class="common" style="border-right-width: 30rpx; border-right-style: solid; "></view>
</view>
<view>
<text>border-bottom-width: 40rpx</text>
<view class="common" style="border-bottom-width: 40rpx"></view>
<view class="common" style="border-bottom-width: 40rpx; border-bottom-style: solid; "></view>
</view>
</view>
<!-- #ifdef APP -->
......
......@@ -33,7 +33,8 @@
width: 250rpx;
height: 250rpx;
background-color: #00dd00;
border-width: 20rpx;
border-width: 20rpx;
border-style: solid;
border-color: #000000;
border-bottom-width: 40rpx;
border-bottom-color: #ff0000;
......@@ -45,7 +46,8 @@
.border-rect {
width: 250rpx;
height: 250rpx;
height: 250rpx;
border-style: solid;
background-color: #00dd00;
border-width: 20rpx;
border-color: #000000;
......@@ -53,4 +55,4 @@
border-bottom-color: #ff0000;
border-right-color: #FFDC02;
}
</style>
\ No newline at end of file
</style>
......@@ -24,7 +24,7 @@
methods: {
changeZIndex(zIndex : number) {
this.zIndex = 20;
(this.$refs['view'] as INode).style.setProperty('z-index', zIndex);
(this.$refs['view'] as Element).style.setProperty('z-index', zIndex);
}
}
}
......
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<!-- #endif -->
<view>
<view class="container">
<text class="text">点击修改宽度</text>
<view
class="base-style transition-width"
:style="widthOrHeight"
@click="changeWidthOrHeight"
></view>
<view class="base-style transition-width" id="widthOrHeight" @click="changeWidthOrHeight"></view>
</view>
<view class="container">
<text class="text">点击修改Margin</text>
<view
class="base-style transition-margin"
:style="styleMargin"
@click="changeMargin"
></view>
<view class="base-style transition-margin" id="styleMargin" @click="changeMargin"></view>
</view>
<view class="container">
<text class="text">点击修改Padding</text>
<view
class="base-style transition-padding"
:style="stylePadding"
@click="changePadding"
>
<view
style="background-color: black; height: 50px; width: 50px"
></view>
<view class="base-style transition-padding" id="stylePadding" @click="changePadding">
<view style="background-color: black; height: 50px; width: 50px"></view>
</view>
</view>
<view class="container">
<text class="text">点击修改Background</text>
<view
class="base-style transition-background"
:style="styleBackground"
@click="changeBackground"
></view>
<view class="base-style transition-background" id="styleBackground" @click="changeBackground"></view>
</view>
<view class="container">
<text class="text">点击修改Transform</text>
<view
class="base-style transition-transform"
:style="styleTransform"
@click="changeTransform"
></view>
<view class="base-style transition-transform" id="styleTransform" @click="changeTransform"></view>
</view>
<view class="container">
<text class="text">点击修改Border</text>
<view
class="base-style transition-border"
:style="styleBorder"
@click="changeBorder"
></view>
<view class="base-style transition-border" id="styleBorder" @click="changeBorder"></view>
</view>
<view class="container">
<text class="text">点击修改Position</text>
<view
class="base-style transition-position"
:style="stylePosition"
@click="changestylePosition"
></view>
<view class="base-style transition-position" id="stylePosition" @click="changestylePosition"></view>
</view>
</view>
<!-- #ifdef APP -->
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
isTranstionWidthOrHeight: false,
widthOrHeight: '',
isTranstionChangeMargin: false,
styleMargin: '',
isTransitionStylePadding: false,
stylePadding: '',
isTransitionstyleBackground: false,
styleBackground: '',
isTransitionStyleTransform: false,
styleTransform: '',
isTransitionstyleBorder: false,
styleBorder: '',
isTransitionstylePosition: false,
stylePosition: '',
}
},
methods: {
changeWidthOrHeight() {
this.widthOrHeight = this.isTranstionWidthOrHeight
? 'width:400rpx'
: 'width:600rpx'
this.isTranstionWidthOrHeight = !this.isTranstionWidthOrHeight
export default {
data() {
return {
isTranstionWidthOrHeight: false,
widthOrHeight: null as Element | null,
isTranstionChangeMargin: false,
styleMargin: null as Element | null,
isTransitionStylePadding: false,
stylePadding: null as Element | null,
isTransitionstyleBackground: false,
styleBackground: null as Element | null,
isTransitionStyleTransform: false,
styleTransform: null as Element | null,
isTransitionstyleBorder: false,
styleBorder: null as Element | null,
isTransitionstylePosition: false,
stylePosition: null as Element | null,
}
},
changeMargin() {
this.styleMargin = this.isTranstionChangeMargin
? 'margin-top:0rpx;margin-left:0rpx'
: 'margin-top:100rpx;margin-left:100rpx'
this.isTranstionChangeMargin = !this.isTranstionChangeMargin
onReady() {
this.widthOrHeight = uni.getElementById("widthOrHeight")
this.styleMargin = uni.getElementById("styleMargin")
this.stylePadding = uni.getElementById("stylePadding")
this.styleBackground = uni.getElementById("styleBackground")
this.styleTransform = uni.getElementById("styleTransform")
this.styleBorder = uni.getElementById("styleBorder")
this.stylePosition = uni.getElementById("stylePosition")
},
methods: {
changeWidthOrHeight() {
this.widthOrHeight?.style?.setProperty("width", this.isTranstionWidthOrHeight
? '400rpx'
: '600rpx')
this.isTranstionWidthOrHeight = !this.isTranstionWidthOrHeight
},
changeMargin() {
this.styleMargin?.style?.setProperty("margin-top", this.isTranstionChangeMargin
? '0rpx'
: '100rpx'
)
this.styleMargin?.style?.setProperty("margin-left", this.isTranstionChangeMargin
? '0rpx'
: '100rpx'
)
this.isTranstionChangeMargin = !this.isTranstionChangeMargin
},
changePadding() {
this.stylePadding = this.isTransitionStylePadding
? 'padding-top:0rpx;padding-left:0rpx'
: 'padding-top:100rpx;padding-left:100rpx'
this.isTransitionStylePadding = !this.isTransitionStylePadding
},
changeBackground() {
this.styleBackground = this.isTransitionstyleBackground
? 'background-color: brown;opacity:1'
: 'background-color: black;opacity:0.5'
this.isTransitionstyleBackground = !this.isTransitionstyleBackground
},
changeTransform() {
this.styleTransform = this.isTransitionStyleTransform
? 'transform: rotate(0deg)'
: 'transform: rotate(135deg)'
this.isTransitionStyleTransform = !this.isTransitionStyleTransform
changePadding() {
this.stylePadding?.style?.setProperty("padding-top", this.isTransitionStylePadding
? '0rpx'
: '100rpx')
this.stylePadding?.style?.setProperty("padding-left", this.isTransitionStylePadding
? '0rpx'
: '100rpx')
this.isTransitionStylePadding = !this.isTransitionStylePadding
},
changeBackground() {
this.styleBackground?.style?.setProperty("background-color", this.isTransitionstyleBackground
? 'brown'
: 'black'
)
this.styleBackground?.style?.setProperty("opacity", this.isTransitionstyleBackground
? '1'
: '0.5'
)
this.isTransitionstyleBackground = !this.isTransitionstyleBackground
},
changeTransform() {
this.styleTransform?.style?.setProperty("transform", this.isTransitionStyleTransform
? 'rotate(0deg)'
: 'rotate(135deg)'
)
this.isTransitionStyleTransform = !this.isTransitionStyleTransform
},
changeBorder() {
this.styleBorder?.style?.setProperty("border-color", this.isTransitionstyleBorder
? 'brown'
: 'yellow'
)
this.isTransitionstyleBorder = !this.isTransitionstyleBorder
},
changestylePosition() {
this.stylePosition?.style?.setProperty("left", this.isTransitionstylePosition
? '0rpx'
: '150rpx'
)
this.isTransitionstylePosition = !this.isTransitionstylePosition
},
},
changeBorder() {
this.styleBorder = this.isTransitionstyleBorder
? 'border-color: brown;'
: 'border-color: yellow;'
this.isTransitionstyleBorder = !this.isTransitionstyleBorder
},
changestylePosition() {
this.stylePosition = this.isTransitionstylePosition
? 'left:0rpx'
: 'left:150rpx;'
this.isTransitionstylePosition = !this.isTransitionstylePosition
},
},
}
}
</script>
<style>
.container {
margin: 15rpx;
background-color: white;
}
.text {
margin-top: 20rpx;
margin-bottom: 32rpx;
}
.container {
margin: 15rpx;
background-color: white;
}
.text {
margin-top: 20rpx;
margin-bottom: 32rpx;
}
.base-style {
width: 400rpx;
height: 400rpx;
background-color: brown;
}
.base-style {
width: 400rpx;
height: 400rpx;
background-color: brown;
}
.transition-width {
transition-property: width;
transition-duration: 1000;
}
.transition-width {
transition-property: width;
transition-duration: 1000;
}
.transition-margin {
transition-property: margin-left, margin-top;
transition-duration: 1000;
}
.transition-margin {
transition-property: margin-left, margin-top;
transition-duration: 1000;
}
.transition-padding {
transition-property: padding-left, padding-top;
transition-duration: 1000;
}
.transition-padding {
transition-property: padding-left, padding-top;
transition-duration: 1000;
}
.transition-background {
transition-property: background-color, opacity;
transition-duration: 1000;
}
.transition-background {
transition-property: background-color, opacity;
transition-duration: 1000;
}
.transition-transform {
transition-property: transform;
transition-duration: 1000;
}
.transition-transform {
transition-property: transform;
transition-duration: 1000;
}
.transition-border {
border-width: 5px;
border-color: brown;
transition-property: border-color;
transition-duration: 1000;
}
.transition-border {
border-width: 5px;
border-color: brown;
border-style: solid;
transition-property: border-color;
transition-duration: 1000;
}
.transition-position {
transition-property: left;
transition-duration: 1000;
}
</style>
.transition-position {
transition-property: left;
transition-duration: 1000;
}
</style>
\ No newline at end of file
......@@ -69,7 +69,7 @@ export default {
},
methods: {
validateGeneralAttributes() {
const generalTarget = this.$refs.get('general-target') as INode
const generalTarget = this.$refs['general-target'] as Element
const generalId = generalTarget.getAttribute('id')
if (generalId != this.generalId) {
this.validateGeneralAttrText = '基础属性 id 验证失败'
......@@ -98,8 +98,8 @@ export default {
this.validateGeneralAttrText = '基础属性验证成功'
},
changeHeight(){
const generalTarget = this.$refs.get('general-target') as INode
generalTarget.style.set('height', '200px')
const generalTarget = this.$refs['general-target'] as Element
generalTarget.style.setProperty('height', '200px')
}
},
}
......
......@@ -32,7 +32,7 @@
},
{
src: '../../../static/Test-Image/Logo.png',
description: '本地相对路径忽略大小写'
description: '本地相对路径忽略大小写(需注意Android打包后无效)'
},
{
src: logo,
......@@ -43,7 +43,7 @@
src: 'file:///storage/emulated/0/Android/data/io.dcloud.uniappx/apps/__UNI__3584C99/www/static/test-image/logo.png',
// #endif
// TODO iOS发版时还需再补路径
description: '本地绝对路径file:///方式。需注意打包后包名appid匹配'
description: '本地绝对路径file://方式(需注意打包后包名appid匹配)'
},
{
src: 'testerror.jpg',
......
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('component-native-image', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/image/image');
await page.waitFor(600);
});
it('check_image_load', async () => {
expect(await page.data('loadError')).toBe(false)
});
it('check_image_load_url', async () => {
await page.setData({
loadError: false,
imageSrc: 'https://request.dcloud.net.cn/api/http/contentType/image/png'
})
await page.waitFor(300);
expect(await page.data('loadError')).toBe(false)
})
it('check_image_load_error', async () => {
await page.setData({
loadError: false,
imageSrc: 'testerror.jpg'
})
await page.waitFor(300);
expect(await page.data('loadError')).toBe(true)
})
});
......@@ -3,7 +3,7 @@
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-center" style="background:#FFFFFF;">
<image class="image" :fade-show="true" mode="widthFix" src="/static/test-image/logo.png" @error="error"
<image class="image" :fade-show="true" mode="widthFix" :src="imageSrc" @error="error"
@load="load"></image>
</view>
<view class="uni-btn-v">
......@@ -25,11 +25,14 @@
export default {
data() {
return {
title: 'image'
title: 'image',
imageSrc: "/static/test-image/logo.png",
loadError: false
}
},
methods: {
error(event : ImageErrorEvent) {
error(event : ImageErrorEvent) {
this.loadError = true
console.log(event.type, event.detail);
},
load(event : ImageLoadEvent) {
......@@ -63,4 +66,4 @@
margin: 40rpx auto;
width: 200rpx;
}
</style>
\ No newline at end of file
</style>
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('component-native-input', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/input/input')
await page.waitFor(3000);
});
// it("beforeAllTestScreenshot", async () => {
// const image = await program.screenshot({
// fullPage: true
// })
// expect(image).toMatchImageSnapshot()
// })
// 测试焦点及键盘弹起
// it('focus', async () => {
// const input = await page.$('.uni-input-focus');
// expect(await input.property('focus')).toBe(true)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
// await page.setData({
// focus: false,
// })
// expect(await input.property('focus')).toBe(false)
// await page.waitFor(1000)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
// await page.setData({
// focus: true,
// })
// expect(await input.property('focus')).toBe(true)
// await page.waitFor(1000)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(true)
// await page.setData({
// focus: false,
// })
// expect(await input.property('focus')).toBe(false)
// await page.waitFor(1000)
// expect(await page.data("inputFocusKeyBoardChangeValue")).toBe(false)
// await page.waitFor(1000)
// });
// 测试修改value属性
it("value", async () => {
const input = await page.$('.uni-input-default');
expect(await input.property('value')).toEqual("hello uni-app x")
})
//测试input的类型
it("type", async () => {
const text = await page.$('.uni-input-type-text');
const number = await page.$('.uni-input-type-number');
const digit = await page.$('.uni-input-type-digit');
const tel = await page.$('.uni-input-type-tel');
expect(await text.property('type')).toEqual("text")
expect(await number.property('type')).toEqual("number")
expect(await digit.property('type')).toEqual("digit")
expect(await tel.property('type')).toEqual("tel")
})
// 测试密码属性
// it("password", async () => {
// const input = await page.$('.uni-input-password');
// expect(await input.property('password')).toBe(true)
// await page.setData({
// inputPassword: false,
// inputPasswordValue: "inputPasswordValue"
// })
// expect(await input.property('password')).toBe(false)
// await page.waitFor(500)
// await page.setData({
// inputPassword: true
// })
// })
// 测试placeholder
it("placeholder", async () => {
const placeholder1 = await page.$('.uni-input-placeholder1');
expect(await placeholder1.property("placeholder-style")).toMatchObject({
"color": "red"
})
expect(await placeholder1.property("placeholder")).toEqual("占位符文字颜色为红色")
await page.setData({
inputPlaceHolderStyle: "color:#CC00CC",
})
expect(await placeholder1.property("placeholder-style")).toMatchObject({
"color": "#CC00CC"
})
await page.setData({
inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0",
})
expect(await placeholder1.property("placeholder-style")).toMatchObject({
"color": "#CC19CC",
"backgroundColor": "#00b1c0"
})
await page.setData({
inputPlaceHolderStyle: "color:#CC19CC;background-color:#00b1c0;text-align:center;font-size:44px;font-weight:900",
})
expect(await placeholder1.property("placeholder-style")).toEqual({
"backgroundColor": "#00b1c0",
"color": "#CC19CC",
"fontSize": "44px",
"fontWeight": "900",
"textAlign": "center"
})
const placeholder2 = await page.$('.uni-input-placeholder2');
expect(await placeholder2.property("placeholder-class")).toMatchObject({
"backgroundColor": "#008000"
})
await page.setData({
inputPlaceHolderClass: "uni-input-placeholder-class-ts",
})
expect(await placeholder2.property("placeholder-class")).toMatchObject({
"backgroundColor": "#FFA500"
})
expect(await placeholder2.property("placeholder")).toEqual("占位符背景色为绿色")
})
it("disable", async () => {
const input = await page.$('.uni-input-disable');
expect(await input.property("disabled")).toBe(true)
})
it("confirm-type", async () => {
expect(await (await page.$('.uni-input-confirm-send')).property("confirmType")).toEqual("send")
expect(await (await page.$('.uni-input-confirm-search')).property("confirmType")).toEqual("search")
expect(await (await page.$('.uni-input-confirm-next')).property("confirmType")).toEqual("next")
expect(await (await page.$('.uni-input-confirm-go')).property("confirmType")).toEqual("go")
expect(await (await page.$('.uni-input-confirm-done')).property("confirmType")).toEqual("done")
})
// it("maxlength", async () => {
// const input = await page.$('.uni-input-maxlength');
// await page.setData({
// inputMaxLengthValue: "uni-input-maxlength"
// })
// await page.waitFor(500)
// })
// it("afterAllTestScreenshot", async () => {
// const image = await program.screenshot({
// fullPage: true
// })
// expect(image).toMatchImageSnapshot()
// })
});
此差异已折叠。
describe('component-native-list-view', () => {
let page
beforeAll(async () => {
//打开list-view测试页
page = await program.reLaunch('/pages/component/list-view/list-view')
await page.waitFor(600)
})
//检测竖向可滚动区域
it('check_scroll_height', async () => {
await page.callMethod('change_scroll_y_boolean', true)
await page.callMethod('change_scroll_x_boolean', false)
await page.waitFor(600)
const value = await page.callMethod('check_scroll_height')
expect(value).toBe(true)
})
//检测竖向scrolltop属性赋值
it('check_scroll_top', async () => {
await page.callMethod('confirm_scroll_top_input', 600)
await page.waitFor(600)
const listElement = await page.$('#listview')
const scrollTop = await listElement.attribute("scrollTop")
console.log("check_scroll_top---"+scrollTop)
expect(scrollTop-600).toBeGreaterThanOrEqual(0)
})
//检测竖向scroll_into_view属性赋值
it('check_scroll_into_view_top', async () => {
await page.callMethod('item_change_size_enum', 3)
await page.waitFor(600)
const listElement = await page.$('#listview')
const scrollTop = await listElement.attribute("scrollTop")
console.log("check_scroll_into_view_top--"+scrollTop)
await page.callMethod('item_change_size_enum', 0)
expect(scrollTop-690).toBeGreaterThanOrEqual(0)
})
//检测下拉刷新
it('check_refresher', async () => {
await page.setData({
refresher_enabled_boolean: true,
refresher_triggered_boolean: true
})
await page.waitFor(2000)
expect(await page.data('refresherrefresh')).toBe(true)
})
//检测横向可滚动区域
it('check_scroll_width', async () => {
await page.callMethod('change_scroll_y_boolean', false)
await page.callMethod('change_scroll_x_boolean', true)
await page.waitFor(600)
const value = await page.callMethod('check_scroll_width')
expect(value).toBe(true)
})
//检测横向scrollLeft属性赋值
it('check_scroll_left', async () => {
await page.callMethod('confirm_scroll_left_input', 600)
await page.waitFor(600)
const listElement = await page.$('#listview')
const scrollLeft = await listElement.attribute("scrollLeft")
console.log("check_scroll_left---"+scrollLeft)
expect(scrollLeft-600).toBeGreaterThanOrEqual(0)
})
//检测横向scroll_into_view属性赋值
it('check_scroll_into_view_left', async () => {
await page.callMethod('item_change_size_enum', 3)
await page.waitFor(600)
const listElement = await page.$('#listview')
const scrollLeft = await listElement.attribute("scrollLeft")
console.log("check_scroll_into_view_left--"+scrollLeft)
await page.callMethod('item_change_size_enum', 0)
expect(scrollLeft-1080).toBeGreaterThanOrEqual(0)
})
})
<template>
<!-- #ifdef APP -->
<scroll-view style="flex: 1">
<!-- #endif -->
<view class="article-content">
<text>{{content}}</text>
</view>
<!-- #ifdef APP -->
</scroll-view>
<!-- #endif -->
</template>
<script>
export default {
data() {
return {
content: "",
}
},
onLoad(event) {
this.content = event["content"] ?? "";
},
methods: {
}
}
</script>
<style>
.article-content {
padding: 0 30rpx;
overflow: hidden;
font-size: 30rpx;
margin-bottom: 30rpx;
}
</style>
\ No newline at end of file
此差异已折叠。
const PAGE_PATH = '/pages/component/navigator/navigator'
const PAGE_PATH_NAVIGATE = '/pages/component/navigator/navigate'
const PAGE_PATH_REDIRECT = '/pages/component/navigator/redirect'
describe('navigator', () => {
let page
beforeAll(async () => {})
it('navigate', async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
const btnNavigate = await page.$('.navigate')
await btnNavigate.tap()
await page.waitFor(100)
const currentPage = await program.currentPage()
expect(currentPage.path).toBe(PAGE_PATH_NAVIGATE.substring(1))
})
it('redirect', async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(500)
const btnRedirect = await page.$('.redirect')
await btnRedirect.tap()
await page.waitFor(100)
const currentPage = await program.currentPage()
expect(currentPage.path).toBe(PAGE_PATH_REDIRECT.substring(1))
})
})
......@@ -2,10 +2,10 @@
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<navigator class="navigator" url="navigate?title=navigate">
<navigator class="navigator navigate" url="navigate?title=navigate">
<button type="default">跳转到新页面</button>
</navigator>
<navigator class="navigator" url="redirect?title=redirect" open-type="redirect">
<navigator class="navigator redirect" url="redirect?title=redirect" open-type="redirect">
<button type="default">在当前页打开</button>
</navigator>
</view>
......
......@@ -15,7 +15,6 @@
</template>
<script>
import RefresherEvent from 'io.dcloud.uniapp.runtime.RefresherEvent';
import refreshBox from '../../template/custom-refresher/refresh-box/refresh-box.uvue';
export default {
components: { refreshBox },
......
此差异已折叠。
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
describe('test title', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/component/scroll-view/scroll-view-refresher');
await page.waitFor(300);
});
it('check_refresher', async () => {
await page.setData({
refresherTriggered: true
})
await page.waitFor(2000);
expect(await page.data('refresherrefresh')).toBe(true)
});
});
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册