From 1016a3ac011ad50a70566f89f62c4bb7003a28d5 Mon Sep 17 00:00:00 2001 From: anne-lxm <1076217653@qq.com> Date: Mon, 27 Sep 2021 20:38:19 +0800 Subject: [PATCH] =?UTF-8?q?jest=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../uni-send-sms-code/uni-send-sms-code.vue | 124 +++--- env.js | 30 ++ jest.config.js | 17 + manifest.json | 382 ++++++++---------- package.json | 16 +- pages/grid/grid.test.js | 40 ++ pages/grid/grid.vue | 6 +- pages/list/detail.test1.js | 20 + pages/list/list.nvue | 22 +- pages/list/list.test.js | 32 ++ pages/list/search/search.test.js | 34 ++ pages/ucenter/about/about.test.js | 32 ++ pages/ucenter/login-page/index/index.test1.js | 56 +++ .../login-page/phone-code/phone-code.test1.js | 37 ++ .../login-page/phone-code/phone-code.vue | 62 ++- .../login-page/pwd-login/pwd-login.test.js | 49 +++ .../login-page/pwd-login/pwd-login.vue | 105 +++-- .../pwd-retrieve/pwd-retrieve.test.js | 32 ++ .../login-page/pwd-retrieve/pwd-retrieve.vue | 66 ++- .../login-page/register/register.test.js | 55 +++ .../ucenter/login-page/register/register.vue | 62 ++- pages/ucenter/settings/settings.test.js | 25 ++ pages/ucenter/settings/settings.vue | 38 +- pages/ucenter/ucenter.test.js | 30 ++ pages/ucenter/ucenter.vue | 27 +- .../userinfo/bind-mobile/bind-mobile.test.js | 60 +++ .../userinfo/bind-mobile/bind-mobile.vue | 108 +++-- pages/ucenter/userinfo/userinfo.test.js | 35 ++ pages/ucenter/userinfo/userinfo.vue | 15 +- testSequencer.js | 16 + uni-starter.config.js | 42 +- .../uni-config-center/uni-id/config.json | 4 +- .../cloudfunctions/uni-id-cf/index.js | 10 +- vue.config.js | 9 + 34 files changed, 1237 insertions(+), 461 deletions(-) create mode 100644 env.js create mode 100644 jest.config.js create mode 100644 pages/grid/grid.test.js create mode 100644 pages/list/detail.test1.js create mode 100644 pages/list/list.test.js create mode 100644 pages/list/search/search.test.js create mode 100644 pages/ucenter/about/about.test.js create mode 100644 pages/ucenter/login-page/index/index.test1.js create mode 100644 pages/ucenter/login-page/phone-code/phone-code.test1.js create mode 100644 pages/ucenter/login-page/pwd-login/pwd-login.test.js create mode 100644 pages/ucenter/login-page/pwd-retrieve/pwd-retrieve.test.js create mode 100644 pages/ucenter/login-page/register/register.test.js create mode 100644 pages/ucenter/settings/settings.test.js create mode 100644 pages/ucenter/ucenter.test.js create mode 100644 pages/ucenter/userinfo/bind-mobile/bind-mobile.test.js create mode 100644 pages/ucenter/userinfo/userinfo.test.js create mode 100644 testSequencer.js create mode 100644 vue.config.js diff --git a/components/uni-send-sms-code/uni-send-sms-code.vue b/components/uni-send-sms-code/uni-send-sms-code.vue index 9cea476..2a512be 100644 --- a/components/uni-send-sms-code/uni-send-sms-code.vue +++ b/components/uni-send-sms-code/uni-send-sms-code.vue @@ -39,9 +39,9 @@ /* 验证码类型,用于防止不同功能的验证码混用,目前支持的类型login登录、register注册、bind绑定手机、unbind解绑手机 */ - codeType:{ + codeType: { type: String, - default(){ + default () { return 'login' } } @@ -52,14 +52,15 @@ reverseTimer: null }; }, - computed: { + computed: { innerText() { if (this.reverseNumber == 0) return this.$t('common').getVerifyCode; - return this.$t('smsCode.resendVerifyCode ')+ '('+this.reverseNumber+'s)'; + return this.$t('smsCode.resendVerifyCode') + '(' + this.reverseNumber + 's)'; } }, created() { this.initClick(); + // console.log(this.$t('smsCode.resendVerifyCode')); }, methods: { initClick() { @@ -68,63 +69,92 @@ this.sendMsg(); }) }, - sendMsg() { + async sendMsg() { let reg_phone = /^1\d{10}$/; - if(!reg_phone.test(this.phone))return uni.showToast({ + if (!reg_phone.test(this.phone)) return uni.showToast({ title: this.$t('smsCode.phoneErrTip'), icon: 'none' }); - uniCloud.callFunction({ - name:'uni-id-cf', - data:{ - action:'sendSmsCode', - params:{ + return await uniCloud.callFunction({ + name: 'uni-id-cf', + data: { + action: 'sendSmsCode', + params: { "mobile": this.phone, "type": this.codeType }, }, - success: ({result}) => { - console.log(result); - if(result.code===0){ - uni.showToast({ - title: this.$t('smsCode.sendSuccessTip'), - icon: 'none' - }); - this.reverseNumber = Number(this.count); - this.getCode(); - this.$emit('getCode'); - }else{ - uni.showModal({ - content: result.msg, - showCancel: false - }); - } + }).then(({result})=>{ + console.log(result); + if (result.code === 0) { + uni.showToast({ + title: this.$t('smsCode.sendSuccessTip'), + icon: 'none' + }); + this.reverseNumber = Number(this.count); + this.getCode(); + this.$emit('getCode'); + } else { + uni.showModal({ + content: result.msg, + showCancel: false + }); } + return result }) - }, - getCode() { - if (this.reverseNumber == 0) { - clearTimeout(this.reverseTimer); - this.reverseTimer = null; - return; - } - this.reverseNumber--; - this.reverseTimer = setTimeout(() => { - this.getCode(); - }, 1000) + + // uniCloud.callFunction({ + // name:'uni-id-cf', + // data:{ + // action:'sendSmsCode', + // params:{ + // "mobile": this.phone, + // "type": this.codeType + // }, + // }, + // success: ({result}) => { + // console.log(result); + // if(result.code===0){ + // uni.showToast({ + // title: this.$t('smsCode.sendSuccessTip'), + // icon: 'none' + // }); + // this.reverseNumber = Number(this.count); + // this.getCode(); + // this.$emit('getCode'); + // }else{ + // uni.showModal({ + // content: result.msg, + // showCancel: false + // }); + // } + // } + // }) + }, + getCode() { + if (this.reverseNumber == 0) { + clearTimeout(this.reverseTimer); + this.reverseTimer = null; + return; } + this.reverseNumber--; + this.reverseTimer = setTimeout(() => { + this.getCode(); + }, 1000) } } + } + diff --git a/env.js b/env.js new file mode 100644 index 0000000..4b3f357 --- /dev/null +++ b/env.js @@ -0,0 +1,30 @@ +module.exports = { + "compile": true, + "h5": { + "options": { + "headless": false + }, + "executablePath": "C:/Program Files/Google/Chrome/Application/chrome.exe" + }, + "mp-weixin": { + "port": 9420, + "account": "", + "args": "", + "cwd": "", + "launch": true, + "teardown": "disconnect", + "remote": false, + "executablePath": "C:/Users/liuxi/download/微信web开发者工具/cli.bat" + }, + "app-plus": { + "android": { + "id": "", + "executablePath": "D:/HX/alpha-3.1.3/HBuilderX/plugins/launcher/base/android_base.apk" + }, + "version": "", + "ios": { + "id": "", + "executablePath": "" + } + } +} diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..0f6fbea --- /dev/null +++ b/jest.config.js @@ -0,0 +1,17 @@ +const path = require('path'); +module.exports = { + testTimeout: 10000, + reporters: [ + 'default' + ], + watchPathIgnorePatterns: ['/node_modules/', '/dist/', '/.git/'], + moduleFileExtensions: ['js', 'json'], + rootDir: __dirname, + testMatch: ["/pages/**/*test.[jt]s?(x)"], + // testMatch: ["/pages/ucenter/login-page/pwd-retrieve/pwd-retrieve.test.js"], + testPathIgnorePatterns: ['/node_modules/'], + testSequencer:path.join(__dirname, "testSequencer.js") + //pages/ucenter/userinfo/userinfo.test.js + //pages/ucenter/login-page/pwd-login/pwd-login.test.js + +} diff --git a/manifest.json b/manifest.json index 4d879fd..ed7d6a8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,224 +1,198 @@ { - "name": "统一应用基本项目", - "appid": "请点击重新获取", - "description": "云端一体应用快速开发模版", - "versionName": "1.0.0", - "versionCode": "100", - "transformPx": false, - "app-plus": { - "locales": { - "en": { + "name" : "统一应用基本项目", + "appid" : "__UNI__D53040B", + "description" : "云端一体应用快速开发模版", + "versionName" : "1.0.0", + "versionCode" : "100", + "transformPx" : false, + "app-plus" : { + "locales" : { + "en" : { // 英文 - "name": "uni-starter", // 应用名称 - "android": { - "strings": { + "name" : "uni-starter", // 应用名称 + "android" : { + "strings" : { //Android平台自定义字符串 - "CustomKey": "CustomValue" - } - }, - "ios": { - "privacyDescription": { + "CustomKey" : "CustomValue" + } + }, + "ios" : { + "privacyDescription" : { //iOS平台隐私访问描述信息 - "NSPhotoLibraryUsageDescription": "access to the user’s photo library(read)" - }, - "infoPlist": { + "NSPhotoLibraryUsageDescription" : "access to the user’s photo library(read)" + }, + "infoPlist" : { //iOS平台自定义InfoPlist.strings - "CustomKey": "CustomValue" - } - } - }, - "zh": { + "CustomKey" : "CustomValue" + } + } + }, + "zh" : { // 中文(简体) - "name": "统一应用基本项目" // 应用名称 - } - }, - "privacy": { - "prompt": "template", - "template": { - "title": "服务协议和隐私政策", - "message": "  请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。
  你可阅读《服务协议》《隐私政策》了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。", - "buttonAccept": "同意", - "buttonRefuse": "暂不同意" - } - }, - "compatible": { - "ignoreVersion": true - }, - "usingComponents": true, - "nvueStyleCompiler": "uni-app", - "compilerVersion": 3, - "splashscreen": { - "alwaysShowBeforeRender": false, - "waiting": true, - "autoclose": true, - "delay": 0 - }, - "modules": { - "Fingerprint": { - }, - "Share": { - }, - "OAuth": { - }, - "FaceID": { - }, - "Push": { - }, - "Geolocation": { - } - }, - "distribute": { - "android": { - "permissions": [ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "" - ], - "abiFilters": [ - "armeabi-v7a", - "arm64-v8a", - "x86" - ] - }, - "ios": { - "capabilities": { - "entitlements": { - "com.apple.developer.associated-domains": [ - "applinks:static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com" - ] - } - } - }, - "sdkConfigs": { - "oauth": { - "apple": { - }, - "weixin": { - "appid": "", - "appsecret": "", - "UniversalLinks": "" - }, - "univerify": { - } + "name" : "统一应用基本项目" // 应用名称 + } }, - "ad": { + "privacy" : { + "prompt" : "template", + "template" : { + "title" : "服务协议和隐私政策", + "message" : "  请你务必审慎阅读、充分理解“服务协议”和“隐私政策”各条款,包括但不限于:为了更好的向你提供服务,我们需要收集你的设备标识、操作日志等信息用于分析、优化应用性能。
  你可阅读《服务协议》《隐私政策》了解详细信息。如果你同意,请点击下面按钮开始接受我们的服务。", + "buttonAccept" : "同意", + "buttonRefuse" : "暂不同意" + } }, - "share": { - "weixin": { - "appid": "", - "UniversalLinks": "" - } + "compatible" : { + "ignoreVersion" : true }, - "geolocation": { - "baidu": { - "__platform__": [ - "ios", - "android" - ], - "appkey_ios": "请填写地图的key", - "appkey_android": "请填写地图的key" - } + "usingComponents" : true, + "nvueStyleCompiler" : "uni-app", + "compilerVersion" : 3, + "splashscreen" : { + "alwaysShowBeforeRender" : false, + "waiting" : true, + "autoclose" : true, + "delay" : 0 }, - "push": { - "unipush": { - } + "modules" : { + "Fingerprint" : {}, + "OAuth" : {}, + "FaceID" : {}, + "Push" : {}, + "Geolocation" : {} }, - "payment": { - } - }, - "icons": { - "android": { - "hdpi": "", - "xhdpi": "", - "xxhdpi": "", - "xxxhdpi": "" + "distribute" : { + "android" : { + "permissions" : [ + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" + ], + "abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ] + }, + "ios" : { + "capabilities" : { + "entitlements" : { + "com.apple.developer.associated-domains" : [ "applinks:static-76ce2c5e-31c7-4d81-8fcf-ed1541ecbc6e.bspapp.com" ] + } + } + }, + "sdkConfigs" : { + "oauth" : { + "apple" : {}, + "univerify" : {} + }, + "ad" : {}, + "share" : { + "weixin" : { + "appid" : "", + "UniversalLinks" : "" + } + }, + "geolocation" : { + "baidu" : { + "__platform__" : [ "ios", "android" ], + "appkey_ios" : "请填写地图的key", + "appkey_android" : "请填写地图的key" + } + }, + "push" : { + "unipush" : {} + }, + "payment" : {} + }, + "icons" : { + "android" : { + "hdpi" : "", + "xhdpi" : "", + "xxhdpi" : "", + "xxxhdpi" : "" + }, + "ios" : { + "appstore" : "", + "ipad" : { + "app" : "", + "app@2x" : "", + "notification" : "", + "notification@2x" : "", + "proapp@2x" : "", + "settings" : "", + "settings@2x" : "", + "spotlight" : "", + "spotlight@2x" : "" + }, + "iphone" : { + "app@2x" : "", + "app@3x" : "", + "notification@2x" : "", + "notification@3x" : "", + "settings@2x" : "", + "settings@3x" : "", + "spotlight@2x" : "", + "spotlight@3x" : "" + } + } + }, + "splashscreen" : { + "iosStyle" : "common", + "androidStyle" : "common" + } + }, + "nvueLaunchMode" : "" + }, + "quickapp" : {}, + "mp-weixin" : { + "appid" : "", + "setting" : { + "urlCheck" : false, + "es6" : false }, - "ios": { - "appstore": "", - "ipad": { - "app": "", - "app@2x": "", - "notification": "", - "notification@2x": "", - "proapp@2x": "", - "settings": "", - "settings@2x": "", - "spotlight": "", - "spotlight@2x": "" - }, - "iphone": { - "app@2x": "", - "app@3x": "", - "notification@2x": "", - "notification@3x": "", - "settings@2x": "", - "settings@3x": "", - "spotlight@2x": "", - "spotlight@3x": "" - } + "usingComponents" : true, + "betterScopedSlots" : true, + "permission" : { + "scope.userLocation" : { + "desc" : "演示在onShow生命周期获取地理位置" + } } - }, - "splashscreen": { - "iosStyle": "common", - "androidStyle": "common" - } }, - "nvueLaunchMode": "" - }, - "quickapp": { - }, - "mp-weixin": { - "appid": "", - "setting": { - "urlCheck": false, - "es6": false + "mp-alipay" : { + "usingComponents" : true + }, + "mp-baidu" : { + "usingComponents" : true }, - "usingComponents": true, - "betterScopedSlots": true, - "permission": { - "scope.userLocation": { - "desc": "演示在onShow生命周期获取地理位置" - } - } - }, - "mp-alipay": { - "usingComponents": true - }, - "mp-baidu": { - "usingComponents": true - }, - "mp-toutiao": { - "usingComponents": true - }, - "uniStatistics": { - "enable": false - }, - "h5": { - "template": "", - "sdkConfigs": { - "maps": { - "qqmap": { - "key": "" + "mp-toutiao" : { + "usingComponents" : true + }, + "uniStatistics" : { + "enable" : false + }, + "h5" : { + "template" : "", + "sdkConfigs" : { + "maps" : { + "qqmap" : { + "key" : "" + } + } } - } - } - }, - "_spaceID": "", - "vueVersion": "2" + }, + "_spaceID" : "", + "vueVersion" : "2" } //... // 中文(简体) // 应用名称 + diff --git a/package.json b/package.json index f6a9ffd..28b42c7 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,12 @@ "version": "1.1.9", "description": "云端一体应用快速开发基本项目模版", "keywords": [ - "login", - "登录", - "搜索", - "uni-id例子", - "留言板" - ], + "login", + "登录", + "搜索", + "uni-id例子", + "留言板" + ], "repository": "https://codechina.csdn.net/dcloud/uni-starter.git", "engines": { "HBuilderX": "^3.1.20" @@ -81,5 +81,7 @@ } } }, - "dependencies": {} + "dependencies": { + "@jest/test-sequencer": "^27.0.6" + } } diff --git a/pages/grid/grid.test.js b/pages/grid/grid.test.js new file mode 100644 index 0000000..cc37b18 --- /dev/null +++ b/pages/grid/grid.test.js @@ -0,0 +1,40 @@ +// jest官方文档: https://www.jestjs.cn/ +// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start + +describe('pages/grid/grid.vue', () => { + let page + beforeAll(async () => { + page = await program.switchTab('/pages/grid/grid') + await page.waitFor(500) + }) + + it('检测宫格', async () => { + // expect.assertions(1); + // const perPage = await page.$('.warp') + // const getData = await perPage.data('gridList') + // console.log("getData: ",getData); + // expect(getData.length).toBe(9) + expect.assertions(1); + const getData = await page.data('gridList') + console.log("getData: ",getData); + expect(getData.length).toBe(9) + + }) + + it('点击宫格', async () => { + // expect.assertions(1); + const perPage = await page.$('.warp') + const uGrid = await perPage.$('.uni-grid-box') + console.log("uGrid-----------: ",uGrid); + + // await uGrid.callMethod('change') + + // const tapRes = await uGrid.tap() + // const tapRes = await uGrid.callMethod('change') + // await page.waitFor(300) + // console.log("tapRes: ",tapRes); + }) + + + +}); \ No newline at end of file diff --git a/pages/grid/grid.vue b/pages/grid/grid.vue index 55a04b7..00a9a4e 100644 --- a/pages/grid/grid.vue +++ b/pages/grid/grid.vue @@ -25,7 +25,7 @@ - +