From e691801a164dc1b63e9fceca0d1af7e6ea4bb815 Mon Sep 17 00:00:00 2001 From: Anne_LXM <54163582+anne-lxm@users.noreply.github.com> Date: Mon, 27 Nov 2023 16:04:43 +0800 Subject: [PATCH] update test --- pages/clientDB/clientDB.test.js | 15 +-- pages/clientDB/demo/demo.test.js | 7 +- .../permission-demo/permission-demo.test.js | 5 +- pages/clientDB/permission-demo/readme.test.js | 101 +----------------- .../permission-field-simple.test.js | 5 +- .../permission-table-compound.test.js | 12 +-- .../permission-table-simple.test.js | 98 ++++++++--------- .../unicloud-db-demo/unicloud-db-demo.test.js | 43 ++------ .../unicloud-db-demo/unicloud-db-demo.vue | 6 +- pages/cloudObject/cloudObject.test.js | 6 +- pages/storage/storage.test.js | 4 - pages/user-info/add.test.js | 13 +-- pages/user-info/add.vue | 4 +- pages/validate-demo/add.test.js | 8 +- 14 files changed, 83 insertions(+), 244 deletions(-) diff --git a/pages/clientDB/clientDB.test.js b/pages/clientDB/clientDB.test.js index 4bff30f..a702d50 100644 --- a/pages/clientDB/clientDB.test.js +++ b/pages/clientDB/clientDB.test.js @@ -4,24 +4,13 @@ describe('pages/clientDB/clientDB.vue', () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.switchTab('/pages/clientDB/clientDB') await page.waitFor('view') - page = await program.currentPage() + // page = await program.currentPage() }) - it('当前页面-clientDB', async () => { - // await page.waitFor(1000) //expect.assertions(2); - console.log('await page.path: ',await page.path); expect(await page.path).toBe('pages/clientDB/clientDB') await page.waitFor(300) const list = await page.$$('.item') - // console.log("list: ",list); - // if(list){ - // const getList = await list.$$('.item') - // console.log("getList: ",getList); - // expect(getList.length).toBe(5) - // } - - + expect(list.length).toBe(5) }) - }) diff --git a/pages/clientDB/demo/demo.test.js b/pages/clientDB/demo/demo.test.js index e997441..eeb00f7 100644 --- a/pages/clientDB/demo/demo.test.js +++ b/pages/clientDB/demo/demo.test.js @@ -12,6 +12,7 @@ describe('pages/clientDB/demo/demo.vue', () => { it('未登陆', async () => { await roles[0].tap() const start = Date.now() + // console.log('start: ',start); const unLogin = await page.waitFor(async()=>{ if(Date.now() - start > 4000){ console.warn('连接服务器超时') @@ -20,9 +21,9 @@ describe('pages/clientDB/demo/demo.vue', () => { const unLoginRole = await page.data('currentRole') return unLoginRole === 0 }) + // console.log('Date.now(): ',Date.now()); console.log("未登陆: ",unLogin ); const commentBtn = await page.$('.comment-btn') - console.log(await commentBtn.text(),"text---------"); expect((await commentBtn.text()).trim()).toBe('写留言') }) it('用户', async () => { @@ -40,9 +41,7 @@ describe('pages/clientDB/demo/demo.vue', () => { if(user){ //新增一条留言 const userWrite = await page.callMethod('submitComment', '我是用户') - const usId = userWrite.id - console.log('usId: ',usId); - //expect(usId).not.toBeUndefined(); + expect(userWrite.id).toHaveLength(24); } }) it('审核员', async () => { diff --git a/pages/clientDB/permission-demo/permission-demo.test.js b/pages/clientDB/permission-demo/permission-demo.test.js index 16b08c5..17d5a04 100644 --- a/pages/clientDB/permission-demo/permission-demo.test.js +++ b/pages/clientDB/permission-demo/permission-demo.test.js @@ -7,7 +7,6 @@ describe('pages/clientDB/permission-demo/permission-demo.vue', () => { await page.waitFor('view') page = await program.currentPage() perPage = await page.$('.page') - if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM.startsWith("app") ) { //底部角色控制条 roles = await perPage.$$('.roles-item') @@ -17,11 +16,12 @@ describe('pages/clientDB/permission-demo/permission-demo.vue', () => { //底部角色控制条 roles = await setPer.$$('.roles-item') } - }) it('未登陆', async () => { await roles[0].tap() + await page.waitFor(500) console.log('rulo_index: ',await page.data('rulo_index')); + console.log('role: ',await page.data('role')); expect((await roles[0].text()).trim()).toBe('未登陆') }) @@ -47,7 +47,6 @@ describe('pages/clientDB/permission-demo/permission-demo.vue', () => { await toButton.tap() await page.waitFor(800) } - }) it('审核员', async () => { diff --git a/pages/clientDB/permission-demo/readme.test.js b/pages/clientDB/permission-demo/readme.test.js index bcf8342..727c055 100644 --- a/pages/clientDB/permission-demo/readme.test.js +++ b/pages/clientDB/permission-demo/readme.test.js @@ -1,14 +1,11 @@ describe('pages/clientDB/permission-demo/readme.vue', () => { - let page,perPage,setPer,roles; beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch( '/pages/clientDB/permission-demo/readme') await page.waitFor('view') - // page = await program.currentPage() perPage = await page.$('.page') - if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM.startsWith("app") ) { roles = await perPage.$$('.roles-item') } @@ -17,290 +14,196 @@ describe('pages/clientDB/permission-demo/readme.vue', () => { //底部角色控制条 roles = await setPer.$$('.roles-item') } - }) 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 () => { await roles[0].tap() - 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); - - + console.log("auditor",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); - - + console.log("admin",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 diff --git a/pages/clientDB/permission-field-simple/permission-field-simple.test.js b/pages/clientDB/permission-field-simple/permission-field-simple.test.js index 7ebd460..49d2f0b 100644 --- a/pages/clientDB/permission-field-simple/permission-field-simple.test.js +++ b/pages/clientDB/permission-field-simple/permission-field-simple.test.js @@ -199,14 +199,13 @@ describe('pages/clientDB/permission-field-simple/permission-field-simple.nvue', "type": "create", "index": 2, }) - console.log('createUserB: ',createUserB); - // expect(createUserB).toBe('[permission-test-12.ip.write]权限校验未通过') + // console.log('createUserB: ',createUserB); + expect(createUserB).toBe(errMsgA) await page.callMethod('myFn', { "type": "create", "index": 2, "field": "_id,state,create_time,text", }) - }) it('读取--用户', async () => { diff --git a/pages/clientDB/permission-table-compound/permission-table-compound.test.js b/pages/clientDB/permission-table-compound/permission-table-compound.test.js index 2854780..a8d7d74 100644 --- a/pages/clientDB/permission-table-compound/permission-table-compound.test.js +++ b/pages/clientDB/permission-table-compound/permission-table-compound.test.js @@ -214,15 +214,15 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "index": 0, "where": "create_time > 1613534788761" }) - console.log(readUserA,"readUserA---------"); - //expect(readUserA).toBe('权限校验未通过') + // console.log(readUserA,"readUserA---------"); + expect(readUserA).toBe(errMsgA) const readUserB = await page.callMethod('myFn', { "type": "read", "index": 0 }) - console.log(readUserB,"readUserB---------"); - //expect(readUserB).toBe('权限校验未通过') + // console.log(readUserB,"readUserB---------"); + expect(readUserB).toBe(errMsgA) await page.callMethod('myFn', { "type": "read", @@ -258,8 +258,8 @@ describe('pages/clientDB/permission-table-compound/permission-table-compound.vue "index": 0, "where": "create_time > 1613534788761" }) - console.log(updateUserA,"updateUserA---------"); - //expect(updateUserA).toBe('权限校验未通过') + // console.log(updateUserA,"updateUserA---------"); + expect(updateUserA).toBe(errMsgA) const updateUserB = await page.callMethod('myFn', { "type": "update", diff --git a/pages/clientDB/permission-table-simple/permission-table-simple.test.js b/pages/clientDB/permission-table-simple/permission-table-simple.test.js index bd438fb..836330f 100644 --- a/pages/clientDB/permission-table-simple/permission-table-simple.test.js +++ b/pages/clientDB/permission-table-simple/permission-table-simple.test.js @@ -37,7 +37,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "create", "index": 0 }) - expect(createA.success).toBeTruthy() + // console.log('createA: ',createA); + expect(createA.result.id).toHaveLength(24) // 禁止任何角色创建,管理员除外 const createB = await page.callMethod('myFn', { @@ -73,9 +74,9 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 6, "action": "add_view_count" }) - expect(createAction.success).toBeTruthy() + // console.log('createAction: ',createAction); + expect(createAction.result.id).toHaveLength(24) } - }) it('读取--未登陆', async () => { @@ -95,8 +96,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 0 }) - console.log('readA: ',readA); - // expect(readA.success).toBeTruthy() + // console.log('readA: ',readA); + expect(readA.result.data.length).toBeGreaterThanOrEqual(1) // 禁止任何角色读取 const readB = await page.callMethod('myFn', { @@ -132,8 +133,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 3 }) - console.log('readF: ',readF); - // expect(readF.errMsg).toBe(errMsgC) + // console.log('readF: ',readF); + // expect(readF.errMsg).toBe(errMsgB) // 只能读取1分钟内创建的数据,先创建数据 @@ -149,8 +150,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 4, "where": "create_time > 1613541303576" }) - console.log('readH: ',readH); - // expect(readH.success).toBeTruthy() + // console.log('readH: ',readH); // 读取全表数据 @@ -158,10 +158,9 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 4 }) - console.log('readI: ',readI); + // console.log('readI: ',readI); // expect(readI.errCode).toBe(0) - // 限审核员读取 const readJ = await page.callMethod('myFn', { "type": "create", @@ -182,7 +181,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 6, "action": "add_view_count" }) - expect(actionRead.errCode).toBe(0) + expect(actionRead.result.data.length).toBeGreaterThanOrEqual(1) } }) @@ -205,8 +204,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 0 }) // console.log('updateA: ',updateA); - // expect(updateA.result.updated).toBeGreaterThanOrEqual(1) - expect(updateA.result.errCode).toBe(0) + expect(updateA.result.updated).toBeGreaterThanOrEqual(1) // 禁止任何角色更新,管理员除外 const updateB = await page.callMethod('myFn', { @@ -242,8 +240,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 3 }) - console.log('updateF: ',updateF); - // expect(updateF.result.updated).toBe(0) + // console.log('updateF:---------- ',updateF); + expect(updateF.result.updated).toBe(0) // 只更新1分钟内创建的数据,先创建数据 const updateG = await page.callMethod('myFn', { @@ -258,6 +256,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 4, "where": "create_time > 1613546251521" }) + // console.log('updateH:------------------ ',updateH); expect(updateH.result.updated).toBe(0) // 更新全表数据 @@ -265,7 +264,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 4 }) - expect(updateI.success).toBeTruthy() + expect(updateI.result.updated).toBe(0) //限审核员更新全表数据 const updateJ = await page.callMethod('myFn', { @@ -288,7 +287,6 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "action": "add_view_count" }) expect(updateAction.result.updated).toBe(1) - } }) @@ -310,8 +308,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 0 }) // console.log("deleteA",deleteA); - // expect(deleteA.result.deleted).toBeGreaterThanOrEqual(0) - expect(deleteA.result.errCode).toBe(0) + expect(deleteA.result.deleted).toBeGreaterThanOrEqual(1) // 禁止任何角色删除,管理员除外 const deleteB = await page.callMethod('myFn', { @@ -347,9 +344,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "delete", "index": 3 }) - console.log('deleteF: ',deleteF); - // expect(deleteF.success).toBeTruthy() - // expect(deleteF.result.deleted).toBe(0) + // console.log('deleteF: ',deleteF); + expect(deleteF.result.deleted).toBe(0) // 只更新1分钟内创建的数据,先创建数据 const deleteG = await page.callMethod('myFn', { @@ -357,23 +353,19 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 4 }) expect(deleteG.errMsg).toBe(errMsgC) - + // 只更新1分钟内创建的数据 - expect(( - await page.callMethod('myFn', { - "type": "delete", - "index": 4, - "where": "create_time > 1613546644107" - }) - ).success).toBeTruthy() + await page.callMethod('myFn', { + "type": "delete", + "index": 4, + "where": "create_time > 1613546644107" + }) // 删除全表数据 - expect(( - await page.callMethod('myFn', { - "type": "delete", - "index": 4 - }) - ).success).toBeTruthy() + await page.callMethod('myFn', { + "type": "delete", + "index": 4 + }) // 删除全表 仅审核员 const deleteH = await page.callMethod('myFn', { @@ -395,7 +387,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 6, "action": "add_view_count" }) - expect(deleteAction.result.deleted).toBe(1) + // console.log('deleteAction: ',deleteAction); + expect(deleteAction.result.deleted).toBeGreaterThanOrEqual(1) }) it('创建--用户', async () => { @@ -469,7 +462,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 0 }) - console.log('readUserA: ',readUserA); + // console.log('readUserA: ',readUserA); + expect(readUserA.errCode).toBe(0) // expect(readUserA.result.data.length).toBeGreaterThan(0) // 仅管理员可读 @@ -484,7 +478,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 2 }) - console.log('readUserC: ',readUserC); + // console.log('readUserC: ',readUserC); + // expect(readUserA.errCode).toBe(0) expect(readUserC.result.data.length).toBeGreaterThan(0) // 只能读取自己创建的数据,先创建数据 @@ -500,7 +495,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 3, "where": "uid == $env.uid" }) - console.log('readUserE: ',readUserE); + // console.log('readUserE: ',readUserE); expect(readUserE.result.data.length).toBeGreaterThan(0) // 读取全表数据 @@ -508,7 +503,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 3 }) - console.log('readUserF: ',readUserF); + // console.log('readUserF: --------------',readUserF); expect(readUserF.result.data.length).toBeGreaterThan(0) // 只读取1分钟内创建的数据,先创建数据 @@ -524,7 +519,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 4, "where": "create_time > 1613541303576" }) - console.log('readUserH: ',readUserH); + // console.log('readUserH: ',readUserH); expect(readUserH.result.data.length).toBeGreaterThan(0) // 读取全表数据 @@ -532,7 +527,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "read", "index": 4 }) - console.log('readUserI: ',readUserI); + // console.log('readUserI: ',readUserI); expect(readUserI.result.data.length).toBeGreaterThanOrEqual(1) // 仅审核员读取全表数据 @@ -555,8 +550,9 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 6, "action": "add_view_count" }) - console.log('readUserO: ',readUserO); + // console.log('readUserO: ',readUserO); // expect(readUserO.result.data.length).toBeGreaterThan(0) + expect(readUserO.errCode).toBe(0) }) @@ -590,8 +586,7 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 2 }) - console.log('updateUserC: ',updateUserC); - // expect(updateUserC.result.updated).toBe(1) + expect(updateUserC.result.updated).toBeGreaterThanOrEqual(1) // 仅更新自己创建的数据 先创建数据 const updateUserD = await page.callMethod('myFn', { @@ -613,8 +608,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "type": "update", "index": 3 }) - // console.log('updateUserF: ',updateUserF); - expect(updateUserF.result.errCode).toBe(0) + // console.log('updateUserF: ------------------',updateUserF); + expect(updateUserF.result.updated).toBeGreaterThanOrEqual(1) // 只更新1分钟内创建的数据 先创建数据 const updateUserG = await page.callMethod('myFn', { @@ -658,9 +653,8 @@ describe('pages/clientDB/permission-table-simple/permission-table-simple.vue', ( "index": 6, "action": "add_view_count" }) - console.log('updateUserAction: ',updateUserAction); - // expect(updateUserAction.result.updated).toBe(1) - // expect(updateUserAction.errCode).toBe(0) + // console.log('updateUserAction: ',updateUserAction); + expect(updateUserAction.result.updated).toBeGreaterThanOrEqual(1) }) it('删除--用户', async () => { diff --git a/pages/clientDB/unicloud-db-demo/unicloud-db-demo.test.js b/pages/clientDB/unicloud-db-demo/unicloud-db-demo.test.js index 542069b..9292dcb 100644 --- a/pages/clientDB/unicloud-db-demo/unicloud-db-demo.test.js +++ b/pages/clientDB/unicloud-db-demo/unicloud-db-demo.test.js @@ -6,30 +6,23 @@ describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => { page = await program.reLaunch('/pages/clientDB/unicloud-db-demo/unicloud-db-demo') await page.waitFor('view') }) - - it("增-删", async () => { - const count = await page.data('getcount') - console.log("count: ",count); - /* expect.assertions(1); + it("增", async () => { + // 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(count).toBeTruthy() + await page.callMethod('add') + }) + it("删", async () => { + // const getDataList = await page.data('dataList') // expect(await getDataList.length).toBeGreaterThanOrEqual(1); - const removeData = await page.callMethod('remove') + await page.callMethod('remove') }) - - it("改", async () => { - const updateData = await page.callMethod('update') + await page.callMethod('update') }) - it("查", async () => { - const getFnData = await page.callMethod('getFn') + await page.callMethod('getFn') }) - it("只查一条数据", async () => { //开启只查一条 const swGetone = await page.$('.switch-getone') @@ -42,25 +35,20 @@ describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => { 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') @@ -70,7 +58,6 @@ describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => { //增加每页数据数量 const pageSizeAfter = await page.data('pageSize') expect(pageSizeAfter).toBeGreaterThanOrEqual(pageSizeBefore);//大于 - }) it("追加数据-add", async () => { @@ -82,7 +69,6 @@ describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => { const addText = await page.data('pageData') return addText === 'add' }) - if(isAdd){//加载更多 /* if (process.env.UNI_PLATFORM === "mp-weixin") { const toLoadMore = await page.$('.toLoadMore') @@ -93,7 +79,7 @@ describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => { if (process.env.UNI_PLATFORM === "h5" || process.env.UNI_PLATFORM.startsWith("app")) { const loadMore = await page.$('.loadMore') console.log('loadMore: ',loadMore); - await page.waitFor(300) + // await page.waitFor(300) await loadMore.tap() await page.waitFor(300) } @@ -104,17 +90,13 @@ describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => { 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() @@ -123,12 +105,10 @@ describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => { 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') @@ -136,5 +116,4 @@ describe('pages/clientDB/unicloud-db-demo/unicloud-db-demo', () => { field: ['create_date'], }) }) - }) diff --git a/pages/clientDB/unicloud-db-demo/unicloud-db-demo.vue b/pages/clientDB/unicloud-db-demo/unicloud-db-demo.vue index 9b7cbf5..60e80b7 100644 --- a/pages/clientDB/unicloud-db-demo/unicloud-db-demo.vue +++ b/pages/clientDB/unicloud-db-demo/unicloud-db-demo.vue @@ -208,7 +208,7 @@ success: (res) => { // 新增成功后的回调 console.log("res.result: ",res.result); this.getFn() - return res + return res.result } }) }, @@ -221,7 +221,9 @@ return await udb.update(_id,{book_id:"这条数据被改"}, { success: (res) => { // 新增成功后的回调 - return this.getFn() + console.log('res: ',res); + this.getFn() + return res.result } }) }, diff --git a/pages/cloudObject/cloudObject.test.js b/pages/cloudObject/cloudObject.test.js index 0508ae3..fcc2d22 100644 --- a/pages/cloudObject/cloudObject.test.js +++ b/pages/cloudObject/cloudObject.test.js @@ -33,13 +33,9 @@ describe('pages/cloudObject/cloudObject.vue', () => { }) it('查询前10条数据',async()=>{ - // expect.assertions(1); + expect.assertions(1); const getTenData = await page.callMethod('get') - 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()=>{ diff --git a/pages/storage/storage.test.js b/pages/storage/storage.test.js index 824cdf8..1f26078 100644 --- a/pages/storage/storage.test.js +++ b/pages/storage/storage.test.js @@ -6,17 +6,13 @@ describe('pages/storage/storage.vue', () => { page = await program.switchTab('/pages/storage/storage') await page.waitFor('view') }) - it('云存储页-检查标题',async()=>{ //expect.assertions(1); const content = await page.$('.content') const title = await content.$('.title') - console.log('content: ',content,await title.text()); expect(await title.text()).toBe('直接上传文件到云存储'); }) - // it('上传文件',async()=>{ // const upload = await page.callMethod('upload') // }) - }) \ No newline at end of file diff --git a/pages/user-info/add.test.js b/pages/user-info/add.test.js index c97ad48..82d2906 100644 --- a/pages/user-info/add.test.js +++ b/pages/user-info/add.test.js @@ -1,15 +1,11 @@ describe('pages/user-info/add.vue', () => { - let page beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch('/pages/user-info/add') await page.waitFor('view') - page = await program.currentPage() }) - it('输入表单内容', async () => { - let username = "林小明" let weight = 51 let mobile = "17769516066" @@ -33,26 +29,19 @@ describe('pages/user-info/add.vue', () => { "isTest":true }) //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); + await page.callMethod('submit') }) }) \ No newline at end of file diff --git a/pages/user-info/add.vue b/pages/user-info/add.vue index dbfbdfc..eb23698 100644 --- a/pages/user-info/add.vue +++ b/pages/user-info/add.vue @@ -127,13 +127,11 @@ }) return this.$refs.form.validate().then(async(res) => { console.log('res: ',res); - await this.submitForm(res) - return res + return await this.submitForm(res) }).catch(() => { uni.hideLoading() }) }, - async submitForm(value) { // 使用 clientDB 提交数据 return await db.collection(dbCollectionName).add(value).then((res) => { diff --git a/pages/validate-demo/add.test.js b/pages/validate-demo/add.test.js index 4c4dec4..9edfa96 100644 --- a/pages/validate-demo/add.test.js +++ b/pages/validate-demo/add.test.js @@ -1,15 +1,11 @@ describe('pages/validate-demo/add.vue', () => { - let page beforeAll(async () => { // 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象) page = await program.reLaunch('/pages/validate-demo/add') await page.waitFor('view') - page = await program.currentPage() }) - it('输入表单内容', async () => { - let type = 1 let type_name = "数字天堂" let comment = "我是备注消息" @@ -32,8 +28,7 @@ describe('pages/validate-demo/add.vue', () => { "address": "110108" } }) - - console.log(await page.data('formData'), "setForm---"); + // console.log(await page.data('formData'), "setForm---"); //姓名只能输入中文 //expect(username).toMatch(/\u4e00-\u9fa5/); @@ -59,6 +54,7 @@ describe('pages/validate-demo/add.vue', () => { expect(weight).toBeGreaterThan(50) expect(weight).toBeLessThanOrEqual(500) await page.callMethod('submit') + await page.waitFor(500) }) }) -- GitLab