提交 a89a5585 编写于 作者: study夏羽's avatar study夏羽

add jest

上级 5748d504
...@@ -2,3 +2,6 @@ ...@@ -2,3 +2,6 @@
/node_modules/ /node_modules/
/unpackage/ /unpackage/
/vue.config.js /vue.config.js
/coverage/
/android/
/mp-weixin/
## 1.3.4(2022-06-29)
新增:支持 ios 安全区
## 1.3.2(2022-06-28)
清除多余的:h5端运行的基础路径配置
## 1.3.1(2022-03-09) ## 1.3.1(2022-03-09)
修改错误的变量名称 修改错误的变量名称
## 1.3.0(2022-02-25) ## 1.3.0(2022-02-25)
......
module.exports = {
"compile": true,
"h5": {
"options": {
"headless": false
},
"executablePath": "C:/Program Files/Google/Chrome/Application/chrome.exe"
},
"mp-weixin": {
"executablePath": "C:/Users/liuxi/download/微信web开发者工具/cli.bat"
},
"mp-qq": {
"executablePath": ""
},
"mp-baidu": {
"executablePath": ""
},
"mp-toutiao": {
"executablePath": ""
},
"mp-alipay": {
"executablePath": ""
},
"mp-360": {
"executablePath": ""
},
"app-plus": {
"android": {
"executablePath": "D:\\HX\\alpha\\HBuilderX\\plugins\\launcher\\base\\android_base.apk",
"id": "a6160e9d"
},
"version": "D:\\HX\\alpha\\HBuilderX\\plugins\\launcher\\base\\version.txt",
"ios": {
"id": "",
"executablePath": ""
}
}
}
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<script> <script>
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') || var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
CSS.supports('top: constant(a)')) CSS.supports('top: constant(a)'))
......
module.exports = {
testEnvironmentOptions: {
compile: true,
h5: {
options: {
headless: false // 配置是否显示 puppeteer 测试窗口
}
},
"mp-weixin": {
port: 9420, // 默认 9420
account: "", // 测试账号
args: "", // 指定开发者工具参数cnpm
cwd: "", // 指定开发者工具工作目录
launch: true, // 是否主动拉起开发者工具
teardown: "disconnect", // 可选值 "disconnect"|"close" 运行测试结束后,断开开发者工具或关闭开发者工具
remote: false, // 是否真机自动化测试
executablePath: "C:/Users/liuxi/download/微信web开发者工具/cli.bat", // 开发者工具cli路径,默认会自动查找
},
"app-plus": { // 需要安装 HBuilderX
android: {
executablePath: "D:/HX/alpha/HBuilderX/plugins/launcher/base/android_base.apk" // apk 目录
},
/* ios: {
id: "",
executablePath: "HBuilderX/plugins/launcher/base/Pandora_simulator.app" // ipa 目录
} */
}
},
collectCoverage:true,
collectCoverageFrom: ["src/**/*.{js,vue}"],
testTimeout:10000,
reporters: [
'default'
],
watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'],
moduleFileExtensions: ['js', 'json'],
rootDir: __dirname,
testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)"],
testPathIgnorePatterns: ['/node_modules/','/js_sdk/validator/permission-test.js']
}
// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema?id=validatefunction // 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema?id=validatefunction
// 扩展校验函数示例 // 扩展校验函数示例
module.exports = function (rule, value, data, callback) { export default function (rule, value, data, callback) {
console.log('vvvvv',data); console.log('vvvvv',data);
if(data.type===0&&data.type_name.length>5){ if(data.type===0&&data.type_name.length>5){
callback('姓名不能超过5位数') callback('姓名不能超过5位数')
......
// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema?id=validatefunction // 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema?id=validatefunction
// 扩展校验函数示例 // 扩展校验函数示例
module.exports = function (rule, value, data, callback) { module.exports = function (rule, value, data, callback) {
...@@ -21,3 +22,4 @@ module.exports = function (rule, value, data, callback) { ...@@ -21,3 +22,4 @@ module.exports = function (rule, value, data, callback) {
} }
//} //}
} }
...@@ -4,7 +4,7 @@ import App from './App' ...@@ -4,7 +4,7 @@ import App from './App'
import Vue from 'vue' import Vue from 'vue'
Vue.config.productionTip = false Vue.config.productionTip = false
uni.showModal = ()=>{};
App.mpType = 'app' App.mpType = 'app'
const app = new Vue({ const app = new Vue({
......
{ {
"version": "1.2.3", "version": "1.2.5",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
......
{ {
"id": "uni-cloud", "id": "uni-cloud",
"displayName": "hello uniCloud", "displayName": "hello uniCloud",
"version": "1.3.4", "version": "1.3.1",
"description": "为开发者提供的基于 serverless 模式和 js 编程的云开发平台。示例代码", "description": "为开发者提供的基于 serverless 模式和 js 编程的云开发平台。示例代码",
"keywords": [ "keywords": [
"uniCloud示例" "uniCloud示例"
...@@ -62,8 +62,7 @@ ...@@ -62,8 +62,7 @@
"阿里": "u", "阿里": "u",
"百度": "u", "百度": "u",
"字节跳动": "u", "字节跳动": "u",
"QQ": "u", "QQ": "u"
"京东": "u"
}, },
"快应用": { "快应用": {
"华为": "u", "华为": "u",
...@@ -76,4 +75,4 @@ ...@@ -76,4 +75,4 @@
} }
} }
} }
} }
\ No newline at end of file
describe('pages/clientDB/clientDB-api/clientDB-api.nvue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/clientDB/clientDB-api/clientDB-api')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
})
beforeEach(async()=>{
jest.setTimeout(30000)
return false
})
it('查图书book表的数据', async () => {
expect.assertions(1);
const bookData = await page.callMethod('getData', 'book')
expect(bookData.length).toBe(4)
})
it('查订单order表的数据', async () => {
expect.assertions(1);
const orderData = await page.callMethod('getData', 'order')
expect(orderData.length).not.toBeUndefined();
})
it('分页查图书book表的数据', async () => {
//expect.assertions(1);
//获取页码
const numBox1 = await page.$('.num-box1')
const pageSize = await numBox1.property('value')
console.log("pageSize: ",pageSize);
//获取当前页
const numBox2 = await page.$('.num-box2')
const pageCurrent = await numBox2.property('value')
console.log("pageCurrent: ",pageCurrent);
if (pageSize === 1 && pageCurrent == 2) {
const orderData = await page.callMethod('getPageData', 'order')
expect(orderData.length).toBe(2)
}
//增加页码
const numBox1Add = await numBox1.$('.uni-numbox__plus')
await numBox1Add.tap()
await page.waitFor(1000)
const pageSizeAfter = await page.data('pageSize')
//增加每页查询数量
const numBox2Add = await numBox2.$('.uni-numbox__plus')
await numBox2Add.tap()
await page.waitFor(1000)
const pageCurrentAfter = await page.data('pageCurrent')
const bookData = await page.callMethod('getPageData')
})
it('联表查询订单和图书', async () => {
expect.assertions(1);
const orderBookData = await page.callMethod('getOrder')
expect(orderBookData.length).not.toBeUndefined();
})
it('查询一本图书数据', async () => {
const getOneBook = await page.callMethod('getOneBook')
expect(getOneBook).toEqual({
"_id": "1",
"author": "吴承恩",
"title": "西游记"
});
})
it('查询结果返回总数', async () => {
const getBookHasCount = await page.callMethod('getBookHasCount')
expect(getBookHasCount.count).toEqual(4)
})
it('仅查询图书数据的书名', async () => {
const getBookTitle = await page.callMethod('getBookTitle')
const aTitleRecord = {
_id: '1',
title: '西游记'
};
expect(getBookTitle).toContainEqual(aTitleRecord);
})
it('获得被设置别名的数据', async () => {
const getBookAs = await page.callMethod('getBookAs')
const aBookAsRecord = {
_id: '1',
title: '西游记',
book_author: '吴承恩'
};
expect(getBookAs).toContainEqual(aBookAsRecord);
})
it('按质量升序', async () => {
await page.waitFor(500)
const quantityData = await page.callMethod('getOrderOrderBy',
'quantity asc')
expect(quantityData.length).not.toBeUndefined();
})
it('按创建时间降序', async () => {
const createDateData = await page.callMethod('getOrderOrderBy',
'create_date desc')
expect(createDateData.length).not.toBeUndefined();
})
it('质量相同时,按创建时间降序', async () => {
const resData = await page.callMethod(
'getOrderOrderBy',
'quantity asc, create_date desc'
)
expect(resData.length).not.toBeUndefined();
})
it('查询树形数据', async () => {
const treeData = await page.callMethod('getTreeFn')
const children = treeData[0].children
expect(children).not.toBeUndefined();
})
})
describe('pages/clientDB/clientDB.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/clientDB/clientDB')
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000)
}
page = await program.currentPage()
})
beforeEach(async()=>{
jest.setTimeout(5000)
return false
})
it('当前页面-clientDB', async () => {
// await page.waitFor(1000)
//expect.assertions(2);
expect(await page.path).toBe('pages/clientDB/clientDB')
await page.waitFor(300)
const list = await page.$('uni-list')
console.log("list: ",list);
// if(list){
// const getList = await list.$$('.item')
// console.log("getList: ",getList);
// expect(getList.length).toBe(5)
// }
})
})
describe('pages/clientDB/demo/demo.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch(
'/pages/clientDB/demo/demo')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
// console.log("page-------------: ",page);
})
beforeEach(async()=>{
jest.setTimeout(30000)
return false
})
it('未登陆', async () => {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[0].tap()
await page.waitFor(2000)
const unLogin = await page.waitFor(async()=>{
const unLoginRole = await page.data('currentRole')
return unLoginRole === 0
})
console.log("unLogin: ",unLogin,unLogin === 0 );
const commentBtn = await page.$('.comment-btn')
// console.log(await commentBtn.text(),"text---------");
expect(await commentBtn.text()).toBe('写留言')
})
it('用户', async () => {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[1].tap()
const user = await page.waitFor(async()=>{
const userRole = await page.data('currentRole')
return userRole === 'user'
})
console.log("用户: ",user);
if(user){
//新增一条留言
const userWrite = await page.callMethod('submitComment', '我是用户')
const usId = userWrite.id
//expect(usId).not.toBeUndefined();
await page.waitFor(1000)
}
})
it('审核员', async () => {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[2].tap()
const auditor = await page.waitFor(async()=>{
const auditorRole = await page.data('currentRole')
return auditorRole === 'auditor'
})
console.log("审核员: ",auditor);
if(auditor){
//新增一条留言
const auditorWrite = await page.callMethod('submitComment', '我是审核员11')
const audId = auditorWrite.id
expect(audId).not.toBeUndefined();
await page.waitFor(1000)
// 审核一条为通过
await page.callMethod('updateState',
{
"detail": {
"value": true
},
},
audId
)
await page.waitFor(1000)
//审核员更改留言
const setUid = await page.setData({
"activeNoticeId":audId
})
const auditorUpdate = await page.callMethod('updateComment',
"我是审核员123"
)
await page.waitFor(1000)
}
})
it('管理员', async () => {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[3].tap()
const admin = await page.waitFor(async()=>{
const adminRole = await page.data('currentRole')
return adminRole === 'admin'
})
// await page.setData({'currentRole':'admin'})
// const adminRole = await page.data('currentRole')
console.log("管理员: ",admin);
if(admin){
//管理员写入一条留言
const adminWrite = await page.callMethod('submitComment','我是管理员')
var admId = adminWrite.id
expect(admId).not.toBeUndefined();
await page.waitFor(1000)
// 审核一条为通过
await page.callMethod('updateState',
{
"detail": {
"value": true
},
},
admId
)
await page.waitFor(1000)
//审核一条为拒绝
const adminRefuse = await page.callMethod('updateState',
{
"detail": {
"value": false
},
},
admId
)
//管理员删除创建的这条留言 弹框无法操作,点击确定才能删除
await page.callMethod('clickIcon',
1,
{
"state": 0,
"text": "我是管理员",
"_id": admId
}
)
}
})
})
<template> <template>
<view class="page"> <view class="page">
<uniNoticeBar v-if="noticeData.data" showIcon="true" :text="noticeData.data"></uniNoticeBar> <uniNoticeBar v-if="noticeData.data" showIcon="true" :text="noticeData.data"></uniNoticeBar>
......
describe('pages/clientDB/permission-demo/permission-demo.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch(
'/pages/clientDB/permission-demo/permission-demo')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(2000)
}
page = await program.currentPage()
})
beforeEach(async()=>{
jest.setTimeout(30000)
return false
})
it('未登陆', async () => {
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus" ) {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[0].tap()
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
const perPage = await page.$('.page')
const setPer = await perPage.$('set-permission')
//底部角色控制条
const roles = await setPer.$$('.roles-item')
//点击创建
await roles[0].tap()
await page.waitFor(500)
}
const unlogin = await page.waitFor(async()=>{
const unloginRole = await page.data('rulo_index')
return unloginRole === 0
})
const getData = await page.data('formData')
})
it('用户', async () => {
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[1].tap()
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(500)
const perPage = await page.$('.page')
const setPer = await perPage.$('set-permission')
//底部角色控制条
const roles = await setPer.$$('.roles-item')
//点击创建
await roles[1].tap()
}
const user = await page.waitFor(async()=>{
const userRole = await page.data('rulo_index')
//console.log("userRole: ",userRole);
return userRole === 1
})
console.log("user: ",user);
if(user){
//更新一条数据
const setDataA = await page.setData({
"formData": {
"_id": "60200c3554a29f0001d14586",
"nickname": "我是学生",
"username": "小明",
"state": 0,
"phone": "18890903030"
}
})
const perPage = await page.$('.page')
const buttonGroup = await perPage.$('.uni-button-group')
const toButton = await buttonGroup.$('.uni-button')
await toButton.tap()
await page.waitFor(800)
}
})
it('审核员', async () => {
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus" ) {
await page.waitFor(500)
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[2].tap()
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(500)
const perPage = await page.$('.page')
const setPer = await perPage.$('set-permission')
//底部角色控制条
const roles = await setPer.$$('.roles-item')
//点击创建
await roles[2].tap()
await page.waitFor(500)
}
const auditor = await page.waitFor(async()=>{
const auditorRole = await page.data('rulo_index')
return auditorRole === 2
})
if(auditor){
const setDataB = await page.setData({
"formData": {
"_id": "60200c3554a29f0001d14586",
"nickname": "我是学生",
"username": "小明",
"state":1,
"phone": "18890903030"
}
})
}
//console.log(await page.data('formData'), "setDataB-------");
})
it('管理员', async () => {
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus" ) {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[3].tap()
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(500)
const perPage = await page.$('.page')
const setPer = await perPage.$('set-permission')
//底部角色控制条
const roles = await setPer.$$('.roles-item')
//点击创建
await roles[3].tap()
await page.waitFor(500)
}
const admin = await page.waitFor(async()=>{
const adminRole = await page.data('rulo_index')
return adminRole === 3
})
if(admin){
const setDataC = await page.setData({
"formData": {
"_id": "60200c3554a29f0001d14586",
"nickname": "我是学生",
"username": "小明",
"state":-1,
"phone": "18890903030"
}
})
}
})
})
describe('pages/clientDB/permission-demo/readme.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch(
'/pages/clientDB/permission-demo/readme')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus" ) {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
// page = await program.currentPage()
})
beforeEach(async()=>{
jest.setTimeout(30000)
return false
})
it('用户', async () => {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[1].tap()
const user = await page.waitFor(async()=>{
const userRole = await page.data('currentRole')
return userRole == 'user'
})
console.log("user: ",user);
if(user){
const getData = await page.callMethod('getFn','uid,username,nickname,state')
expect(getData).not.toBeUndefined();
const removeAll = await page.callMethod('removeFn','uid,username,nickname,state')
// expect(removeAll.code).toBe('PERMISSION_ERROR')
//创建一条数据
await page.callMethod('addFn')
//更新创建者自己的昵称
await page.callMethod(
'updateFn',
{"nickname":'新昵称'},'uid == $env.uid'
)
const updateAllNickname = await page.callMethod(
'updateFn',
{"nickname":'新昵称'}
)
// expect(updateAllNickname.code).toBe("PERMISSION_ERROR")
const updateState = await page.callMethod('updateFn',{state:1})
// expect(updateState.code).toBe('PERMISSION_ERROR')
const updateAllUsername = await page.callMethod(
'updateFn',
{"username":"新姓名"}
)
// expect(updateAllUsername.code).toBe('PERMISSION_ERROR')
const updateUsername = await page.callMethod(
'updateFn',
{"username":'新姓名'},'uid == $env.uid'
)
// expect(updateUsername.code).toBe('PERMISSION_ERROR')
await page.callMethod(
'getFn',
'uid,username,nickname,state'
)
const readPhone = await page.callMethod(
'getFn',
'uid,username,nickname,state'
)
}
})
it('未登陆', async () => {
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus" ) {
console.log("h5");
await page.waitFor(2000)
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[0].tap()
await page.waitFor(500)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(300)
console.log("mp-weixin");
const perPage = await page.$('.page')
const setPer = await perPage.$('set-permission')
//底部角色控制条
const roles = await setPer.$$('.roles-item')
//点击创建
await roles[0].tap()
await page.waitFor(500)
}
const unlogin = await page.waitFor(async()=>{
const unloginRole = await page.data('currentRole')
return unloginRole === 0
})
console.log("unlogin: ",unlogin);
if(unlogin){
const getData = await page.callMethod('getFn','uid,username,nickname,state')
expect(getData.data).not.toBeUndefined();
// console.log("getData: ",getData.data);
//删除所有
const removeAll = await page.callMethod('removeFn','uid,username,nickname,state')
// expect(removeAll.code).toBe('PERMISSION_ERROR')
//创建一条数据
const createOne = await page.callMethod('addFn')
const updateNickname = await page.callMethod(
'updateFn',
{"nickname":'新昵称'},'uid == $env.uid'
)
// expect(updateNickname.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
const updateAllNickname = await page.callMethod(
'updateFn',
{"nickname":'新昵称'}
)
// expect(updateAllNickname.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
const updateState = await page.callMethod('updateFn',{state:1})
// expect(updateState.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
const updateAllUsername = await page.callMethod(
'updateFn',
{"username":"新姓名"}
)
// console.log("updateAllUsername: ",updateAllUsername);
// expect(updateAllUsername.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
const updateUsername = await page.callMethod(
'updateFn',
{"username":'新姓名'},'uid == $env.uid'
)
// expect(updateUsername.code).toBe('TOKEN_INVALID_ANONYMOUS_USER')
await page.callMethod(
'getFn',
'uid,username,nickname,state'
)
const readPhone = await page.callMethod(
'getFn',
'uid,username,nickname,state'
)
}
})
it('审核员', async () => {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[2].tap()
const auditor = await page.waitFor(async()=>{
const auditorRole = await page.data('currentRole')
return auditorRole == 'auditor'
})
console.log(auditor);
if(auditor){
const getData = await page.callMethod('getFn','uid,username,nickname,state')
expect(getData).not.toBeUndefined();
const removeAll = await page.callMethod('removeFn','uid,username,nickname,state')
expect(removeAll.code).toBe('PERMISSION_ERROR')
await page.callMethod('addFn')
//更新创建者
await page.callMethod(
'updateFn',
{"nickname":'新昵称'},'uid == $env.uid'
)
//更新表中所有
const updateAllNickname = await page.callMethod(
'updateFn',
{"nickname":'新昵称'}
)
//state更新为1
await page.callMethod('updateFn',{state:1})
//更新表中所有
await page.callMethod(
'updateFn',
{"username":"新姓名"}
)
//更新创建者
await page.callMethod(
'updateFn',
{"username":'新姓名'},'uid == $env.uid'
)
//读不含phone
await page.callMethod(
'getFn',
'uid,username,nickname,state'
)
//读含有phone
await page.callMethod(
'getFn',
'uid,username,nickname,state'
)
}
})
it('管理员', async () => {
const perPage = await page.$('.page')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await roles[3].tap()
const admin = await page.waitFor(async()=>{
const adminRole = await page.data('currentRole')
return adminRole == 'admin'
})
console.log(admin);
if(admin){
const getData = await page.callMethod('getFn','uid,username,nickname,state')
expect(getData).not.toBeUndefined();
//删除所有
await page.callMethod('removeFn','uid,username,nickname,state')
//新增一条
await page.callMethod('addFn')
//更新创建者
await page.callMethod(
'updateFn',
{"nickname":'新昵称'},'uid == $env.uid'
)
//更新表中所有
const updateAllNickname = await page.callMethod(
'updateFn',
{"nickname":'新昵称'}
)
//state更新为1
await page.callMethod('updateFn',{state:1})
//更新表中所有
await page.callMethod(
'updateFn',
{"username":"新姓名"}
)
//更新创建者
await page.callMethod(
'updateFn',
{"username":'新姓名'},'uid == $env.uid'
)
//读不含phone
await page.callMethod(
'getFn',
'uid,username,nickname,state'
)
//读含有phone
await page.callMethod(
'getFn',
'uid,username,nickname,state'
)
}
})
})
\ No newline at end of file
<template> <template>
<view class="page"> <view class="page">
<alertCode ref="alertCode"></alertCode> <alertCode ref="alertCode"></alertCode>
...@@ -442,3 +443,4 @@ button{ ...@@ -442,3 +443,4 @@ button{
padding: 10rpx; padding: 10rpx;
} }
</style> </style>
describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch(
'/pages/clientDB/permission-field-simple/permission-field-simple')
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
})
// beforeEach(async()=>{
// jest.setTimeout(30000)
// return false
// })
it('创建--未登陆', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[0].tap()
await roles[0].tap()
const createUnlogin = await page.waitFor(async () => {
const createUnloginIndex = await page.data('typeIndex')
const createUnloginRole = await page.data('currentRole')
return createUnloginIndex === 0 && createUnloginRole === 0
})
console.log("createUnlogin: ",createUnlogin);
const createA = await page.callMethod('myFn', {
"type": "create",
"index": 0
})
/* expect(createA).toBe('[permission-test-10.ip.write]权限校验未通过') */
await page.callMethod('myFn', {
"type": "create",
"index": 0,
"field": "_id,state,create_time,text",
})
const createB = await page.callMethod('myFn', {
"type": "create",
"index": 1,
})
// expect(createB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "create",
"index": 1,
"field": "_id,state,create_time,text",
})
const createC = await page.callMethod('myFn', {
"type": "create",
"index": 2,
})
expect(createC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "create",
"index": 2,
"field": "_id,state,create_time,text",
})
})
it('读取--未登陆', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击读取
await segItems[1].tap()
await roles[0].tap()
const readUnlogin = await page.waitFor(async () => {
const readUnloginIndex = await page.data('typeIndex')
const readUnloginRole = await page.data('currentRole')
return readUnloginIndex === 1 && readUnloginRole === 0
})
console.log("readUnlogin: ",readUnlogin);
const readA = await page.callMethod('myFn', {
"type": "read",
"index": 0
})
console.log("readA: ",readA);
// expect(readA).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"field": "_id,state,create_time,text"
})
const readB = await page.callMethod('myFn', {
"type": "read",
"index": 1
})
expect(readB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "read",
"index": 1,
"field": "_id,state,create_time,text"
})
const readC = await page.callMethod('myFn', {
"type": "read",
"index": 2
})
expect(readC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "read",
"index": 2,
"field": "_id,state,create_time,text"
})
})
it('更新--未登陆', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击更新
await segItems[2].tap()
await roles[0].tap()
const updateUnlogin = await page.waitFor(async () => {
const updateUnloginIndex = await page.data('typeIndex')
const updateUnloginRole = await page.data('currentRole')
return updateUnloginIndex === 2 && updateUnloginRole === 0
})
console.log("updateUnlogin: ",updateUnlogin);
const updateA = await page.callMethod('myFn', {
"type": "update",
"index": 0
})
console.log("updateA: ",updateA);
// expect(updateA).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "update",
"index": 0,
"field": "_id,state,create_time,text"
})
const updateB = await page.callMethod('myFn', {
"type": "update",
"index": 1
})
expect(updateB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "update",
"index": 1,
"field": "_id,state,create_time,text"
})
const updateC = await page.callMethod('myFn', {
"type": "update",
"index": 2
})
expect(updateC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "update",
"index": 2,
"field": "_id,state,create_time,text"
})
})
it('创建--用户', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[0].tap()
await roles[1].tap()
const createUser = await page.waitFor(async () => {
const createUserIndex = await page.data('typeIndex')
const createUserRole = await page.data('currentRole')
return createUserIndex === 0 && createUserRole == 'user'
})
console.log("createUser: ",createUser);
const createUserA = await page.callMethod('myFn', {
"type": "create",
"index": 0,
})
console.log("createUserA: ",createUserA);
// expect(createUserA).toBe('[permission-test-10.ip.write]权限校验未通过')
await page.callMethod('myFn', {
"type": "create",
"index": 0,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "create",
"index": 1,
})
await page.callMethod('myFn', {
"type": "create",
"index": 1,
"field": "_id,state,create_time,text",
})
const createUserB = await page.callMethod('myFn', {
"type": "create",
"index": 2,
})
// expect(createUserB).toBe('[permission-test-12.ip.write]权限校验未通过')
//未能获取当前用户信息:30205 | 当前用户为匿名身份
await page.callMethod('myFn', {
"type": "create",
"index": 2,
"field": "_id,state,create_time,text",
})
})
it('读取--用户', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击读取
await segItems[1].tap()
await roles[1].tap()
const readUser = await page.waitFor(async () => {
const readUserIndex = await page.data('typeIndex')
const readUserRole = await page.data('currentRole')
return readUserIndex === 1 && readUserRole == 'user'
})
console.log("readUser: ",readUser);
const readUserA = await page.callMethod('myFn', {
"type": "read",
"index": 0
})
expect(readUserA).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "read",
"index": 1
})
await page.callMethod('myFn', {
"type": "read",
"index": 1,
"field": "_id,state,create_time,text"
})
const readUserB = await page.callMethod('myFn', {
"type": "read",
"index": 2
})
expect(readUserB).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "read",
"index": 2,
"field": "_id,state,create_time,text"
})
})
it('更新--用户', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击更新
await segItems[2].tap()
await roles[1].tap()
const readUser = await page.waitFor(async () => {
const updateUserIndex = await page.data('typeIndex')
const updateUserRole = await page.data('currentRole')
return updateUserIndex === 2 && updateUserRole == 'user'
})
const updateUserA = await page.callMethod('myFn', {
"type": "update",
"index": 0
})
expect(updateUserA).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "update",
"index": 0,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "update",
"index": 1
})
await page.callMethod('myFn', {
"type": "update",
"index": 1,
"field": "_id,state,create_time,text"
})
const updateUserB = await page.callMethod('myFn', {
"type": "update",
"index": 2
})
expect(updateUserB).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "update",
"index": 2,
"field": "_id,state,create_time,text"
})
})
it('创建--审核员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[0].tap()
await roles[2].tap()
const createAuditor = await page.waitFor(async () => {
const createAuditorIndex = await page.data('typeIndex')
const createAuditorRole = await page.data('currentRole')
return createAuditorIndex === 0 && createAuditorRole == 'auditor'
})
const createAuditorA = await page.callMethod('myFn', {
"type": "create",
"index": 0,
})
console.log("createAuditorA: ",createAuditorA);
// expect(createAuditorA).toBe('[permission-test-10.ip.write]权限校验未通过')
await page.callMethod('myFn', {
"type": "create",
"index": 0,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "create",
"index": 1,
})
await page.callMethod('myFn', {
"type": "create",
"index": 1,
"field": "_id,state,create_time,text",
})
await page.callMethod('myFn', {
"type": "create",
"index": 2,
})
await page.callMethod('myFn', {
"type": "create",
"index": 2,
"field": "_id,state,create_time,text",
})
})
it('读取--审核员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击读取
await segItems[1].tap()
await roles[2].tap()
const readAuditor = await page.waitFor(async () => {
const readAuditorIndex = await page.data('typeIndex')
const readAuditorRole = await page.data('currentRole')
return readAuditorIndex === 1 && readAuditorRole == 'auditor'
})
const readAuditorA = await page.callMethod('myFn', {
"type": "read",
"index": 0
})
expect(readAuditorA).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "read",
"index": 1
})
await page.callMethod('myFn', {
"type": "read",
"index": 1,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "read",
"index": 2
})
await page.callMethod('myFn', {
"type": "read",
"index": 2,
"field": "_id,state,create_time,text"
})
})
it('更新--审核员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击更新
await segItems[2].tap()
await roles[2].tap()
const updateAuditor = await page.waitFor(async () => {
const updateAuditorIndex = await page.data('typeIndex')
const updateAuditorRole = await page.data('currentRole')
return updateAuditorIndex === 2 && updateAuditorRole == 'auditor'
})
const updateAuditorA = await page.callMethod('myFn', {
"type": "update",
"index": 0
})
expect(updateAuditorA).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "update",
"index": 0,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "update",
"index": 1
})
await page.callMethod('myFn', {
"type": "update",
"index": 1,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "update",
"index": 2
})
await page.callMethod('myFn', {
"type": "update",
"index": 2,
"field": "_id,state,create_time,text"
})
})
it('创建--管理员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[0].tap()
await roles[3].tap()
const createAdmin = await page.waitFor(async () => {
const createAdminIndex = await page.data('typeIndex')
const createAdminRole = await page.data('currentRole')
return createAdminIndex === 0 && createAdminRole == 'admin'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0,
})
await page.callMethod('myFn', {
"type": "create",
"index": 0,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "create",
"index": 1,
})
await page.callMethod('myFn', {
"type": "create",
"index": 1,
"field": "_id,state,create_time,text",
})
await page.callMethod('myFn', {
"type": "create",
"index": 2,
})
await page.callMethod('myFn', {
"type": "create",
"index": 2,
"field": "_id,state,create_time,text",
})
})
it('读取--管理员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击读取
await segItems[1].tap()
await roles[3].tap()
const readAdmin = await page.waitFor(async () => {
const readAdminIndex = await page.data('typeIndex')
const readAdminRole = await page.data('currentRole')
return readAdminIndex === 1 && readAdminRole == 'admin'
})
await page.callMethod('myFn', {
"type": "read",
"index": 0
})
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "read",
"index": 1
})
await page.callMethod('myFn', {
"type": "read",
"index": 1,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "read",
"index": 2
})
await page.callMethod('myFn', {
"type": "read",
"index": 2,
"field": "_id,state,create_time,text"
})
})
it('更新--管理员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击更新
await segItems[2].tap()
await roles[3].tap()
const updateAdmin = await page.waitFor(async () => {
const updateAdminIndex = await page.data('typeIndex')
const updateAdminRole = await page.data('currentRole')
return updateAdminIndex === 2 && updateAdminRole == 'admin'
})
await page.callMethod('myFn', {
"type": "update",
"index": 0
})
await page.callMethod('myFn', {
"type": "update",
"index": 0,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "update",
"index": 1
})
await page.callMethod('myFn', {
"type": "update",
"index": 1,
"field": "_id,state,create_time,text"
})
await page.callMethod('myFn', {
"type": "update",
"index": 2
})
await page.callMethod('myFn', {
"type": "update",
"index": 2,
"field": "_id,state,create_time,text"
})
})
})
<template> <template>
<view class="page"> <view class="page">
<view class="top-view"> <view class="top-view">
...@@ -49,6 +50,14 @@ ...@@ -49,6 +50,14 @@
return this.types[this.typeIndex].text return this.types[this.typeIndex].text
} }
}, },
computed: {
type() {
return this.types[this.typeIndex].value
},
typeText() {
return this.types[this.typeIndex].text
}
},
data() { data() {
return { return {
currentRole:0, currentRole:0,
......
describe('pages/clientDB/permission-table-compound/permission-table-compound.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch(
'/pages/clientDB/permission-table-compound/permission-table-compound')
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
// page = await program.currentPage()
// console.log("page------------------: ",page);
})
// beforeEach(async()=>{
// jest.setTimeout(30000)
// return false
// })
it('创建--未登陆', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[0].tap()
await roles[0].tap()
const createUnlogin = await page.waitFor(async () => {
const createUnloginIndex = await page.data('typeIndex')
const createUnloginRole = await page.data('currentRole')
return createUnloginIndex === 0 && createUnloginRole === 0
})
const createA = await page.callMethod('myFn', {
"type": "create",
"index": 1
})
// expect(createA).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "create",
"index": 1,
"action": "add_view_count"
})
})
it('读取--未登陆', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[1].tap()
await roles[0].tap()
const readUnlogin = await page.waitFor(async () => {
const readUnloginIndex = await page.data('typeIndex')
const readUnloginRole = await page.data('currentRole')
return readUnloginIndex === 1 && readUnloginRole === 0
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
const readA = await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
// expect(readA).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
const readB = await page.callMethod('myFn', {
"type": "read",
"index": 0
})
expect(readB).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
const readC = await page.callMethod('myFn', {
"type": "read",
"index": 1
})
expect(readC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "read",
"index": 1,
"action": "add_view_count"
})
})
it('更新--未登陆', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击更新
await segItems[2].tap()
await roles[0].tap()
const updateUnlogin = await page.waitFor(async () => {
const updateUnloginIndex = await page.data('typeIndex')
const updateUnloginRole = await page.data('currentRole')
return updateUnloginIndex === 2 && updateUnloginRole === 0
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
const updateA = await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
expect(updateA).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
const updateB = await page.callMethod('myFn', {
"type": "update",
"index": 0
})
console.log("updateB: ",updateB);
// expect(updateB).toBe('权限校验未通过')
const updateC = await page.callMethod('myFn', {
"type": "update",
"index": 1
})
expect(updateC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "update",
"index": 1,
"action": "add_view_count"
})
})
it('删除--未登陆', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击删除
await segItems[3].tap()
await roles[0].tap()
const deleteUnlogin = await page.waitFor(async () => {
const deleteUnloginIndex = await page.data('typeIndex')
const deleteUnloginRole = await page.data('currentRole')
return deleteUnloginIndex === 3 && deleteUnloginRole === 0
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
const deleteA = await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
expect(deleteA).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
const deleteB = await page.callMethod('myFn', {
"type": "delete",
"index": 0
})
console.log("deleteB: ",deleteB);
// expect(deleteB).toBe('权限校验未通过')
const deleteC = await page.callMethod('myFn', {
"type": "delete",
"index": 1
})
expect(deleteC).toBe('未能获取当前用户信息:30205 | 当前用户为匿名身份')
await page.callMethod('myFn', {
"type": "delete",
"index": 1,
"action": "add_view_count"
})
})
it('创建--用户', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[0].tap()
await roles[1].tap()
const createUser = await page.waitFor(async () => {
const createUserIndex = await page.data('typeIndex')
const createUserRole = await page.data('currentRole')
return createUserIndex === 0 && createUserRole == 'user'
})
await page.callMethod('myFn', {
"type": "create",
"index": 1
})
await page.callMethod('myFn', {
"type": "create",
"index": 1,
"action": "add_view_count"
})
})
it('读取--用户', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[1].tap()
await roles[1].tap()
const readUser = await page.waitFor(async () => {
const readUserIndex = await page.data('typeIndex')
const readUserRole = await page.data('currentRole')
return readUserIndex === 1 && readUserRole == 'user'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
const readUserA = await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
//console.log(readUserA,"readUserA---------");
//未能获取当前用户信息:30205 | 当前用户为匿名身份
//expect(readUserA).toBe('权限校验未通过')
const readUserB = await page.callMethod('myFn', {
"type": "read",
"index": 0
})
//console.log(readUserB,"readUserB---------");
//expect(readUserB).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "read",
"index": 1
})
await page.callMethod('myFn', {
"type": "read",
"index": 1,
"action": "add_view_count"
})
})
it('更新--用户', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击更新
await segItems[2].tap()
await roles[1].tap()
const updateUser = await page.waitFor(async () => {
const updateUserIndex = await page.data('typeIndex')
const updateUserRole = await page.data('currentRole')
return updateUserIndex === 2 && updateUserRole == 'user'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
const updateUserA = await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
//console.log(updateUserA,"updateUserA---------");
//expect(updateUserA).toBe('权限校验未通过')
//未能获取当前用户信息:30205 | 当前用户为匿名身份
const updateUserB = await page.callMethod('myFn', {
"type": "update",
"index": 0
})
expect(updateUserB).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "update",
"index": 1
})
await page.callMethod('myFn', {
"type": "update",
"index": 1,
"action": "add_view_count"
})
})
it('删除--用户', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击删除
await segItems[3].tap()
await roles[1].tap()
const deleteUser = await page.waitFor(async () => {
const deleteUserIndex = await page.data('typeIndex')
const deleteUserRole = await page.data('currentRole')
return deleteUserIndex === 3 && deleteUserRole == 'user'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
const deleteUserA = await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
expect(deleteUserA).toBe('权限校验未通过')
const deleteUserB = await page.callMethod('myFn', {
"type": "delete",
"index": 0
})
expect(deleteUserB).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "delete",
"index": 1
})
await page.callMethod('myFn', {
"type": "delete",
"index": 1,
"action": "add_view_count"
})
})
it('创建--审核员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[0].tap()
await roles[2].tap()
const createAuditor = await page.waitFor(async () => {
const createAuditorIndex = await page.data('typeIndex')
const createAuditorRole = await page.data('currentRole')
return createAuditorIndex === 0 && createAuditorRole == 'auditor'
})
await page.callMethod('myFn', {
"type": "create",
"index": 1
})
await page.callMethod('myFn', {
"type": "create",
"index": 1,
"action": "add_view_count"
})
})
it('读取--审核员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[1].tap()
await roles[2].tap()
const readAuditor = await page.waitFor(async () => {
const readAuditorIndex = await page.data('typeIndex')
const readAuditorRole = await page.data('currentRole')
return readAuditorIndex === 1 && readAuditorRole == 'auditor'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
const readAuditorA = await page.callMethod('myFn', {
"type": "read",
"index": 0
})
await page.callMethod('myFn', {
"type": "read",
"index": 1
})
await page.callMethod('myFn', {
"type": "read",
"index": 1,
"action": "add_view_count"
})
})
it('更新--审核员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击更新
await segItems[2].tap()
await roles[2].tap()
const updateAuditor = await page.waitFor(async () => {
const updateAuditorIndex = await page.data('typeIndex')
const updateAuditorRole = await page.data('currentRole')
return updateAuditorIndex === 2 && updateAuditorRole == 'auditor'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
const updateAuditorA = await page.callMethod('myFn', {
"type": "update",
"index": 0
})
expect(updateAuditorA).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "update",
"index": 1
})
await page.callMethod('myFn', {
"type": "update",
"index": 1,
"action": "add_view_count"
})
})
it('删除--审核员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击删除
await segItems[3].tap()
await roles[2].tap()
const deleteAuditor = await page.waitFor(async () => {
const deleteAuditorIndex = await page.data('typeIndex')
const deleteAuditorRole = await page.data('currentRole')
return deleteAuditorIndex === 3 && deleteAuditorRole == 'auditor'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
const deleteAuditorB = await page.callMethod('myFn', {
"type": "delete",
"index": 0
})
expect(deleteAuditorB).toBe('权限校验未通过')
await page.callMethod('myFn', {
"type": "delete",
"index": 1
})
await page.callMethod('myFn', {
"type": "delete",
"index": 1,
"action": "add_view_count"
})
})
it('创建--管理员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[0].tap()
await roles[3].tap()
const createAdmin = await page.waitFor(async () => {
const createAdminIndex = await page.data('typeIndex')
const createAdminRole = await page.data('currentRole')
return createAdminIndex === 0 && createAdminRole == 'admin'
})
await page.callMethod('myFn', {
"type": "create",
"index": 1
})
await page.callMethod('myFn', {
"type": "create",
"index": 1,
"action": "add_view_count"
})
})
it('读取--管理员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击创建
await segItems[1].tap()
await roles[3].tap()
const readAdmin = await page.waitFor(async () => {
const readAdminIndex = await page.data('typeIndex')
const readAdminRole = await page.data('currentRole')
return readAdminIndex === 1 && readAdminRole === 'admin'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
await page.callMethod('myFn', {
"type": "read",
"index": 0
})
await page.callMethod('myFn', {
"type": "read",
"index": 1
})
await page.callMethod('myFn', {
"type": "read",
"index": 1,
"action": "add_view_count"
})
})
it('更新--管理员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击更新
await segItems[2].tap()
await roles[3].tap()
const updateAdmin = await page.waitFor(async () => {
const updateAdminIndex = await page.data('typeIndex')
const updateAdminRole = await page.data('currentRole')
return updateAdminIndex === 2 && updateAdminRole == 'admin'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
await page.callMethod('myFn', {
"type": "update",
"index": 0
})
await page.callMethod('myFn', {
"type": "update",
"index": 1
})
await page.callMethod('myFn', {
"type": "update",
"index": 1,
"action": "add_view_count"
})
})
it('删除--管理员', async () => {
const perPage = await page.$('.page')
//头部操作控制条
const segItems = await perPage.$$('.segmented-control__item')
//底部角色控制条
const roles = await perPage.$$('.roles-item')
//点击删除
await segItems[3].tap()
await roles[3].tap()
const deleteAdmin = await page.waitFor(async () => {
const deleteAdminIndex = await page.data('typeIndex')
const deleteAdminRole = await page.data('currentRole')
return deleteAdminIndex === 3 && deleteAdminRole == 'admin'
})
await page.callMethod('myFn', {
"type": "create",
"index": 0
})
await page.callMethod('myFn', {
"type": "read",
"index": 0,
"where": "create_time > 1613534788761"
})
await page.callMethod('myFn', {
"type": "delete",
"index": 0
})
await page.callMethod('myFn', {
"type": "delete",
"index": 1
})
await page.callMethod('myFn', {
"type": "delete",
"index": 1,
"action": "add_view_count"
})
})
})
<template> <template>
<view class="page"> <view class="page">
<view class="top-view"> <view class="top-view">
......
<template> <template>
<view class="page"> <view class="page">
<view class="top-view"> <view class="top-view">
...@@ -154,7 +155,8 @@ ...@@ -154,7 +155,8 @@
}, },
methods: { methods: {
async myFn(e) { // {type:'',tableName:'',index,action:'',where:{}} async myFn(e) { // {type:'',tableName:'',index,action:'',where:{}}
console.log('myFun' + JSON.stringify(e)); console.log("e:----------- ",e);
// console.log('myFun' + JSON.stringify(e));
e.where = e.where || {} e.where = e.where || {}
let item = this.permissionList[e.index] let item = this.permissionList[e.index]
let tableName = item.tableName || 'permission-test-' + (e.index + 1) let tableName = item.tableName || 'permission-test-' + (e.index + 1)
...@@ -172,6 +174,7 @@ ...@@ -172,6 +174,7 @@
switch (e.type) { switch (e.type) {
case 'read': case 'read':
res = await db.action(e.action).collection(tableName).where(e.where).get() res = await db.action(e.action).collection(tableName).where(e.where).get()
console.log("res:----read--------- ",res);
if (res.result.data.length == 0) { if (res.result.data.length == 0) {
uni.showModal({ uni.showModal({
title: "数据为空,请先点击创建数据", title: "数据为空,请先点击创建数据",
...@@ -182,19 +185,24 @@ ...@@ -182,19 +185,24 @@
return res return res
break; break;
case 'create': case 'create':
console.log(e.action);
res = await db.action(e.action).collection(tableName).add({ res = await db.action(e.action).collection(tableName).add({
"text": "默认写入的数据" + Date.now() "text": "默认写入的数据" + Date.now()
}) })
console.log("res:-----create-------- ",res);
return res return res
break; break;
case 'update': case 'update':
console.log("tableName: ",tableName);
res = await db.action(e.action).collection(tableName).where(e.where).update({ res = await db.action(e.action).collection(tableName).where(e.where).update({
"text": "更新后的数据" + Date.now() "text": "更新后的数据" + Date.now()
}) })
console.log("res:----update--------- ",res);
return res return res
break; break;
case 'delete': case 'delete':
res = await db.action(e.action).collection(tableName).where(e.where).remove() res = await db.action(e.action).collection(tableName).where(e.where).remove()
console.log("res:----delete--------- ",res);
return res return res
break; break;
default: default:
......
describe('pages/clientDB/permission/permission.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/clientDB/permission/permission')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
})
beforeEach(async()=>{
jest.setTimeout(5000)
return false
})
it('获取数据',async()=>{
//expect.assertions(2)
if(process.env.UNI_PLATFORM === "mp-weixin"){
const listItem = await page.$$('uni-list-item')
expect(listItem.length).toBe(4)
}
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(500)
const perPage = await page.$('.page')
const getData = await perPage.$$(".table-item")
expect(getData.length).toBe(4)
//expect(await getData[0].text()).not.toBeUndefined();
}
})
})
\ No newline at end of file
describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/clientDB/unicloud-db-demo/unicloud-db-demo')
await page.waitFor(1000);
})
beforeEach(async()=>{
jest.setTimeout(10000)
return false
})
it("增-删", async () => {
const count = await page.data('getcount')
console.log("count: ",count);
/* expect.assertions(1);
const count = await page.data('getcount')
expect(count).toBeTruthy(); */
const addData = await page.callMethod('add')
await page.waitFor(500)
const getDataList = await page.data('dataList')
console.log("getDataList: ",getDataList);
expect(await getDataList.length).toBeGreaterThanOrEqual(1);
const removeData = await page.callMethod('remove')
})
it("", async () => {
const updateData = await page.callMethod('update')
})
it("", async () => {
const getFnData = await page.callMethod('getFn')
})
it("只查一条数据", async () => {
//开启只查一条
const swGetone = await page.$('.switch-getone')
await swGetone.tap()
await page.waitFor(500)
const getoneBool = await page.data('getone')
expect.assertions(1);
expect(getoneBool).toBeTruthy();
//关闭只查一条
await swGetone.tap()
await page.waitFor(500)
})
it("数据翻页-replace", async () => {
expect.assertions(3);
//判断类型为翻页加载
const replace = await page.data('pageData')
expect(replace).toBe('replace')
//增加当前页码
const pageCurrentBefore = await page.data('pageCurrent')
const numBox1 = await page.$('.num-box1')
const numboxAdd1 = await numBox1.$('.uni-numbox__plus')
await numboxAdd1.tap()
await page.waitFor(500)
//获取增加后的页码
const pageCurrentAfter = await page.data('pageCurrent')
expect(pageCurrentAfter).toBeGreaterThanOrEqual(pageCurrentBefore);//大于/toBeGreaterThan
//增加当前每页数量
const pageSizeBefore = await page.data('pageSize')
const numBox2 = await page.$('.num-box2')
const numboxAdd2 = await numBox2.$('.uni-numbox__plus')
await numboxAdd2.tap()
await page.waitFor(500)
//增加每页数据数量
const pageSizeAfter = await page.data('pageSize')
expect(pageSizeAfter).toBeGreaterThanOrEqual(pageSizeBefore);//大于
})
it("追加数据-add", async () => {
//改变分页策略为add
const pageCheckbox = await page.$('.page-checkbox')
const addSet = await page.setData({"pageData": "add"})
const isAdd = await page.waitFor(async()=>{
const addText = await page.data('pageData')
return addText === 'add'
})
if(isAdd){//加载更多
/* if (process.env.UNI_PLATFORM === "mp-weixin") {
const toLoadMore = await page.$('.toLoadMore')
const loadMore = await toLoadMore.$('.loadMore')
await loadMore.tap()
await page.waitFor(300)
} */
if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM === "app-plus") {
const loadMore = await page.$('.loadMore')
await loadMore.tap()
await page.waitFor(300)
}
}
//每页数据数量减去1
const pageSizeSubBefore = await page.data('pageSize')
const numBox2 = await page.$('.num-box2')
const numboxMin2 = await numBox2.$('.uni-numbox__minus')
await numboxMin2.tap()
await page.waitFor(500)
//减少数据数量,由3页变为2页
const pageSizeSubAfter = await page.data('pageSize')
expect(pageSizeSubAfter).toBeLessThanOrEqual(pageSizeSubBefore);//小于
})
it("设置排序字段-orderBy", async () => {
await page.setData({"orderby": 'create_date asc'})
})
it("是否查询总数据条数", async () => {
const swGetcount = await page.$('.switch-getcount')
await swGetcount.tap()
await page.waitFor(500)
const getcountBool = await page.data('getcount')
expect.assertions(1);
expect(getcountBool).toBeFalsy();
})
it("指定要查询的字段", async () => {
expect.assertions(1);
const arr = [ 'book_id', 'create_date', 'quantity' ]
const getFields = await page.data('fields')
//expect(getFields).toContain('book_id');
expect(getFields).toEqual(arr);
//指定字段create_date
const fieldCheckbox = await page.$('.field-checkbox')
await fieldCheckbox.setData({
field: ['create_date'],
})
})
})
<template> <template>
<view class="root"> <view class="root">
<unicloud-db ref="udb" v-slot:default="{data, loading, error, options,pagination,hasMore}" <unicloud-db ref="udb" v-slot:default="{data, loading, error, options,pagination,hasMore}"
:options="options" :options="options"
:page-data="pageData" :page-data="pageData"
...@@ -116,10 +118,14 @@ ...@@ -116,10 +118,14 @@
udb = this.$refs.udb udb = this.$refs.udb
}, },
onLoad() { onLoad() {
setTimeout(()=>{ this.$nextTick(()=>{
this.dataList = this.$refs.udb.dataList
})
/* setTimeout(()=>{
console.log(this.$refs.udb,12121111); console.log(this.$refs.udb,12121111);
this.dataList = this.$refs.udb.dataList this.dataList = this.$refs.udb.dataList
}, 2000); }, 2000); */
}, },
watch: { watch: {
field(field, oldValue) { field(field, oldValue) {
...@@ -214,6 +220,7 @@ ...@@ -214,6 +220,7 @@
}, },
async remove(){ async remove(){
const _id = udb.dataList[0]._id const _id = udb.dataList[0]._id
console.log("_id: ",_id);
return await udb.remove(_id) return await udb.remove(_id)
}, },
async update(){ async update(){
......
describe('pages/cloudFunction/cloudFunction.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/cloudFunction/cloudFunction')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
})
beforeEach(async()=>{
jest.setTimeout(5000)
return false
})
it('云函数页-检查标题',async()=>{
expect.assertions(1);
const title = await page.$('.title')
expect(await title.text()).toBe('基础示例-云函数');
})
it('添加一条数据',async()=>{
expect.assertions(1);
const addData = await page.callMethod('add')
expect(addData).toBeDefined();
})
/* it('删除一条数据',async()=>{
expect.assertions(1);
const removeData = await page.callMethod('remove')
//console.log(removeData);
expect(removeData).toBe('成功删除unicloud-test内第一条数据');
}) */
it('修改数据',async()=>{
expect.assertions(1);
const updateData = await page.callMethod('update')
expect(updateData).toBeDefined();
})
it('查询前10条数据',async()=>{
expect.assertions(1);
const getTenData = await page.callMethod('get')
expect(getTenData.length).not.toBeUndefined();
})
it('使用公用模块',async()=>{
expect.assertions(1);
const useCommon = await page.callMethod('useCommon')
const record = {"secret":"abcdefg","version":"1.0.0"}
expect(useCommon).toEqual(record);
})
})
\ No newline at end of file
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
showCancel: false showCancel: false
}) })
console.error(err) console.error(err)
return err
}) })
}, },
async remove() { async remove() {
...@@ -101,6 +102,7 @@ ...@@ -101,6 +102,7 @@
showCancel: false showCancel: false
}) })
console.error(err) console.error(err)
return err
}) })
}, },
async get() { async get() {
......
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.io/collocation/auto/hbuilderx-extension/index
describe('pages/cloudObject/cloudObject.vue', () => {
let page;
beforeAll(async () => {
page = await program.reLaunch('/pages/cloudObject/cloudObject')
console.log("page: ",page);
await page.waitFor(500);
});
it('云对象-检查标题',async()=>{
expect.assertions(1);
const title = await page.$('.title')
console.log("title: ",await title.text());
expect(await title.text()).toBe('基础示例-云对象');
})
it('新增一条数据',async()=>{
expect.assertions(1);
const addData = await page.callMethod('add')
console.log("addData: ",addData);
expect(addData).toBeDefined();
})
it('删除一条数据',async()=>{
expect.assertions(1);
const removeData = await page.callMethod('remove')
console.log("removeData: ",removeData);
expect(removeData).toBe('成功删除unicloud-test内第一条数据');
})
it('修改数据',async()=>{
expect.assertions(1);
const updateData = await page.callMethod('update')
console.log("updateData: ",updateData);
expect(updateData).toBeDefined();
})
it('查询前10条数据',async()=>{
// expect.assertions(1);
const getTenData = await page.callMethod('get')
console.log("getTenData: ",getTenData);
console.log("getTenData.data.length: ",getTenData.data.length);
// expect(getTenData.length).not.toBeUndefined();
expect(getTenData.data.length).toBeGreaterThanOrEqual(1);
// expect(getTenData.length).toBeDefined();
})
it('使用公用模块',async()=>{
expect.assertions(1);
const useCommon = await page.callMethod('useCommon')
console.log("useCommon: ",useCommon);
const record = {"secret":"abcdefg","version":"1.0.0"}
expect(useCommon).toEqual(record);
})
});
...@@ -39,11 +39,11 @@ ...@@ -39,11 +39,11 @@
} }
}, },
methods: { methods: {
add() { async add() {
uni.showLoading({ uni.showLoading({
title: '处理中...' title: '处理中...'
}) })
cloudObjectDemo.add({ return await cloudObjectDemo.add({
name: 'DCloud', name: 'DCloud',
subType: 'uniCloud', subType: 'uniCloud',
createTime: Date.now() createTime: Date.now()
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
content: `成功添加一条数据,文档id为:${res.id}`, content: `成功添加一条数据,文档id为:${res.id}`,
showCancel: false showCancel: false
}) })
return res
}).catch((err) => { }).catch((err) => {
console.error(err) console.error(err)
uni.hideLoading() uni.hideLoading()
...@@ -61,19 +62,21 @@ ...@@ -61,19 +62,21 @@
content: `添加数据失败,错误信息为:${err.message}`, content: `添加数据失败,错误信息为:${err.message}`,
showCancel: false showCancel: false
}) })
return err
}) })
}, },
remove() { async remove() {
uni.showLoading({ uni.showLoading({
title: '处理中...' title: '处理中...'
}) })
cloudObjectDemo.remove().then((res) => { return await cloudObjectDemo.remove().then((res) => {
console.log(res) console.log(res)
uni.hideLoading() uni.hideLoading()
uni.showModal({ uni.showModal({
content: res.msg, content: res.msg,
showCancel: false showCancel: false
}) })
return res.msg
}).catch((err) => { }).catch((err) => {
uni.hideLoading() uni.hideLoading()
uni.showModal({ uni.showModal({
...@@ -81,13 +84,14 @@ ...@@ -81,13 +84,14 @@
showCancel: false showCancel: false
}) })
console.error(err) console.error(err)
return err
}) })
}, },
update() { async update() {
uni.showLoading({ uni.showLoading({
title: '处理中...' title: '处理中...'
}) })
cloudObjectDemo.update({ return await cloudObjectDemo.update({
name: 'DCloud', name: 'DCloud',
subType: 'html 5+', subType: 'html 5+',
createTime: Date.now() createTime: Date.now()
...@@ -106,19 +110,21 @@ ...@@ -106,19 +110,21 @@
showCancel: false showCancel: false
}) })
console.error(err) console.error(err)
return err
}) })
}, },
get() { async get() {
uni.showLoading({ uni.showLoading({
title: '处理中...' title: '处理中...'
}) })
cloudObjectDemo.get().then((res) => { return await cloudObjectDemo.get().then((res) => {
uni.hideLoading() uni.hideLoading()
uni.showModal({ uni.showModal({
content: `查询成功,获取数据列表为:${JSON.stringify(res)}`, content: `查询成功,获取数据列表为:${JSON.stringify(res)}`,
showCancel: false showCancel: false
}) })
console.log(res) console.log(res)
return res
}).catch((err) => { }).catch((err) => {
uni.hideLoading() uni.hideLoading()
uni.showModal({ uni.showModal({
...@@ -126,16 +132,18 @@ ...@@ -126,16 +132,18 @@
showCancel: false showCancel: false
}) })
console.error(err) console.error(err)
return err
}) })
}, },
useCommon() { async useCommon() {
cloudObjectDemo.useCommon().then((res) => { return await cloudObjectDemo.useCommon().then((res) => {
uni.hideLoading() uni.hideLoading()
uni.showModal({ uni.showModal({
content: '云对象使用公共模块返回结果:' + JSON.stringify(res), content: '云对象使用公共模块返回结果:' + JSON.stringify(res),
showCancel: false showCancel: false
}) })
console.log(res) console.log(res)
return res
}).catch((err) => { }).catch((err) => {
uni.hideLoading() uni.hideLoading()
uni.showModal({ uni.showModal({
...@@ -143,6 +151,7 @@ ...@@ -143,6 +151,7 @@
showCancel: false showCancel: false
}) })
console.error(err) console.error(err)
return err
}) })
}, },
toRedisPage() { toRedisPage() {
......
describe('pages/schema2code/schema2code.nvue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/schema2code/schema2code')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
})
beforeEach(async()=>{
jest.setTimeout(5000)
return false
})
it('schema2code-点击',async()=>{
const title = await page.$('.uni-title')
const showSchemaCode = await title.$('.showSchemaCode')
await showSchemaCode.tap()
await page.waitFor(300)
// const showSchemaCode = await page.callMethod('showSchemaCode')
})
it('前往生成的云端一体页面',async()=>{
const toForm = await page.$('.toForm')
await toForm.tap()
await page.waitFor(1000)
// expect( (await program.currentPage()).path).toBe('pages/user-info/list')
// await page.waitFor(500)
// //返回navigateBack 验证是否返回
// expect((await program.navigateBack()).path).toBe('pages/schema2code/schema2code')
})
})
\ No newline at end of file
describe('pages/storage/storage.nvue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/storage/storage')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
})
beforeEach(async()=>{
jest.setTimeout(5000)
return false
})
it('云存储页-检查标题',async()=>{
//expect.assertions(1);
await page.waitFor(300)
const content = await page.$('.content')
await page.waitFor(300)
const title = await content.$('.title')
expect(await title.text()).toBe('直接上传文件到云存储');
})
// it('上传文件',async()=>{
// const upload = await page.callMethod('upload')
// })
})
\ No newline at end of file
describe('pages/user-info/add.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/user-info/add')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
// console.log("page-add: ",page);
})
beforeEach(async()=>{
jest.setTimeout(20000)
return false
})
it('输入表单内容', async () => {
const getForm = await page.data('formData')
console.log("getForm: ",getForm);
let username = "林小明"
let weight = 51
let mobile = "17769516066"
let email = "1076998870@qq.com"
let url = "https://dcloud.io/"
const setForm = await page.setData({
"formData": {
"username":username,
"gender":1,
"birth_date": 1612519694000,
"weight":weight,
"mobile":mobile,
"email":email,
"url":url,
"favorite_book_id": "4",
"address_code": "110105",
"party_member": true,
"hobby":["dance"],
"comment": "好的"
}
})
//console.log(await page.data('formData'), "setForm---");
//姓名只能输入中文
//expect(username).toMatch(/^[\u4e00-\u9fa5]+/);
//手机号校验
expect(mobile).toMatch(/^1[3|4|5|7|8][0-9]{9}$/);
//var re=/\w+@[a-z0-9]+\.[a-z]{2,4}/
expect(email).toMatch(/\w+@[a-z0-9]+\.[a-z]{2,4}/);
//url验证
const urlEx = /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/;
expect(url).toMatch(urlEx);
//体重要大于50 小于或等于500
expect(weight).toBeGreaterThan(50)
expect(weight).toBeLessThanOrEqual(500)
const subRes = await page.callMethod('submit')
console.log("subRes: ",subRes);
})
})
\ No newline at end of file
describe('pages/user-info/detail.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
///pages/user-info/detail?id=601d044ac9e7be0001cc00b8
page = await program.reLaunch('/pages/user-info/detail')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
})
// beforeEach(async()=>{
// jest.setTimeout(10000)
// return false
// })
it('点击修改',async()=>{
const getId = await page.data('_id')
console.log("getId: ",getId);
expect.assertions(1);
const getQuery = await page.query
expect(getQuery).not.toBeUndefined();
const handleUpdate = await page.callMethod('handleUpdate')
})
it('点击删除',async()=>{
const handleDelete = await page.callMethod('handleDelete')
})
})
\ No newline at end of file
describe('pages/user-info/detail.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/user-info/edit?id=601d044ac9e7be0001cc00b8')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
})
beforeEach(async()=>{
jest.setTimeout(10000)
return false
})
it('修改表单内容', async () => {
let username = "林小明加"
let weight = 51
let mobile = "17766666666"
let email = "1076998866@qq.com"
let url = "https://dcloud.io/"
const setForm = await page.setData({
"formData": {
"username":username,
"gender":1,
"birth_date": 1612519694000,
"weight":weight,
"mobile":mobile,
"email":email,
"url":url,
"favorite_book_id": "4",
"address_code": "110105",
"party_member": true,
"hobby":["dance","Sing","draw"],
"comment": "好的更新了1"
}
})
await page.waitFor(1000)
//console.log(await page.data('formData'), "setForm---");
//姓名只能输入中文
//expect(username).toMatch(/^[\u4e00-\u9fa5]+/);
//手机号校验
expect(mobile).toMatch(/^1[3|4|5|7|8][0-9]{9}$/);
//var re=/\w+@[a-z0-9]+\.[a-z]{2,4}/
expect(email).toMatch(/\w+@[a-z0-9]+\.[a-z]{2,4}/);
//url验证
const urlEx = /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/;
expect(url).toMatch(urlEx);
//体重要大于50 小于或等于500
expect(weight).toBeGreaterThan(50)
expect(weight).toBeLessThanOrEqual(500)
await page.callMethod('submit')
})
})
\ No newline at end of file
describe('pages/user-info/list.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/user-info/list')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
})
// beforeEach(async()=>{
// jest.setTimeout(20000)
// return false
// })
/* it('点击某一条',async()=>{
const getDataList = await page.data('dataList')
console.log("getDataList: ",getDataList);
for (var i = 0; i < getDataList.length; i++) {
console.log("getDataList[i]: ",getDataList[i]);
}
const uId = getDataList[0]._id
console.log("uId: ",uId);
if(uId){
const handleItemClick = await page.callMethod('handleItemClick',uId)
}
}) */
it('点击fab跳转到添加页',async()=>{
const fabClick = await page.callMethod('fabClick')
})
})
\ No newline at end of file
<template> <template>
<view class="container"> <view class="container">
<unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}" collection="user-info,book,opendb-city-china" field="username,gender,birth_date,weight,mobile,email,url,favorite_book_id{title},address_code{name},party_member,hobby,comment"> <unicloud-db ref="udb" v-slot:default="{data, pagination, loading, hasMore, error}"
<view v-if="error">{{error.message}}</view> collection="user-info,book,opendb-city-china"
<view v-else-if="data"> field="username,gender,birth_date,weight,mobile,email,url,favorite_book_id{title},address_code{name},party_member,hobby,comment">
<uni-list> <view v-if="error">{{error.message}}</view>
<uni-list-item v-for="(item, index) in data" :key="index" showArrow :clickable="true" @click="handleItemClick(item._id)"> <view v-else-if="data">
<template v-slot:body> <uni-list>
<text> <uni-list-item v-for="(item, index) in data" :key="index" showArrow :clickable="true"
<!-- 此处默认显示为_id,请根据需要自行修改为其他字段 --> @click="handleItemClick(item._id)">
<!-- 如果使用了联表查询,请参考生成的 admin 项目中 list.vue 页面的绑定字段的写法 --> <template v-slot:body>
{{item._id}} <text>
</text> <!-- 此处默认显示为_id,请根据需要自行修改为其他字段 -->
</template> <!-- 如果使用了联表查询,请参考生成的 admin 项目中 list.vue 页面的绑定字段的写法 -->
</uni-list-item> {{item._id}}
</uni-list> </text>
</view> </template>
<uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more> </uni-list-item>
</unicloud-db> </uni-list>
<uni-fab ref="fab" horizontal="right" vertical="bottom" :pop-menu="false" @fabClick="fabClick" /> </view>
</view> <uni-load-more :status="loading?'loading':(hasMore ? 'more' : 'noMore')"></uni-load-more>
</unicloud-db>
<uni-fab ref="fab" horizontal="right" vertical="bottom" :pop-menu="false" @fabClick="fabClick" />
</view>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return { return {
loadMore: { loadMore: {
contentdown: '', contentdown: '',
contentrefresh: '', contentrefresh: '',
contentnomore: '' contentnomore: ''
} },
} dataList: []
}, }
onPullDownRefresh() { },
this.$refs.udb.loadData({ onReady() {
clear: true this.dataList = this.$refs.udb.loadData()
}, () => { console.log("dataList: ",this.dataList);
uni.stopPullDownRefresh() },
}) onPullDownRefresh() {
}, this.$refs.udb.loadData({
onReachBottom() { clear: true
this.$refs.udb.loadMore() }, () => {
}, uni.stopPullDownRefresh()
methods: { })
handleItemClick(id) { },
uni.navigateTo({ onReachBottom() {
url: './detail?id=' + id this.$refs.udb.loadMore()
}) },
}, methods: {
fabClick() { handleItemClick(id) {
// 打开新增页面 uni.navigateTo({
uni.navigateTo({ url: './detail?id=' + id
url: './add', })
events: { },
// 监听新增数据成功后, 刷新当前页面数据 fabClick() {
refreshData: () => { // 打开新增页面
this.$refs.udb.loadData({ uni.navigateTo({
clear: true url: './add',
}) events: {
} // 监听新增数据成功后, 刷新当前页面数据
} refreshData: () => {
}) this.$refs.udb.loadData({
} clear: true
} })
} }
}
})
}
}
}
</script> </script>
<style> <style>
......
describe('pages/validate-demo/add.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.reLaunch('/pages/validate-demo/add')
if (process.env.UNI_PLATFORM === "h5"|| process.env.UNI_PLATFORM === "app-plus") {
await page.waitFor(1000)
}
if (process.env.UNI_PLATFORM === "mp-weixin") {
await page.waitFor(1000);//微信等待
}
page = await program.currentPage()
const formData = await page.data('formData')
})
beforeEach(async()=>{
jest.setTimeout(20000)
return false
})
it('输入表单内容', async () => {
let type = 1
let type_name = "数字天堂"
let comment = "我是备注消息"
let username = "林明"
let weight = 51
let email = "1076998870@qq.com"
let dowloadUrl = "https://dcloud.io/"
const setForm = await page.setData({
"formData": {
"type": type,
"type_name": type_name,
"comment": comment,
"username": username,
"email": email,
"dowload_url": dowloadUrl,
"weight": weight,
"favorite_book": "4",
"party_member": true,
"hobby": ["dance"],
"address": "110108"
}
})
console.log(await page.data('formData'), "setForm---");
//姓名只能输入中文
//expect(username).toMatch(/\u4e00-\u9fa5/);
//姓名不能超过5位数
if (type === 0 && type_name.length > 5) {
expect(type_name).toBeLessThan(5);
}
//企业名称不能低于4位数
if (type === 1 && type_name.length < 4) {
expect(type_name).toBeGreaterThan(4);
}
//expect(type_name).not.toBeUndefined();
//var re=/\w+@[a-z0-9]+\.[a-z]{2,4}/
expect(email).toMatch(/\w+@[a-z0-9]+\.[a-z]{2,4}/);
//url验证
const urlEx = /^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/;
expect(dowloadUrl).toMatch(urlEx);
//体重要大于50 小于或等于500
expect(weight).toBeGreaterThan(50)
expect(weight).toBeLessThanOrEqual(500)
await page.callMethod('submit')
})
})
{ {
"name": "uni-captcha", "name": "uni-captcha",
"version": "0.1.1", "version": "0.2.2",
"description": "uni-captcha", "description": "uni-captcha",
"main": "index.js", "main": "index.js",
"homepage": "https://ext.dcloud.net.cn/plugin?id=4048", "homepage": "https://ext.dcloud.net.cn/plugin?id=4048",
...@@ -9,5 +9,8 @@ ...@@ -9,5 +9,8 @@
"url": "git+https://gitee.com/dcloud/uni-captcha" "url": "git+https://gitee.com/dcloud/uni-captcha"
}, },
"author": "DCloud", "author": "DCloud",
"license": "Apache-2.0" "license": "Apache-2.0",
"dependencies": {
"uni-config-center": "file:../../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center"
}
} }
\ No newline at end of file
{
"name": "uni-config-center",
"version": "0.0.1",
"lockfileVersion": 1
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册