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

jest update v2-h5

上级 675f1da3
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":""}}} module.exports = {
\ No newline at end of file "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": ""
}
}
}
...@@ -23,7 +23,7 @@ module.exports = { ...@@ -23,7 +23,7 @@ module.exports = {
} }
} }
}, */ }, */
testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)"], testMatch: ["<rootDir>/pages/**/*test.[jt]s?(x)","<rootDir>/uni_modules/uni-id-pages/**/*test.[jt]s?(x)"],
testPathIgnorePatterns: ['/node_modules/'], testPathIgnorePatterns: ['/node_modules/'],
testSequencer: path.join(__dirname, "testSequencer.js") testSequencer: path.join(__dirname, "testSequencer.js")
} }
......
import App from './App' import App from './App'
import i18n from './lang/i18n' import i18n from './lang/i18n'
uni.showModal = ()=>{}; // uni.showModal = ()=>{};
// #ifndef VUE3 // #ifndef VUE3
import Vue from 'vue' import Vue from 'vue'
......
...@@ -4,12 +4,12 @@ ...@@ -4,12 +4,12 @@
"version": "2.0.6", "version": "2.0.6",
"description": "云端一体应用快速开发基本项目模版", "description": "云端一体应用快速开发基本项目模版",
"keywords": [ "keywords": [
"login", "login",
"登录", "登录",
"搜索", "搜索",
"uni-id实例", "uni-id实例",
"留言板" "留言板"
], ],
"repository": "https://gitcode.net/dcloud/uni-starter", "repository": "https://gitcode.net/dcloud/uni-starter",
"engines": { "engines": {
"HBuilderX": "^3.2.6" "HBuilderX": "^3.2.6"
...@@ -82,6 +82,8 @@ ...@@ -82,6 +82,8 @@
} }
}, },
"dependencies": { "dependencies": {
"@jest/test-sequencer": "^29.0.0",
"jest-environment-node": "^27.5.1",
"qrcodejs2": "^0.0.2" "qrcodejs2": "^0.0.2"
} }
} }
...@@ -211,15 +211,15 @@ ...@@ -211,15 +211,15 @@
}, },
"condition": { "condition": {
"list": [{ "list": [{
"path": "pages/list/detail"
}, {
"path": "pages/list/list" "path": "pages/list/list"
}, {
"path": "pages/list/detail"
}, },
{ {
"path": "pages/ucenter/settings/settings" "path": "pages/ucenter/settings/settings"
} }
], ],
"current": 1 "current": 0
}, },
"tabBar": { "tabBar": {
"color": "#7A7E83", "color": "#7A7E83",
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<uni-list-item thumbSize="lg" :thumb="data.image"> <uni-list-item thumbSize="lg" :thumb="data.image">
<!-- 通过body插槽定义作者信息内容 --> <!-- 通过body插槽定义作者信息内容 -->
<template v-slot:body> <template v-slot:body>
<view class="header-content"> <view class="header-content">
<view class="uni-title">{{data.user_id && data.user_id[0].username}}</view> <view class="uni-title">{{data.user_id && data.user_id[0].username}}</view>
</view> </view>
</template> </template>
......
...@@ -22,18 +22,24 @@ describe('pages/ucenter/settings/settings', () => { ...@@ -22,18 +22,24 @@ describe('pages/ucenter/settings/settings', () => {
if (pushRes == "wait") { if (pushRes == "wait") {
await page.callMethod('pushServer.off') 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 page.waitFor(300)
await program.navigateBack()
}) })
it('退出登录', async () => { // it('退出登录', async () => {
if(uniToken){ // if(uniToken){
await page.callMethod('clickLogout') // await page.callMethod('clickLogout')
} // }
// console.log(await program.currentPage(),"333333"); // console.log(await program.currentPage(),"333333");
}) // })
}); });
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
supportMode:[], supportMode:[],
pushIsOn:"wait", pushIsOn:"wait",
currentLanguage:"", currentLanguage:"",
userInfo:{} userInfo:{},
uniToken:''
} }
}, },
computed: { computed: {
......
...@@ -20,7 +20,7 @@ describe('pages/ucenter/ucenter.vue', () => { ...@@ -20,7 +20,7 @@ describe('pages/ucenter/ucenter.vue', () => {
it('宫格', async () => { it('宫格', async () => {
const getGrid = await page.data('gridList') const getGrid = await page.data('gridList')
console.log("getGrid: ",getGrid); console.log("getGrid: ",getGrid);
// expect(getGrid.length).toBe(4) expect(getGrid.length).toBe(4)
}) })
it('列表', async () => { it('列表', async () => {
...@@ -74,7 +74,7 @@ describe('pages/ucenter/ucenter.vue', () => { ...@@ -74,7 +74,7 @@ describe('pages/ucenter/ucenter.vue', () => {
}else{ }else{
console.log("getScoreRes: 未登录"); console.log("getScoreRes: 未登录");
try{ 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) await page.waitFor(500)
}catch(e){ }catch(e){
console.log("e: ",e); console.log("e: ",e);
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<view class="center"> <view class="center">
<uni-sign-in ref="signIn"></uni-sign-in> <uni-sign-in ref="signIn"></uni-sign-in>
<view class="userInfo" @click.capture="toUserInfo"> <view class="userInfo" @click.capture="toUserInfo">
<cloud-image width="150rpx" height="150rpx" v-if="hasLogin&&userInfo.avatar_file&&userInfo.avatar_file.url" :src="userInfo.avatar_file.url"></cloud-image> <cloud-image width="150rpx" height="150rpx" v-if="hasLogin&&userInfo.avatar_file&&userInfo.avatar_file.url"
:src="userInfo.avatar_file.url"></cloud-image>
<image v-else class="logo-img" src="@/static/uni-center/defaultAvatarUrl.png"></image> <image v-else class="logo-img" src="@/static/uni-center/defaultAvatarUrl.png"></image>
<view class="logo-title"> <view class="logo-title">
<text class="uer-name" v-if="hasLogin">{{userInfo.nickname||userInfo.username||userInfo.mobile}}</text> <text class="uer-name" v-if="hasLogin">{{userInfo.nickname||userInfo.username||userInfo.mobile}}</text>
...@@ -44,9 +45,11 @@ ...@@ -44,9 +45,11 @@
} from '@/uni_modules/uni-id-pages/common/store.js' } from '@/uni_modules/uni-id-pages/common/store.js'
export default { export default {
// #ifdef APP // #ifdef APP
onBackPress({from}) { onBackPress({
if(from=='backbutton'){ from
this.$nextTick(function(){ }) {
if (from == 'backbutton') {
this.$nextTick(function() {
uniShare.hide() uniShare.hide()
}) })
return uniShare.isShow; return uniShare.isShow;
...@@ -55,6 +58,7 @@ ...@@ -55,6 +58,7 @@
// #endif // #endif
data() { data() {
return { return {
uniToken: '',
gridList: [{ gridList: [{
"text": this.$t('mine.showText'), "text": this.$t('mine.showText'),
"icon": "chat" "icon": "chat"
...@@ -94,7 +98,7 @@ ...@@ -94,7 +98,7 @@
}, },
//#endif //#endif
{ {
"title":this.$t('mine.readArticles'), "title": this.$t('mine.readArticles'),
"to": '/pages/ucenter/read-news-log/read-news-log', "to": '/pages/ucenter/read-news-log/read-news-log',
"icon": "flag" "icon": "flag"
}, },
...@@ -142,7 +146,7 @@ ...@@ -142,7 +146,7 @@
onLoad() { onLoad() {
//#ifdef APP-PLUS //#ifdef APP-PLUS
this.ucenterList[this.ucenterList.length - 2].unshift({ 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, rightText: this.appVersion.version + '-' + this.appVersion.versionCode,
event: 'checkVersion', event: 'checkVersion',
icon: 'loop', icon: 'loop',
...@@ -150,13 +154,16 @@ ...@@ -150,13 +154,16 @@
}) })
//#endif //#endif
}, },
onShow() { onReady() {
this.uniToken = uni.getStorageSync('uni_id_token')
console.log("uniToken: ", this.uniToken);
}, },
onShow() {},
computed: { computed: {
userInfo() { userInfo() {
return store.userInfo return store.userInfo
}, },
hasLogin(){ hasLogin() {
return store.hasLogin return store.hasLogin
}, },
// #ifdef APP-PLUS // #ifdef APP-PLUS
...@@ -177,7 +184,7 @@ ...@@ -177,7 +184,7 @@
signIn() { //普通签到 signIn() { //普通签到
this.$refs.signIn.open() this.$refs.signIn.open()
}, },
signInByAd(){ //看激励视频广告签到 signInByAd() { //看激励视频广告签到
this.$refs.signIn.showRewardedVideoAd() this.$refs.signIn.showRewardedVideoAd()
}, },
/** /**
...@@ -208,7 +215,7 @@ ...@@ -208,7 +215,7 @@
tapGrid(index) { tapGrid(index) {
uni.showToast({ uni.showToast({
// title: '你点击了,第' + (index + 1) + '个', // title: '你点击了,第' + (index + 1) + '个',
title: this.$t('mine.clicked') + " " + (index + 1) , title: this.$t('mine.clicked') + " " + (index + 1),
icon: 'none' icon: 'none'
}); });
}, },
...@@ -220,8 +227,11 @@ ...@@ -220,8 +227,11 @@
if (uni.getSystemInfoSync().platform == "ios") { if (uni.getSystemInfoSync().platform == "ios") {
// 这里填写appstore应用id // 这里填写appstore应用id
let appstoreid = this.appConfig.marketId.ios; // 'id1417078253'; let appstoreid = this.appConfig.marketId.ios; // 'id1417078253';
console.log({appstoreid}); console.log({
plus.runtime.openURL("itms-apps://" + 'itunes.apple.com/cn/app/wechat/' + appstoreid + '?mt=8',err=>{ 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)); console.log('plus.runtime.openURL err:' + JSON.stringify(err));
}); });
} }
...@@ -256,25 +266,29 @@ ...@@ -256,25 +266,29 @@
console.log(res); console.log(res);
const data = res.result.data[0]; const data = res.result.data[0];
let msg = ''; 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({ uni.showToast({
title: msg, title: msg,
icon: 'none' icon: 'none'
}); });
}).finally(()=>{ }).finally(() => {
uni.hideLoading() uni.hideLoading()
}) })
}, },
async share() { 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 let myInviteCode = result.data[0].my_invite_code
if(!myInviteCode){ if (!myInviteCode) {
return uni.showToast({ return uni.showToast({
title: '请检查uni-config-center中uni-id配置,是否已启用 autoSetInviteCode', title: '请检查uni-config-center中uni-id配置,是否已启用 autoSetInviteCode',
icon: 'none' icon: 'none'
}); });
} }
console.log({myInviteCode}); console.log({
myInviteCode
});
let { let {
appName, appName,
logo, logo,
...@@ -354,6 +368,7 @@ ...@@ -354,6 +368,7 @@
page { page {
background-color: #f8f8f8; background-color: #f8f8f8;
} }
/* #endif*/ /* #endif*/
.center { .center {
......
static/screenshot/about.png

77.1 KB | W: | H:

static/screenshot/about.png

62.3 KB | W: | H:

static/screenshot/about.png
static/screenshot/about.png
static/screenshot/about.png
static/screenshot/about.png
  • 2-up
  • Swipe
  • Onion skin
const Sequencer = require("@jest/test-sequencer").default; 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 { class CustomSequencer extends Sequencer {
sort(tests) { sort(tests) {
// 测试例排序 // 测试例排序
...@@ -13,4 +13,6 @@ class CustomSequencer extends Sequencer { ...@@ -13,4 +13,6 @@ class CustomSequencer extends Sequencer {
return [...new Set([...sortTests, ...copyTests])]; return [...new Set([...sortTests, ...copyTests])];
} }
} }
module.exports = CustomSequencer; module.exports = CustomSequencer;
\ No newline at end of file
// ,"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
...@@ -5,7 +5,17 @@ const uniCaptcha = require('uni-captcha') ...@@ -5,7 +5,17 @@ const uniCaptcha = require('uni-captcha')
const db = uniCloud.database(); const db = uniCloud.database();
//获取数据表opendb-verify-codes对象 //获取数据表opendb-verify-codes对象
const verifyCodes = db.collection('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 = { module.exports = {
async getImageCaptcha({ async getImageCaptcha({
scene scene
}) { }) {
...@@ -25,6 +35,7 @@ module.exports = { ...@@ -25,6 +35,7 @@ module.exports = {
//执行并返回结果 //执行并返回结果
//导入配置,配置优先级说明:此处配置 > uni-config-center //导入配置,配置优先级说明:此处配置 > uni-config-center
return await uniCaptcha[action]({ return await uniCaptcha[action]({
text: Config.text,
scene, //来源客户端传递,表示:使用场景值,用于防止不同功能的验证码混用 scene, //来源客户端传递,表示:使用场景值,用于防止不同功能的验证码混用
uniPlatform: platform uniPlatform: platform
}) })
......
// 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;
}
})
});
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
/** /**
* 密码登录 * 密码登录
*/ */
pwdLogin() { async pwdLogin() {
if (!this.password.length) { if (!this.password.length) {
this.focusPassword = true this.focusPassword = true
return uni.showToast({ return uni.showToast({
...@@ -94,6 +94,7 @@ ...@@ -94,6 +94,7 @@
icon: 'none' icon: 'none'
}); });
} }
console.log("this.needCaptcha: ",this.needCaptcha);
if (this.needCaptcha && this.captcha.length != 4) { if (this.needCaptcha && this.captcha.length != 4) {
this.$refs.captcha.getImageCaptcha() this.$refs.captcha.getImageCaptcha()
return uni.showToast({ return uni.showToast({
...@@ -119,8 +120,9 @@ ...@@ -119,8 +120,9 @@
data.username = this.username data.username = this.username
} }
uniIdCo.login(data).then(e => { return await uniIdCo.login(data).then(e => {
this.loginSuccess(e) this.loginSuccess(e)
return e
}).catch(e => { }).catch(e => {
if (e.errCode == 'uni-id-captcha-required') { if (e.errCode == 'uni-id-captcha-required') {
this.needCaptcha = true this.needCaptcha = true
...@@ -128,6 +130,7 @@ ...@@ -128,6 +130,7 @@
//登录失败,自动重新获取验证码 //登录失败,自动重新获取验证码
this.$refs.captcha.getImageCaptcha() this.$refs.captcha.getImageCaptcha()
} }
return e
}) })
}, },
/* 前往注册 */ /* 前往注册 */
......
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;
}
})
})
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<!-- 顶部文字 --> <!-- 顶部文字 -->
<text class="title title-box">用户名密码注册</text> <text class="title title-box">用户名密码注册</text>
</match-media> </match-media>
<uni-forms ref="form" :value="formData" :rules="rules" validate-trigger="submit" err-show-type="toast"> <uni-forms ref="form" :value="formData" :rules="rules" validate-trigger="submit" err-show-type="undertext">
<uni-forms-item name="username" required> <uni-forms-item name="username" required>
<uni-easyinput :inputBorder="false" :focus="focusUsername" @blur="focusUsername = false" <uni-easyinput :inputBorder="false" :focus="focusUsername" @blur="focusUsername = false"
class="input-box" placeholder="请输入用户名" v-model="formData.username" trim="both" /> class="input-box" placeholder="请输入用户名" v-model="formData.username" trim="both" />
...@@ -53,7 +53,9 @@ ...@@ -53,7 +53,9 @@
mutations mutations
} from '@/uni_modules/uni-id-pages/common/store.js' } 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 { export default {
mixins: [mixin], mixins: [mixin],
data() { data() {
...@@ -90,8 +92,8 @@ ...@@ -90,8 +92,8 @@
/** /**
* 触发表单提交 * 触发表单提交
*/ */
submit() { submit() {
this.$refs.form.validate().then((res) => { return this.$refs.form.validate().then(async(res) => {
if (this.formData.captcha.length != 4) { if (this.formData.captcha.length != 4) {
this.$refs.captcha.focusCaptchaInput = true this.$refs.captcha.focusCaptchaInput = true
return uni.showToast({ return uni.showToast({
...@@ -99,29 +101,35 @@ ...@@ -99,29 +101,35 @@
icon: 'none' icon: 'none'
}); });
} }
if (this.needAgreements && !this.agree) { // close
return this.$refs.agreements.popup(() => { // if (this.needAgreements && !this.agree) {
this.submitForm(res) // return this.$refs.agreements.popup(() => {
}) // this.submitForm(res)
} // })
this.submitForm(res) // }
// this.submitForm(res)
return await this.submitForm(res)
}).catch((errors) => { }).catch((errors) => {
let key = errors[0].key let key = errors[0].key
key = key.replace(key[0], key[0].toUpperCase()) key = key.replace(key[0], key[0].toUpperCase())
console.log(key); console.log(key);
this['focus' + key] = true this['focus' + key] = true
return errors
}) })
}, },
submitForm(params) { async submitForm(params) {
uniIdCo.registerUser(this.formData).then(e => { console.log("params: ", params);
console.log(e); return await uniIdCo.registerUser(this.formData).then(e => {
this.loginSuccess(e) this.loginSuccess(e)
return e
}) })
.catch(e => { .catch(e => {
console.log(e);
console.log(e.message); console.log(e.message);
return e
//更好的体验:登录错误,直接刷新验证码 //更好的体验:登录错误,直接刷新验证码
this.$refs.captcha.getImageCaptcha() //close
// this.$refs.captcha.getImageCaptcha()
}) })
}, },
navigateBack() { navigateBack() {
...@@ -148,13 +156,13 @@ ...@@ -148,13 +156,13 @@
.uni-content { .uni-content {
margin-top: 15px; margin-top: 15px;
height: 100%; height: 100%;
background-color: #fff; background-color: #fff;
} }
} }
@media screen and (min-width: 690px) { @media screen and (min-width: 690px) {
.uni-content { .uni-content {
padding: 30px 40px 60px; padding: 30px 40px 60px;
max-height: 530px; max-height: 530px;
} }
......
// 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;
}
})
});
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
/** /**
* 完成并提交 * 完成并提交
*/ */
submit() { async submit() {
if(! /^1\d{10}$/.test(this.formData.mobile)){ if(! /^1\d{10}$/.test(this.formData.mobile)){
this.focusMobile = true this.focusMobile = true
return uni.showToast({ return uni.showToast({
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
icon: 'none' icon: 'none'
}); });
} }
console.log("this.formData.code: ",this.formData.code);
if(! /^\d{6}$/.test(this.formData.code)){ if(! /^\d{6}$/.test(this.formData.code)){
this.$refs.smsForm.focusSmsCodeInput = true this.$refs.smsForm.focusSmsCodeInput = true
return uni.showToast({ return uni.showToast({
...@@ -63,14 +64,16 @@ ...@@ -63,14 +64,16 @@
}); });
} }
console.log(this.formData); console.log(this.formData,"1------------");
const uniIdCo = uniCloud.importObject("uni-id-co") const uniIdCo = uniCloud.importObject("uni-id-co",{
uniIdCo.bindMobileBySms(this.formData).then(e => { customUI:true
})
return await uniIdCo.bindMobileBySms(this.formData).then(e => {
console.log(e); console.log(e);
uni.showToast({ // uni.showToast({
title: e.errMsg, // title: e.errMsg,
icon: 'none' // icon: 'none'
}); // });
// #ifdef APP-NVUE // #ifdef APP-NVUE
const eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE const eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
// #endif // #endif
...@@ -79,13 +82,16 @@ ...@@ -79,13 +82,16 @@
// #endif // #endif
mutations.setUserInfo(this.formData) mutations.setUserInfo(this.formData)
uni.navigateBack() uni.navigateBack()
return e
}).catch(e => { }).catch(e => {
console.log(e); console.log(e);
if (e.errCode == 'uni-id-captcha-required') { if (e.errCode == 'uni-id-captcha-required') {
this.$refs.popup.open() this.$refs.popup.open()
} }
return e
}).finally(e => { }).finally(e => {
this.formData.captcha = "" this.formData.captcha = ""
return e
}) })
} }
} }
......
// 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;
}
})
});
...@@ -81,16 +81,14 @@ ...@@ -81,16 +81,14 @@
/** /**
* 完成并提交 * 完成并提交
*/ */
submit() { async submit() {
console.log("formData", this.formData); console.log("formData", this.formData);
console.log('rules', this.rules); console.log('rules', this.rules);
this.$refs.form.validate() return await this.$refs.form.validate()
.then(res => { .then( async res => {
let { console.log("res:---------- ",res);
oldPassword, let {oldPassword,newPassword} = this.formData
newPassword return await uniIdCo.updatePwd({
} = this.formData
uniIdCo.updatePwd({
oldPassword, oldPassword,
newPassword newPassword
}).then(e => { }).then(e => {
...@@ -100,17 +98,23 @@ ...@@ -100,17 +98,23 @@
uni.redirectTo({ uni.redirectTo({
url:'/uni_modules/uni-id-pages/pages/login/login-withpwd' url:'/uni_modules/uni-id-pages/pages/login/login-withpwd'
}) })
return e
}).catch(e => { }).catch(e => {
uni.showModal({ console.log("e:------------ ",e);
content: e.message, // uni.showModal({
showCancel: false // content: e.message,
}); // showCancel: false
// });
return e
}) })
}).catch(errors => { }).catch(errors => {
console.log("errors: ------------",errors);
let key = errors[0].key let key = errors[0].key
key = key.replace(key[0], key[0].toUpperCase()) key = key.replace(key[0], key[0].toUpperCase())
console.log(key, 'focus' + key); console.log(key, 'focus' + key);
this['focus' + key] = true this['focus' + key] = true
return errors
}) })
} }
} }
......
// 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-------------------");
})
});
// 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')
})
})
// 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" // 默认项目根目录
// })
// }
})
});
...@@ -33,16 +33,16 @@ ...@@ -33,16 +33,16 @@
const db = uniCloud.database(); const db = uniCloud.database();
const usersTable = db.collection('uni-id-users') const usersTable = db.collection('uni-id-users')
const uniIdCo = uniCloud.importObject("uni-id-co") const uniIdCo = uniCloud.importObject("uni-id-co")
import { import {
store, store,
mutations mutations
} from '@/uni_modules/uni-id-pages/common/store.js' } from '@/uni_modules/uni-id-pages/common/store.js'
export default { export default {
computed: { computed: {
userInfo() { userInfo() {
return store.userInfo return store.userInfo
} }
}, },
data() { data() {
return { return {
univerifyStyle: { univerifyStyle: {
...@@ -57,8 +57,8 @@ ...@@ -57,8 +57,8 @@
// mobile:'', // mobile:'',
// nickname:'' // nickname:''
// }, // },
hasPwd:false, hasPwd: false,
showLoginManage:false//通过页面传参隐藏登录&退出登录按钮 showLoginManage: false //通过页面传参隐藏登录&退出登录按钮
} }
}, },
async onShow() { async onShow() {
...@@ -66,8 +66,9 @@ ...@@ -66,8 +66,9 @@
this.univerifyStyle.otherLoginButton.title = "其他号码绑定" this.univerifyStyle.otherLoginButton.title = "其他号码绑定"
}, },
async onLoad(e) { async onLoad(e) {
if(e.showLoginManage){ console.log("store.userInfo:---- ",store.userInfo);
this.showLoginManage = true//通过页面传参隐藏登录&退出登录按钮 if (e.showLoginManage) {
this.showLoginManage = true //通过页面传参隐藏登录&退出登录按钮
} }
//判断当前用户是否有密码,否则就不显示密码修改功能 //判断当前用户是否有密码,否则就不显示密码修改功能
let res = await uniIdCo.getAccountInfo() let res = await uniIdCo.getAccountInfo()
...@@ -82,13 +83,13 @@ ...@@ -82,13 +83,13 @@
} }
}) })
}, },
logout(){ logout() {
mutations.logout() mutations.logout()
}, },
bindMobileSuccess(){ bindMobileSuccess() {
mutations.updateUserInfo() mutations.updateUserInfo()
}, },
changePassword(){ changePassword() {
uni.navigateTo({ uni.navigateTo({
url: '/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd', url: '/uni_modules/uni-id-pages/pages/userinfo/change_pwd/change_pwd',
complete: (e) => { complete: (e) => {
...@@ -126,10 +127,10 @@ ...@@ -126,10 +127,10 @@
console.log(e.authResult); console.log(e.authResult);
uniIdCo.bindMobileByUniverify(e.authResult).then(res => { uniIdCo.bindMobileByUniverify(e.authResult).then(res => {
console.log(res); console.log(res);
mutations.updateUserInfo() mutations.updateUserInfo()
}).catch(e => { }).catch(e => {
console.log(e); console.log(e);
}).finally(e=>{ }).finally(e => {
console.log(e); console.log(e);
uni.closeAuthView() uni.closeAuthView()
}) })
...@@ -143,64 +144,65 @@ ...@@ -143,64 +144,65 @@
}) })
}, },
bindMobileBySmsCode() { bindMobileBySmsCode() {
uni.navigateTo({ uni.navigateTo({
url: './bind-mobile/bind-mobile' url: './bind-mobile/bind-mobile'
}) })
}, },
setNickname(nickname) { setNickname(nickname) {
console.log(nickname); console.log(nickname);
if (nickname) { if (nickname) {
mutations.updateUserInfo({nickname}) mutations.updateUserInfo({
this.$refs.dialog.close() nickname
} else { })
this.$refs.dialog.open() this.$refs.dialog.close()
} } else {
this.$refs.dialog.open()
}
}, },
deactivate(){ deactivate() {
uni.navigateTo({ 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) { async bindThirdAccount(provider) {
const uniIdCo = uniCloud.importObject("uni-id-co") const uniIdCo = uniCloud.importObject("uni-id-co")
const bindField = { const bindField = {
weixin: 'wx_openid', weixin: 'wx_openid',
alipay: 'ali_openid', alipay: 'ali_openid',
apple: 'apple_openid', apple: 'apple_openid',
qq: 'qq_openid' qq: 'qq_openid'
}[provider.toLowerCase()] } [provider.toLowerCase()]
if (this.userInfo[bindField]) { if (this.userInfo[bindField]) {
await uniIdCo['unbind' + provider]() await uniIdCo['unbind' + provider]()
await mutations.updateUserInfo() await mutations.updateUserInfo()
} else { } else {
uni.login({ uni.login({
provider: provider.toLowerCase(), provider: provider.toLowerCase(),
onlyAuthorize: true, onlyAuthorize: true,
success: async e => { success: async e => {
const res = await uniIdCo['bind' + provider]({ const res = await uniIdCo['bind' + provider]({
code: e.code code: e.code
}) })
if (res.errCode) { if (res.errCode) {
uni.showToast({ uni.showToast({
title: res.errMsg || '绑定失败' title: res.errMsg || '绑定失败'
}) })
} }
await mutations.updateUserInfo() await mutations.updateUserInfo()
}, },
fail: async (err) => { fail: async (err) => {
console.log(err); console.log(err);
uni.hideLoading() uni.hideLoading()
} }
}) })
} }
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "@/uni_modules/uni-id-pages/common/login-page.scss"; @import "@/uni_modules/uni-id-pages/common/login-page.scss";
.uni-content { .uni-content {
...@@ -213,6 +215,7 @@ ...@@ -213,6 +215,7 @@
box-sizing: border-box; box-sizing: border-box;
flex-direction: column; flex-direction: column;
} }
@media screen and (min-width: 690px) { @media screen and (min-width: 690px) {
.uni-content { .uni-content {
padding: 0; padding: 0;
...@@ -224,6 +227,7 @@ ...@@ -224,6 +227,7 @@
box-shadow: none; box-shadow: none;
} }
} }
/* #endif */ /* #endif */
.avatar { .avatar {
align-items: center; align-items: center;
...@@ -247,7 +251,7 @@ ...@@ -247,7 +251,7 @@
width: 80%; width: 80%;
} }
.mt10{ .mt10 {
margin-top: 10px; margin-top: 10px;
} }
</style> </style>
...@@ -209,7 +209,7 @@ ...@@ -209,7 +209,7 @@
"title": "昵称", "title": "昵称",
"trim": "both", "trim": "both",
"permission": { "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" "write": "doc._id == auth.uid || 'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
} }
}, },
...@@ -379,7 +379,7 @@ ...@@ -379,7 +379,7 @@
"title": "用户名", "title": "用户名",
"trim": "both", "trim": "both",
"permission": { "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" "write": "'CREATE_UNI_ID_USERS' in auth.permission || 'UPDATE_UNI_ID_USERS' in auth.permission"
} }
}, },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册