提交 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":""}}}
\ 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": ""
}
}
}
......@@ -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/'],
testSequencer: path.join(__dirname, "testSequencer.js")
}
......
import App from './App'
import i18n from './lang/i18n'
uni.showModal = ()=>{};
// uni.showModal = ()=>{};
// #ifndef VUE3
import Vue from 'vue'
......
......@@ -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"
}
}
......@@ -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",
......
......@@ -19,7 +19,7 @@
<uni-list-item thumbSize="lg" :thumb="data.image">
<!-- 通过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>
</template>
......
......@@ -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");
// })
});
......@@ -39,7 +39,8 @@
supportMode:[],
pushIsOn:"wait",
currentLanguage:"",
userInfo:{}
userInfo:{},
uniToken:''
}
},
computed: {
......
......@@ -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);
......
......@@ -2,7 +2,8 @@
<view class="center">
<uni-sign-in ref="signIn"></uni-sign-in>
<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>
<view class="logo-title">
<text class="uer-name" v-if="hasLogin">{{userInfo.nickname||userInfo.username||userInfo.mobile}}</text>
......@@ -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 {
......
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 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
......@@ -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
})
......
// 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 @@
/**
* 密码登录
*/
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
})
},
/* 前往注册 */
......
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 @@
<!-- 顶部文字 -->
<text class="title title-box">用户名密码注册</text>
</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-easyinput :inputBorder="false" :focus="focusUsername" @blur="focusUsername = false"
class="input-box" placeholder="请输入用户名" v-model="formData.username" trim="both" />
......@@ -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;
}
......
// 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 @@
/**
* 完成并提交
*/
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
})
}
}
......
// 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 @@
/**
* 完成并提交
*/
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
})
}
}
......
// 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 @@
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()
}
})
}
}
}
}
}
</script>
<style lang="scss" scoped>
@import "@/uni_modules/uni-id-pages/common/login-page.scss";
.uni-content {
......@@ -213,6 +215,7 @@
box-sizing: border-box;
flex-direction: column;
}
@media screen and (min-width: 690px) {
.uni-content {
padding: 0;
......@@ -224,6 +227,7 @@
box-shadow: none;
}
}
/* #endif */
.avatar {
align-items: center;
......@@ -247,7 +251,7 @@
width: 80%;
}
.mt10{
.mt10 {
margin-top: 10px;
}
</style>
</style>
......@@ -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"
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册