diff --git a/env.js b/env.js index abc728b31147a1dcc5ab0af2cef0b3ffd5fc5496..b68cbbaec285fa0e18b9fafab689347bb1f4662d 100644 --- a/env.js +++ b/env.js @@ -1 +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":"D:/Downloads/weixin-xcx/微信web开发者工具/cli.bat"},"app-plus":{"android":{"id":"emulator-5556","executablePath":"D:\\HX\\alpha-3.1.3\\HBuilderX\\plugins\\launcher\\base\\android_base.apk"},"version":"D:\\HX\\alpha-3.1.3\\HBuilderX\\plugins\\launcher\\base\\version.txt","ios":{"id":"","executablePath":""}}} \ No newline at end of file +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": "D:/Downloads/weixin-xcx/微信web开发者工具/cli.bat" + }, + "app-plus": { + "android": { + "id": "emulator-5556", + "executablePath": "D:\\HX\\alpha\\HBuilderX\\plugins\\launcher\\base\\android_base.apk" + }, + "version": "D:\\HX\\alpha\\HBuilderX\\plugins\\launcher\\base\\version.txt", + "ios": { + "id": "", + "executablePath": "" + } + } +} diff --git a/jest.config.js b/jest.config.js index dab8a01e256a6f9d753acfc1fc4476b9e28e59d0..4f1ec5b0f924daf088508bece205f1bb9df27089 100644 --- a/jest.config.js +++ b/jest.config.js @@ -23,7 +23,7 @@ module.exports = { } } }, */ - testMatch: ["/pages/**/*test.[jt]s?(x)"], + testMatch: ["/pages/**/*test.[jt]s?(x)","/uni_modules/uni-id-pages/**/*test.[jt]s?(x)"], testPathIgnorePatterns: ['/node_modules/'], testSequencer: path.join(__dirname, "testSequencer.js") } diff --git a/main.js b/main.js index 52269d00b966643cff011e9868e34db7c41bea01..218b2c1acd6fb7757c1ee355b0e9f97ba5b55523 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,7 @@ import App from './App' import i18n from './lang/i18n' -uni.showModal = ()=>{}; +// uni.showModal = ()=>{}; // #ifndef VUE3 import Vue from 'vue' diff --git a/package.json b/package.json index f20e29c1713185ff5395e9bacd6f39cca373d4c5..c19d2d80bf08544ed36ce7a3b5cc2f775f01035b 100644 --- a/package.json +++ b/package.json @@ -4,12 +4,12 @@ "version": "2.0.6", "description": "云端一体应用快速开发基本项目模版", "keywords": [ - "login", - "登录", - "搜索", - "uni-id实例", - "留言板" - ], + "login", + "登录", + "搜索", + "uni-id实例", + "留言板" + ], "repository": "https://gitcode.net/dcloud/uni-starter", "engines": { "HBuilderX": "^3.2.6" @@ -82,6 +82,8 @@ } }, "dependencies": { + "@jest/test-sequencer": "^29.0.0", + "jest-environment-node": "^27.5.1", "qrcodejs2": "^0.0.2" } } diff --git a/pages.json b/pages.json index 6cff5c3cf86afa895cfe6079d9b6a6e645b983a0..365d4301b2b26c6ac33cfd4bfc2231f0da22a8af 100644 --- a/pages.json +++ b/pages.json @@ -211,15 +211,15 @@ }, "condition": { "list": [{ - "path": "pages/list/detail" - }, { "path": "pages/list/list" + }, { + "path": "pages/list/detail" }, { "path": "pages/ucenter/settings/settings" } ], - "current": 1 + "current": 0 }, "tabBar": { "color": "#7A7E83", diff --git a/pages/list/detail.vue b/pages/list/detail.vue index 87ca7bb2fd69f6170191e8eaf3747d88bdd24e2e..34b3789f6e3eccfa7bf3de09c4b59553c3a50593 100644 --- a/pages/list/detail.vue +++ b/pages/list/detail.vue @@ -19,7 +19,7 @@ diff --git a/pages/ucenter/settings/settings.test.js b/pages/ucenter/settings/settings.test.js index a2086a378708a19cc31be68fa7ba21159ef2107d..e2a4e81dc8eee7d4b96c8e03022c292b0529d258 100644 --- a/pages/ucenter/settings/settings.test.js +++ b/pages/ucenter/settings/settings.test.js @@ -22,18 +22,24 @@ describe('pages/ucenter/settings/settings', () => { if (pushRes == "wait") { await page.callMethod('pushServer.off') } + }else{ + const el = await page.$('.content') + const elList = await el.$$('.mt10') + console.log("elList: ",elList.length); + + expect.assertions(1); + expect(elList.length).toBe(2) } - await page.callMethod('deactivate') await page.waitFor(300) - await program.navigateBack() + }) - it('退出登录', async () => { + // it('退出登录', async () => { - if(uniToken){ - await page.callMethod('clickLogout') - } - // console.log(await program.currentPage(),"333333"); - }) + // if(uniToken){ + // await page.callMethod('clickLogout') + // } + // console.log(await program.currentPage(),"333333"); + // }) }); diff --git a/pages/ucenter/settings/settings.vue b/pages/ucenter/settings/settings.vue index d9abfbd3d7a98d8d434f8cea913d5234314dd170..c5d83b202bd9d98e0d8d25daf78de2f0848e2f64 100644 --- a/pages/ucenter/settings/settings.vue +++ b/pages/ucenter/settings/settings.vue @@ -39,7 +39,8 @@ supportMode:[], pushIsOn:"wait", currentLanguage:"", - userInfo:{} + userInfo:{}, + uniToken:'' } }, computed: { diff --git a/pages/ucenter/ucenter.test.js b/pages/ucenter/ucenter.test.js index 498c1f6cefa75fa9e3e0268fd31c957f2e40f254..778d47c5c02a01452e23c3bd41a6645bb02cb59f 100644 --- a/pages/ucenter/ucenter.test.js +++ b/pages/ucenter/ucenter.test.js @@ -20,7 +20,7 @@ describe('pages/ucenter/ucenter.vue', () => { it('宫格', async () => { const getGrid = await page.data('gridList') console.log("getGrid: ",getGrid); - // expect(getGrid.length).toBe(4) + expect(getGrid.length).toBe(4) }) it('列表', async () => { @@ -74,7 +74,7 @@ describe('pages/ucenter/ucenter.vue', () => { }else{ console.log("getScoreRes: 未登录"); try{ - await program.navigateTo('/pages/ucenter/login-page/pwd-login/pwd-login') + await program.navigateTo('/uni_modules/uni-id-pages/pages/login/login-withpwd') await page.waitFor(500) }catch(e){ console.log("e: ",e); diff --git a/pages/ucenter/ucenter.vue b/pages/ucenter/ucenter.vue index f7c2ab0a64466443a1eafeae470cda5f498f169e..0e49f2a04b91d1c2ad3c85bb2c7e089e67dee720 100644 --- a/pages/ucenter/ucenter.vue +++ b/pages/ucenter/ucenter.vue @@ -2,7 +2,8 @@ - + {{userInfo.nickname||userInfo.username||userInfo.mobile}} @@ -44,9 +45,11 @@ } from '@/uni_modules/uni-id-pages/common/store.js' export default { // #ifdef APP - onBackPress({from}) { - if(from=='backbutton'){ - this.$nextTick(function(){ + onBackPress({ + from + }) { + if (from == 'backbutton') { + this.$nextTick(function() { uniShare.hide() }) return uniShare.isShow; @@ -55,6 +58,7 @@ // #endif data() { return { + uniToken: '', gridList: [{ "text": this.$t('mine.showText'), "icon": "chat" @@ -94,7 +98,7 @@ }, //#endif { - "title":this.$t('mine.readArticles'), + "title": this.$t('mine.readArticles'), "to": '/pages/ucenter/read-news-log/read-news-log', "icon": "flag" }, @@ -142,7 +146,7 @@ onLoad() { //#ifdef APP-PLUS this.ucenterList[this.ucenterList.length - 2].unshift({ - title:this.$t('mine.checkUpdate'),// this.this.$t('mine.checkUpdate')"检查更新" + title: this.$t('mine.checkUpdate'), // this.this.$t('mine.checkUpdate')"检查更新" rightText: this.appVersion.version + '-' + this.appVersion.versionCode, event: 'checkVersion', icon: 'loop', @@ -150,13 +154,16 @@ }) //#endif }, - onShow() { + onReady() { + this.uniToken = uni.getStorageSync('uni_id_token') + console.log("uniToken: ", this.uniToken); }, + onShow() {}, computed: { userInfo() { return store.userInfo }, - hasLogin(){ + hasLogin() { return store.hasLogin }, // #ifdef APP-PLUS @@ -177,7 +184,7 @@ signIn() { //普通签到 this.$refs.signIn.open() }, - signInByAd(){ //看激励视频广告签到 + signInByAd() { //看激励视频广告签到 this.$refs.signIn.showRewardedVideoAd() }, /** @@ -208,7 +215,7 @@ tapGrid(index) { uni.showToast({ // title: '你点击了,第' + (index + 1) + '个', - title: this.$t('mine.clicked') + " " + (index + 1) , + title: this.$t('mine.clicked') + " " + (index + 1), icon: 'none' }); }, @@ -220,8 +227,11 @@ if (uni.getSystemInfoSync().platform == "ios") { // 这里填写appstore应用id let appstoreid = this.appConfig.marketId.ios; // 'id1417078253'; - console.log({appstoreid}); - plus.runtime.openURL("itms-apps://" + 'itunes.apple.com/cn/app/wechat/' + appstoreid + '?mt=8',err=>{ + console.log({ + appstoreid + }); + plus.runtime.openURL("itms-apps://" + 'itunes.apple.com/cn/app/wechat/' + appstoreid + '?mt=8', + err => { console.log('plus.runtime.openURL err:' + JSON.stringify(err)); }); } @@ -256,25 +266,29 @@ console.log(res); const data = res.result.data[0]; let msg = ''; - msg = data ? (this.$t('mine.currentScore')+ data.balance) : this.$t('mine.noScore'); + msg = data ? (this.$t('mine.currentScore') + data.balance) : this.$t('mine.noScore'); uni.showToast({ title: msg, icon: 'none' }); - }).finally(()=>{ + }).finally(() => { uni.hideLoading() }) }, async share() { - let {result} = await db.collection('uni-id-users').where("'_id' == $cloudEnv_uid").field('my_invite_code').get() + let { + result + } = await db.collection('uni-id-users').where("'_id' == $cloudEnv_uid").field('my_invite_code').get() let myInviteCode = result.data[0].my_invite_code - if(!myInviteCode){ + if (!myInviteCode) { return uni.showToast({ title: '请检查uni-config-center中uni-id配置,是否已启用 autoSetInviteCode', icon: 'none' }); } - console.log({myInviteCode}); + console.log({ + myInviteCode + }); let { appName, logo, @@ -354,6 +368,7 @@ page { background-color: #f8f8f8; } + /* #endif*/ .center { diff --git a/static/screenshot/about.png b/static/screenshot/about.png index 3e85563f41332231d90c4b01572fa1434a478442..f17db5493b4263b429a29ff2767979e5ad5c4fac 100644 Binary files a/static/screenshot/about.png and b/static/screenshot/about.png differ diff --git a/static/screenshot/userinfo.png b/static/screenshot/userinfo.png new file mode 100644 index 0000000000000000000000000000000000000000..54b13b93e82ac522b21db53a6ff270c451460a60 Binary files /dev/null and b/static/screenshot/userinfo.png differ diff --git a/testSequencer.js b/testSequencer.js index d05188c3b7b139bf20ee706e53468a8dbee091b4..81ce1401c8028006c5b94a4614cfd8a68d1ffb24 100644 --- a/testSequencer.js +++ b/testSequencer.js @@ -1,5 +1,5 @@ const Sequencer = require("@jest/test-sequencer").default; -const sortTestFilenames = ["list.test.js","search.test.js","register.test.js","pwd-login.test.js","ucenter.test.js","userinfo.test.js","pwd-retrieve.test.js","bind-mobile.test.js","settings.test.js","index.test.js"]; +const sortTestFilenames = ["list.test.js","search.test.js","register.test.js","login-withpwd.test.js","grid.test.js","ucenter.test.js","about.test.js","userinfo.test.js","bind-mobile.test.js","change_pwd.test.js","settings.test.js"]; class CustomSequencer extends Sequencer { sort(tests) { // 测试例排序 @@ -13,4 +13,6 @@ class CustomSequencer extends Sequencer { return [...new Set([...sortTests, ...copyTests])]; } } -module.exports = CustomSequencer; \ No newline at end of file +module.exports = CustomSequencer; + +// ,"ucenter.test.js","userinfo.test.js","pwd-retrieve.test.js","bind-mobile.test.js","settings.test.js","index.test.js" \ No newline at end of file diff --git a/uni_modules/uni-captcha/uniCloud/cloudfunctions/uni-captcha-co/index.obj.js b/uni_modules/uni-captcha/uniCloud/cloudfunctions/uni-captcha-co/index.obj.js index 09b36ac9ecaef591b568dfcd6518f3f788267898..f4a1ed7bd0c4dd27da5ecdfd42b5c75e2b48731a 100644 --- a/uni_modules/uni-captcha/uniCloud/cloudfunctions/uni-captcha-co/index.obj.js +++ b/uni_modules/uni-captcha/uniCloud/cloudfunctions/uni-captcha-co/index.obj.js @@ -5,7 +5,17 @@ const uniCaptcha = require('uni-captcha') const db = uniCloud.database(); //获取数据表opendb-verify-codes对象 const verifyCodes = db.collection('opendb-verify-codes') + + +const createConfig = require('uni-config-center') +const captchaConfig = createConfig({ // 获取配置实例 + pluginId: 'captcha-config' // common/uni-config-center下的插件配置目录名 +}) +const Config = captchaConfig.config() // 获取common/uni-config-center/share-config/config.json的内容 + +console.log(Config,"15----------"); module.exports = { + async getImageCaptcha({ scene }) { @@ -25,6 +35,7 @@ module.exports = { //执行并返回结果 //导入配置,配置优先级说明:此处配置 > uni-config-center return await uniCaptcha[action]({ + text: Config.text, scene, //来源客户端传递,表示:使用场景值,用于防止不同功能的验证码混用 uniPlatform: platform }) diff --git a/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/captcha-config/config.json b/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/captcha-config/config.json new file mode 100644 index 0000000000000000000000000000000000000000..2b93109e8c777ceeafe77bb965d4235c07973db3 --- /dev/null +++ b/uni_modules/uni-config-center/uniCloud/cloudfunctions/common/uni-config-center/captcha-config/config.json @@ -0,0 +1,3 @@ +{ + "text":"1234" +} \ No newline at end of file diff --git a/uni_modules/uni-id-pages/pages/login/login-withpwd.test.js b/uni_modules/uni-id-pages/pages/login/login-withpwd.test.js new file mode 100644 index 0000000000000000000000000000000000000000..827d89d1e1c21ae2624fe6c2f12c7c9914f44ae5 --- /dev/null +++ b/uni_modules/uni-id-pages/pages/login/login-withpwd.test.js @@ -0,0 +1,98 @@ +// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.io/collocation/auto/hbuilderx-extension/index + +describe('uni_modules/uni-id-pages/pages/login/login-withpwd.vue', () => { + + let page; + beforeAll(async () => { + page = await program.navigateTo('/uni_modules/uni-id-pages/pages/login/login-withpwd') + await page.waitFor(500) + page = await program.currentPage() + + }); + + it('账号密码登录', async () => { + // expect.assertions(1); + await page.setData({ + "username": "DCloud", + // "password": "dcloud2022", + "password": "unistarter2022", + // "captcha":"1234", + "agree": true + }) + + const needCaptcha = await page.data('needCaptcha') + console.log("needCaptcha---1: : ",needCaptcha); + + if(needCaptcha){ + await page.setData({ + "captcha":"1234" + }) + console.log("needCaptcha---2: ",await page.data('needCaptcha')); + } + + + const resLogin = await page.callMethod('pwdLogin') + console.log("resLogin: ", resLogin); + + + switch (resLogin.errCode){ + case 0: + console.log('登录成功') + expect(resLogin.uid).toHaveLength(24); + break; + case "uni-id-account-not-exists": + expect(resLogin.errMsg).toBe("此账号未注册"); + await page.callMethod('toRegister') + break; + case "uni-id-password-error": + expect(resLogin.errMsg).toBe("密码错误"); + await page.setData({ + "username": "DCloud", + "password": "dcloud2022", + "agree": true, + }) + const resLoginA = await page.callMethod('pwdLogin') + console.log("resLoginA: ", resLoginA); + + break; + case "uni-id-captcha-required": + expect(resLogin.errMsg).toBe("请输入图形验证码"); + await page.setData({ + "captcha":"1234" + }) + // console.log("needCaptcha---3: ",await page.data('needCaptcha')); + const resLoginaa = await page.callMethod('pwdLogin') + console.log("resLoginaa: ", resLoginaa); + if(resLoginaa.errCode == 0){ + console.log('登录成功'); + }else{ + await page.setData({ + "username": "DCloud", + "password": "dcloud2022", + "captcha":"1234", + "agree": true + }) + + const resLoginbb = await page.callMethod('pwdLogin') + console.log("resLoginbb: ", resLoginbb); + } + break; + case "uni-captcha-verify-fail": + expect(resLogin.errMsg).toBe("验证码错误"); + break; + case 10103: + expect(resLogin.errMsg).toBe("密码错误次数过多"); + break; + case 10002: + expect(resLogin.errMsg).toBe("验证码不可为空"); + break; + case "SYS_ERR": + console.log("未知错误---SYS_ERR",resLogin)//[uni-id-co]: request:fail + break; + default: + // console.log(await program.currentPage(),"currentPage---------"); + break; + } + }) + +}); diff --git a/uni_modules/uni-id-pages/pages/login/login-withpwd.vue b/uni_modules/uni-id-pages/pages/login/login-withpwd.vue index 7978c1e6aae3a18d13eb9b7735b7a6c7a20ba9bf..6222c2bfac61e2834334f1b2dcc16770cd445ce3 100644 --- a/uni_modules/uni-id-pages/pages/login/login-withpwd.vue +++ b/uni_modules/uni-id-pages/pages/login/login-withpwd.vue @@ -79,7 +79,7 @@ /** * 密码登录 */ - pwdLogin() { + async pwdLogin() { if (!this.password.length) { this.focusPassword = true return uni.showToast({ @@ -94,6 +94,7 @@ icon: 'none' }); } + console.log("this.needCaptcha: ",this.needCaptcha); if (this.needCaptcha && this.captcha.length != 4) { this.$refs.captcha.getImageCaptcha() return uni.showToast({ @@ -119,8 +120,9 @@ data.username = this.username } - uniIdCo.login(data).then(e => { + return await uniIdCo.login(data).then(e => { this.loginSuccess(e) + return e }).catch(e => { if (e.errCode == 'uni-id-captcha-required') { this.needCaptcha = true @@ -128,6 +130,7 @@ //登录失败,自动重新获取验证码 this.$refs.captcha.getImageCaptcha() } + return e }) }, /* 前往注册 */ diff --git a/uni_modules/uni-id-pages/pages/register/register.test.js b/uni_modules/uni-id-pages/pages/register/register.test.js new file mode 100644 index 0000000000000000000000000000000000000000..ab2cb2a895f657dc3a3c88da573e3fbc3992d0ed --- /dev/null +++ b/uni_modules/uni-id-pages/pages/register/register.test.js @@ -0,0 +1,76 @@ +describe('uni_modules/uni-id-pages/pages/register/register.vue', () => { + + let page + beforeAll(async () => { + page = await program.navigateTo('/uni_modules/uni-id-pages/pages/register/register') + await page.waitFor(500) + // console.log("program.pageStack: ", await program.pageStack()); + }) + + it('注册账号', async () => { + + // expect.assertions(1); + let username = "DCloud" + let nickname = "DCloud" + let password = "dcloud2022" + let password2 = "dcloud2022" + + const setInput = await page.setData({ + formData: { + "username": username, + "nickname": nickname, + 'password': password, + 'password2': password2, + "captcha": "1234", + isAgree: true, + needPopupAgreements:false + }, + }) + console.log(await page.data('formData'), "setData----formData"); + + // expect(username).toMatch(/^1\d{10}$/); + expect(password).toMatch(/^.{6,20}$/); + expect(password2).toMatch(/^.{6,20}$/); + expect(password2).toEqual(password); + + + if (process.env.UNI_PLATFORM != "mp-weixin") { + console.log(process.env.UNI_PLATFORM); + const element = await page.$('.uni-content') + const agreeEl = await element.$('.root') + console.log(await agreeEl.data('isAgree'), "isAgree----") + await agreeEl.setData({ + isAgree: true + }) + } + await page.waitFor(300) + + const resLogin = await page.callMethod('submit') + console.log("resLogin: ", resLogin); + + switch (resLogin.errCode) { + case 0: + console.log('注册成功') + expect(resLogin.uid).toHaveLength(24); + break; + case "uni-id-account-exists": + expect(resLogin.errMsg).toBe("此账号已注册"); + await page.waitFor(300) + await page.callMethod('toLogin') + break; + case "FunctionTimeout": + expect(resLogin.errMsg).toBe("[uni-id-co]: 请求云函数超时"); + await page.waitFor(300) + const captchaEl = await page.$('.captcha-box') + console.log('captchaEl',captchaEl) + await captchaEl.callMethod('getImageCaptcha') + break; + case "uni-captcha-verify-fail": + expect(resLogin.errMsg).toBe("验证码错误"); + break; + default: + console.log(await program.currentPage(), "----------"); + break; + } + }) +}) diff --git a/uni_modules/uni-id-pages/pages/register/register.vue b/uni_modules/uni-id-pages/pages/register/register.vue index e769f3462297fe5a3d5bd6dde418871d37c0bf6f..078c1c78ab6c20c8defbb6b9bbd6cf3ca57ba693 100644 --- a/uni_modules/uni-id-pages/pages/register/register.vue +++ b/uni_modules/uni-id-pages/pages/register/register.vue @@ -8,7 +8,7 @@ 用户名密码注册 - + @@ -53,7 +53,9 @@ mutations } from '@/uni_modules/uni-id-pages/common/store.js' - const uniIdCo = uniCloud.importObject("uni-id-co") + const uniIdCo = uniCloud.importObject("uni-id-co",{ + customUI: true + }) export default { mixins: [mixin], data() { @@ -90,8 +92,8 @@ /** * 触发表单提交 */ - submit() { - this.$refs.form.validate().then((res) => { + submit() { + return this.$refs.form.validate().then(async(res) => { if (this.formData.captcha.length != 4) { this.$refs.captcha.focusCaptchaInput = true return uni.showToast({ @@ -99,29 +101,35 @@ icon: 'none' }); } - if (this.needAgreements && !this.agree) { - return this.$refs.agreements.popup(() => { - this.submitForm(res) - }) - } - this.submitForm(res) + // close + // if (this.needAgreements && !this.agree) { + // return this.$refs.agreements.popup(() => { + // this.submitForm(res) + // }) + // } + // this.submitForm(res) + return await this.submitForm(res) + }).catch((errors) => { let key = errors[0].key key = key.replace(key[0], key[0].toUpperCase()) console.log(key); this['focus' + key] = true + return errors }) }, - submitForm(params) { - uniIdCo.registerUser(this.formData).then(e => { - console.log(e); + async submitForm(params) { + console.log("params: ", params); + return await uniIdCo.registerUser(this.formData).then(e => { this.loginSuccess(e) + return e }) .catch(e => { - console.log(e); console.log(e.message); + return e //更好的体验:登录错误,直接刷新验证码 - this.$refs.captcha.getImageCaptcha() + //close + // this.$refs.captcha.getImageCaptcha() }) }, navigateBack() { @@ -148,13 +156,13 @@ .uni-content { margin-top: 15px; height: 100%; - background-color: #fff; + background-color: #fff; } } @media screen and (min-width: 690px) { .uni-content { - padding: 30px 40px 60px; + padding: 30px 40px 60px; max-height: 530px; } diff --git a/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.test.js b/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.test.js new file mode 100644 index 0000000000000000000000000000000000000000..0ae8ab41610b4fd5dc4d5e6c6b8bf44a1b783312 --- /dev/null +++ b/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.test.js @@ -0,0 +1,50 @@ +// jest官方文档: https://www.jestjs.cn/ +// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start + +describe('uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue', () => { + let page + beforeAll(async () => { + try { + page = await program.reLaunch('/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile') + await page.waitFor(500) + console.log("await program.pageStack(): ", await program.pageStack()); + } catch (e) { + console.log("e: ",e); + } + + }) + + it('绑定手机号', async () => { + + await page.setData({ + formData: { + mobile: "17769516019", + code: "123456", + captcha: "1234" + } + }) + + await page.waitFor(300) + const submitRes = await page.callMethod('submit') + console.log("submitRes: ",submitRes); + + + switch (submitRes.errCode){ + case "uni-id-mobile-verify-code-error": + expect(submitRes.errMsg).toBe("手机验证码错误或已过期"); + break; + case "uni-captcha-verify-fail": + expect(submitRes.errMsg).toBe("验证码错误"); + break; + case "uni-id-param-required": + expect(submitRes.errMsg).toBe("缺少参数: token"); + break; + default: + console.log(await program.currentPage(),"currentPage---------"); + break; + } + + }) + + +}); diff --git a/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue b/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue index 67442efd45750f5d76290c59325cd391824af925..0cd6f8824bb843db519005f6af928a658264d165 100644 --- a/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue +++ b/uni_modules/uni-id-pages/pages/userinfo/bind-mobile/bind-mobile.vue @@ -47,7 +47,7 @@ /** * 完成并提交 */ - submit() { + async submit() { if(! /^1\d{10}$/.test(this.formData.mobile)){ this.focusMobile = true return uni.showToast({ @@ -55,6 +55,7 @@ icon: 'none' }); } + console.log("this.formData.code: ",this.formData.code); if(! /^\d{6}$/.test(this.formData.code)){ this.$refs.smsForm.focusSmsCodeInput = true return uni.showToast({ @@ -63,14 +64,16 @@ }); } - console.log(this.formData); - const uniIdCo = uniCloud.importObject("uni-id-co") - uniIdCo.bindMobileBySms(this.formData).then(e => { + console.log(this.formData,"1------------"); + const uniIdCo = uniCloud.importObject("uni-id-co",{ + customUI:true + }) + return await uniIdCo.bindMobileBySms(this.formData).then(e => { console.log(e); - uni.showToast({ - title: e.errMsg, - icon: 'none' - }); + // uni.showToast({ + // title: e.errMsg, + // icon: 'none' + // }); // #ifdef APP-NVUE const eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE // #endif @@ -79,13 +82,16 @@ // #endif mutations.setUserInfo(this.formData) uni.navigateBack() + return e }).catch(e => { console.log(e); if (e.errCode == 'uni-id-captcha-required') { this.$refs.popup.open() } + return e }).finally(e => { this.formData.captcha = "" + return e }) } } diff --git a/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.test.js b/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.test.js new file mode 100644 index 0000000000000000000000000000000000000000..1df977bfbfed8b3f43304b1ae9bd494ab18a1f18 --- /dev/null +++ b/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.test.js @@ -0,0 +1,48 @@ +// jest官方文档: https://www.jestjs.cn/ +// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start + +describe('uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue', () => { + let page + beforeAll(async () => { + try { + page = await program.reLaunch('/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd') + await page.waitFor(500) + console.log("await program.pageStack(): ", await program.pageStack()); + } catch (e) { + console.log("e: ",e); + } + + }) + + it('修改密码', async () => { + await page.setData({ + formData: { + oldPassword: "dcloud2022", + newPassword: "unistarter2022", + newPassword2: "unistarter2022" + } + }) + console.log(await page.data('formData')); + await page.waitFor(300) + const submitRes = await page.callMethod('submit') + console.log("submitRes: ",submitRes); + + switch (submitRes.errCode){ + case 0: + console.log('修改成功') + break; + case "uni-id-param-required": + expect(submitRes.errMsg).toBe("缺少参数: token"); + break; + case "uni-id-password-error": + expect(submitRes.errMsg).toBe("密码错误"); + break; + default: + console.log(await program.currentPage(),"currentPage---------"); + break; + } + + }) + + +}); diff --git a/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue b/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue index 79980ee1c5157cff666f1a1e1e3b4b77b5deca4d..4537ded3a4c49db2fa5d383f2a189ff7827628f5 100644 --- a/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue +++ b/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd.vue @@ -81,16 +81,14 @@ /** * 完成并提交 */ - submit() { + async submit() { console.log("formData", this.formData); console.log('rules', this.rules); - this.$refs.form.validate() - .then(res => { - let { - oldPassword, - newPassword - } = this.formData - uniIdCo.updatePwd({ + return await this.$refs.form.validate() + .then( async res => { + console.log("res:---------- ",res); + let {oldPassword,newPassword} = this.formData + return await uniIdCo.updatePwd({ oldPassword, newPassword }).then(e => { @@ -100,17 +98,23 @@ uni.redirectTo({ url:'/uni_modules/uni-id-pages/pages/login/login-withpwd' }) + return e }).catch(e => { - uni.showModal({ - content: e.message, - showCancel: false - }); + console.log("e:------------ ",e); + // uni.showModal({ + // content: e.message, + // showCancel: false + // }); + return e }) + }).catch(errors => { + console.log("errors: ------------",errors); let key = errors[0].key key = key.replace(key[0], key[0].toUpperCase()) console.log(key, 'focus' + key); this['focus' + key] = true + return errors }) } } diff --git a/uni_modules/uni-id-pages/pages/userinfo/cropImage/bind-mobile/bind-mobile.test.js b/uni_modules/uni-id-pages/pages/userinfo/cropImage/bind-mobile/bind-mobile.test.js deleted file mode 100644 index 08c39ec02a772a19be09df0fc8d89cda561350c6..0000000000000000000000000000000000000000 --- a/uni_modules/uni-id-pages/pages/userinfo/cropImage/bind-mobile/bind-mobile.test.js +++ /dev/null @@ -1,101 +0,0 @@ -// uniapp自动化测试教程: https://uniapp-test.dcloud.net.cn/docs/testcase/start redirectTo - -describe('pages/ucenter/userinfo/bind-mobile/bind-mobile.vue', () => { - let page - beforeAll(async () => { - try { - page = await program.navigateTo('/pages/ucenter/userinfo/bind-mobile/bind-mobile') - console.log("page: ", page); - await page.waitFor(500) - - console.log("program.pageStack: ",await program.pageStack()); - } catch (e) { - console.log("e: ", e); - } - }) - - it('修改绑定手机号', async () => { - await page.waitFor(300) - console.log("formData:---------1 ", await page.data('formData')); - - const isPhone = await page.callMethod('isPhone') - console.log("isPhone: ", isPhone); - - const isCode = await page.callMethod('isCode') - console.log("isCode: ", isCode); - - - let mobile = "17769516019" - await page.setData({ - formData: { - mobile - } - }) - expect(mobile).toMatch(/^1\d{10}$/); - - console.log("formData:--------2 ", await page.data('formData')); - - - - console.log("process.env.UNI_PLATFORM: ", process.env.UNI_PLATFORM); - - if(process.env.UNI_PLATFORM == "mp-weixin"){ - const codeBtnMp = await page.$('uni-send-sms-code') - console.log("codeBtnMp: ",codeBtnMp); - const sendMsgResMp = await codeBtnMp.callMethod('sendMsg') - console.log("sendMsgResMp: ",sendMsgResMp); - await page.waitFor(300) - }else{ - const codebtn = await page.$('.short-code-btn') - console.log("codebtn: ",codebtn); - const sendMsgRes = await codebtn.callMethod('sendMsg') - console.log("sendMsgRes: ",sendMsgRes); - await page.waitFor(300) - } - - - let code = "123456" - await page.setData({formData: {code}}) - expect(code).toMatch(/^\d{6}$/); - - - const submitRes = await page.callMethod('submit') - await page.waitFor(300) - console.log("submitRes: ",submitRes); - - if(submitRes){ - switch (submitRes.code){ - case 0: - expect(submitRes.msg).toBe("手机号码绑定成功") - await page.waitFor(300) - console.log(await program.currentPage()); - expect((await program.currentPage()).path).toBe('/pages/ucenter/userinfo/userinfo') - break; - case 403: - expect(submitRes.msg).toBe("缺少token") - await page.waitFor(300) - await program.redirectTo('/pages/ucenter/login-page/pwd-login/pwd-login') - break; - case 60101: - // expect(submitRes.msg).toBe("此手机号已绑定" || "手机号 is already bound") - expect(submitRes.errCode).toBe("uni-id-account-bound") - break; - case 50202: - expect(submitRes.errCode).toBe("uni-id-invalid-verify-code") - expect(submitRes.errMsg).toBe("短信验证码错误或已失效") - break; - case "SYS_ERR": - console.log("未知错误---SYS_ERR",submitRes) - break; - default: - console.log("submitRes.errMsg",submitRes.errMsg) - - break; - } - } - // await program.switchTab('/pages/ucenter/ucenter') - - console.log(await program.currentPage(), "last-------------------"); - }) - -}); diff --git a/uni_modules/uni-id-pages/pages/userinfo/cropImage/userinfo.test.js b/uni_modules/uni-id-pages/pages/userinfo/cropImage/userinfo.test.js deleted file mode 100644 index cae83dfb7f2633c6ade3779fe3ffc9b9ed4dad26..0000000000000000000000000000000000000000 --- a/uni_modules/uni-id-pages/pages/userinfo/cropImage/userinfo.test.js +++ /dev/null @@ -1,41 +0,0 @@ -// jest官方文档: https://www.jestjs.cn/ -// uniapp自动化测试教程: https://uniapp.dcloud.io/collocation/auto/quick-start -describe('pages/ucenter/userinfo/userinfo.vue', () => { - - let page,uniToken; - beforeAll(async () => { - try{ - page = await program.reLaunch('/pages/ucenter/userinfo/userinfo') - await page.waitFor(500) - uniToken = await page.data('uniToken') - console.log("uniToken: ",uniToken); - console.log("program.pageStack: ",await program.pageStack()); - }catch(e){ - //TODO handle the exception - console.log("e: ",e); - } - }) - - - it('设置昵称', async () => { - const name = "数字天堂DCloud" + Math.round(Math.random()*10); - await page.waitFor(300) - const nicknameRes = await page.callMethod("setNickname",name) - if(nicknameRes.updated){ - expect(nicknameRes.updated).toBe(1) - }else{ - console.log("设置昵称失败"); - } - - }) - - it('绑定手机号', async () => { - await page.callMethod('bindMobileBySmsCode') - - await page.waitFor(1000) - expect((await program.currentPage()).path).toBe('pages/ucenter/userinfo/bind-mobile/bind-mobile') - console.log("currentPage---------------- ",await program.currentPage()); - // expect((await program.navigateBack()).path).toBe('pages/ucenter/userinfo/userinfo') - }) - -}) diff --git a/uni_modules/uni-id-pages/pages/userinfo/userinfo.test.js b/uni_modules/uni-id-pages/pages/userinfo/userinfo.test.js new file mode 100644 index 0000000000000000000000000000000000000000..84b4097c88699b00005fe5d2bb76b96db18ff1fa --- /dev/null +++ b/uni_modules/uni-id-pages/pages/userinfo/userinfo.test.js @@ -0,0 +1,50 @@ +// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.io/collocation/auto/hbuilderx-extension/index + +describe('uni_modules/uni-id-pages/pages/userinfo/userinfo.vue', () => { + + let page; + beforeAll(async () => { + page = await program.navigateTo('/uni_modules/uni-id-pages/pages/userinfo/userinfo') + await page.waitFor(500) + // page = await program.currentPage() + console.log("program.pageStack: ", await program.pageStack()); + }); + + it("昵称", async () => { + const nickname = "数字天堂DCloud" + Math.round(Math.random() * 10); + await page.waitFor(300) + await page.callMethod("setNickname", nickname) + }) + + it("头像", async () => { + + const imgs = [ + "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-52b18b34-3a3e-4861-89a0-c362c7634787/5105c383-8d83-4f40-938e-7c32c5983f8d.png", + "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-52b18b34-3a3e-4861-89a0-c362c7634787/61869c72-3117-4ea4-8d6d-ebb67617c7d9.jpg", + "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-52b18b34-3a3e-4861-89a0-c362c7634787/558cde0a-b514-4de7-8c7d-1d6b733f9440.png"] + + const avatar_file = { + url:imgs[Math.floor(Math.random()*imgs.length)] + } + console.log("avatar_file: ",avatar_file); + + if (process.env.UNI_PLATFORM != "mp-weixin") { + const elBox = await page.$('.box') + await elBox.callMethod('setAvatarFile',avatar_file) + }else{ + await page.waitFor(500) + await program.screenshot({ + path: "static/screenshot/userinfo.png" // 默认项目根目录 + }) + } + + // if (process.env.UNI_PLATFORM != "mp-weixin") { + // await program.screenshot({ + // path: "static/screenshot/userinfo.png" // 默认项目根目录 + // }) + // } + + }) + + +}); diff --git a/uni_modules/uni-id-pages/pages/userinfo/userinfo.vue b/uni_modules/uni-id-pages/pages/userinfo/userinfo.vue index 7852f45b7b955b69e97858edbe9c1fb389a3d951..5049b6ce30385c3b1cf16784161d1961df12ee2c 100644 --- a/uni_modules/uni-id-pages/pages/userinfo/userinfo.vue +++ b/uni_modules/uni-id-pages/pages/userinfo/userinfo.vue @@ -33,16 +33,16 @@ const db = uniCloud.database(); const usersTable = db.collection('uni-id-users') const uniIdCo = uniCloud.importObject("uni-id-co") - import { - store, - mutations - } from '@/uni_modules/uni-id-pages/common/store.js' + import { + store, + mutations + } from '@/uni_modules/uni-id-pages/common/store.js' export default { - computed: { - userInfo() { - return store.userInfo - } - }, + computed: { + userInfo() { + return store.userInfo + } + }, data() { return { univerifyStyle: { @@ -57,8 +57,8 @@ // mobile:'', // nickname:'' // }, - hasPwd:false, - showLoginManage:false//通过页面传参隐藏登录&退出登录按钮 + hasPwd: false, + showLoginManage: false //通过页面传参隐藏登录&退出登录按钮 } }, async onShow() { @@ -66,8 +66,9 @@ this.univerifyStyle.otherLoginButton.title = "其他号码绑定" }, async onLoad(e) { - if(e.showLoginManage){ - this.showLoginManage = true//通过页面传参隐藏登录&退出登录按钮 + console.log("store.userInfo:---- ",store.userInfo); + if (e.showLoginManage) { + this.showLoginManage = true //通过页面传参隐藏登录&退出登录按钮 } //判断当前用户是否有密码,否则就不显示密码修改功能 let res = await uniIdCo.getAccountInfo() @@ -82,13 +83,13 @@ } }) }, - logout(){ - mutations.logout() - }, - bindMobileSuccess(){ - mutations.updateUserInfo() - }, - changePassword(){ + logout() { + mutations.logout() + }, + bindMobileSuccess() { + mutations.updateUserInfo() + }, + changePassword() { uni.navigateTo({ url: '/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd', complete: (e) => { @@ -126,10 +127,10 @@ console.log(e.authResult); uniIdCo.bindMobileByUniverify(e.authResult).then(res => { console.log(res); - mutations.updateUserInfo() + mutations.updateUserInfo() }).catch(e => { console.log(e); - }).finally(e=>{ + }).finally(e => { console.log(e); uni.closeAuthView() }) @@ -143,64 +144,65 @@ }) }, bindMobileBySmsCode() { - uni.navigateTo({ - url: './bind-mobile/bind-mobile' - }) + uni.navigateTo({ + url: './bind-mobile/bind-mobile' + }) }, setNickname(nickname) { console.log(nickname); - if (nickname) { - mutations.updateUserInfo({nickname}) - this.$refs.dialog.close() - } else { - this.$refs.dialog.open() - } + if (nickname) { + mutations.updateUserInfo({ + nickname + }) + this.$refs.dialog.close() + } else { + this.$refs.dialog.open() + } }, - deactivate(){ + deactivate() { uni.navigateTo({ - url:"/uni_modules/uni-id-pages/pages/userinfo/deactivate/deactivate" + url: "/uni_modules/uni-id-pages/pages/userinfo/deactivate/deactivate" }) }, - async bindThirdAccount(provider) { - const uniIdCo = uniCloud.importObject("uni-id-co") - const bindField = { - weixin: 'wx_openid', - alipay: 'ali_openid', - apple: 'apple_openid', - qq: 'qq_openid' - }[provider.toLowerCase()] + async bindThirdAccount(provider) { + const uniIdCo = uniCloud.importObject("uni-id-co") + const bindField = { + weixin: 'wx_openid', + alipay: 'ali_openid', + apple: 'apple_openid', + qq: 'qq_openid' + } [provider.toLowerCase()] - if (this.userInfo[bindField]) { - await uniIdCo['unbind' + provider]() - await mutations.updateUserInfo() - } else { - uni.login({ - provider: provider.toLowerCase(), - onlyAuthorize: true, - success: async e => { - const res = await uniIdCo['bind' + provider]({ - code: e.code - }) - if (res.errCode) { - uni.showToast({ - title: res.errMsg || '绑定失败' - }) - } - await mutations.updateUserInfo() - }, - fail: async (err) => { - console.log(err); - uni.hideLoading() - } - }) - } + if (this.userInfo[bindField]) { + await uniIdCo['unbind' + provider]() + await mutations.updateUserInfo() + } else { + uni.login({ + provider: provider.toLowerCase(), + onlyAuthorize: true, + success: async e => { + const res = await uniIdCo['bind' + provider]({ + code: e.code + }) + if (res.errCode) { + uni.showToast({ + title: res.errMsg || '绑定失败' + }) + } + await mutations.updateUserInfo() + }, + fail: async (err) => { + console.log(err); + uni.hideLoading() + } + }) + } - } + } } } + diff --git a/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json b/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json index 8231c65dff5c1c4d59e2adaadfca7a49bda1802e..b581829d4377134f754266efb7c8964bd753fa9f 100644 --- a/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json +++ b/uni_modules/uni-id-pages/uniCloud/database/uni-id-users.schema.json @@ -209,7 +209,7 @@ "title": "昵称", "trim": "both", "permission": { - "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission", + "read": true, "write": "doc._id == auth.uid || 'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission" } }, @@ -379,7 +379,7 @@ "title": "用户名", "trim": "both", "permission": { - "read": "doc._id == auth.uid || 'READ_UNI_ID_USERS' in auth.permission", + "read": true, "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission" } },