提交 ac4c2aa3 编写于 作者: A Anne_LXM

add ext-storage-qiniu.test.js

上级 1e25fab8
describe('pages/storage/ext-storage-qiniu.vue', () => {
let page
beforeAll(async () => {
// 重新reLaunch至首页,并获取首页page对象(其中 program 是uni-automator自动注入的全局对象)
page = await program.navigateTo('/pages/storage/ext-storage-qiniu')
await page.waitFor('view')
await page.setData({'isTest':true})
})
it('qiniu-storage-上传文件', async () => {
expect.assertions(2);
const res = await page.callMethod('uploadFile', {
filePath: '../../static/logo.png',
cloudPath: Date.now() + 'test-qiniu.png',
isPrivate: false
})
console.log('res: ---1', res);
expectText(res.fileID,'qiniu://')
expectText(res.fileURL,'https://')
})
it('qiniu-私有文件-上传', async () => {
expect.assertions(2);
const res = await page.callMethod('uploadFile', {
filePath: '../../static/play.png',
// cloudPath: Date.now() + 'test-qiniu.png',
isPrivate: true
})
console.log('res: ----2', res);
expectText(res.fileID,'qiniu://')
expectText(res.fileURL,'https://')
})
it('获取私有文件临时下载链接', async () => {
expect.assertions(3);
expectText(await page.data('privateFileID'),'qiniu://jest')
const res = await page.callMethod('getTempFileURL')
console.log('res: ----3', res);
expectText(res,'&token')
expectText(res,'https://')
})
})
function expectText(value,expectValue){
expect(value).toEqual(expect.stringContaining(expectValue));
}
\ No newline at end of file
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
export default { export default {
data() { data() {
return { return {
privateFileID: "" privateFileID: "",
isTest:false
} }
}, },
mounted() {}, mounted() {},
...@@ -76,6 +77,7 @@ ...@@ -76,6 +77,7 @@
}) })
}, },
async uploadFile(options) { async uploadFile(options) {
console.log('options: ',options);
uni.showLoading({ uni.showLoading({
title: '文件上传中...' title: '文件上传中...'
}) })
...@@ -83,9 +85,11 @@ ...@@ -83,9 +85,11 @@
customUI: true customUI: true
}); });
const uploadFileOptionsRes = await uniCloudStorageExtCo.getUploadFileOptions({ const uploadFileOptionsRes = await uniCloudStorageExtCo.getUploadFileOptions({
cloudPath: `test/${Date.now()}.jpg`, // 支持自定义目录 cloudPath: `jest/${Date.now()}.jpg`, // 支持自定义目录
}); });
console.log('uploadFileOptionsRes: ', uploadFileOptionsRes) console.log('uploadFileOptionsRes: ', uploadFileOptionsRes)
let testRes = new Promise((resolve,reject)=>{
const uploadTask = uni.uploadFile({ const uploadTask = uni.uploadFile({
...uploadFileOptionsRes.uploadFileOptions, // 上传文件所需参数 ...uploadFileOptionsRes.uploadFileOptions, // 上传文件所需参数
filePath: options.filePath, // 本地文件路径 filePath: options.filePath, // 本地文件路径
...@@ -111,6 +115,7 @@ ...@@ -111,6 +115,7 @@
content: '图片上传成功,fileID为:' + res.fileID, content: '图片上传成功,fileID为:' + res.fileID,
showCancel: false showCancel: false
}) })
resolve(res)
}, },
fail: (err) => { fail: (err) => {
// 上传失败后的逻辑 // 上传失败后的逻辑
...@@ -121,6 +126,7 @@ ...@@ -121,6 +126,7 @@
showCancel: false showCancel: false
}) })
} }
reject(err)
}, },
complete: () => { complete: () => {
uni.hideLoading() uni.hideLoading()
...@@ -130,6 +136,9 @@ ...@@ -130,6 +136,9 @@
uploadTask.onProgressUpdate((res) => { uploadTask.onProgressUpdate((res) => {
console.log("监听上传进度", res); console.log("监听上传进度", res);
}); });
})
console.log("testRes",testRes)
return testRes
}, },
async getTempFileURL() { async getTempFileURL() {
const uniCloudStorageExtCo = uniCloud.importObject("ext-storage-co"); const uniCloudStorageExtCo = uniCloud.importObject("ext-storage-co");
...@@ -141,6 +150,9 @@ ...@@ -141,6 +150,9 @@
content: '图片临时下载链接为:' + tempFileURL, content: '图片临时下载链接为:' + tempFileURL,
showCancel: false showCancel: false
}) })
if(this.isTest){
return tempFileURL
}
} }
} }
} }
......
// 扩展存储自定义域名 // 扩展存储自定义域名
const domain = "qiniu01.dcloud.net.cn"; const domain = "jest-ext-storage-aliyun.dcloud.net.cn";
module.exports = { module.exports = {
_before() {}, _before() {},
getUploadFileOptions(data = {}) { getUploadFileOptions(data = {}) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册