提交 4ee1b1db 编写于 作者: 杜庆泉's avatar 杜庆泉

手动合并 get-file-system-manager dev分支内容到本地

上级 9d6dffe7
...@@ -30,29 +30,23 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -30,29 +30,23 @@ describe('ExtApi-FileManagerTest', () => {
let globalUserDataPath = await getData('globalUserDataPath') let globalUserDataPath = await getData('globalUserDataPath')
await page.setData({ await page.setData({
logAble:false,
recursiveVal: true, recursiveVal: true,
copyToBasePath:globalUserDataPath, copyToBasePath:globalUserDataPath,
basePath: globalUserDataPath, basePath: globalUserDataPath,
rmDirFile:'a', rmDirFile:'a',
unlinkFile:'a/1.txt' readDir:'a',
writeFile:'a/1.txt',
readFile:'a/1.txt',
unlinkFile:'a/1.txt',
writeFileContent:'锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦'
}) })
// 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败
const btnUnLinkFileButton = await page.$('.btn-unlink-file') const btnUnLinkFileButton = await page.$('.btn-clear-file')
await btnUnLinkFileButton.tap() await btnUnLinkFileButton.tap()
await isDone() await isDone()
await page.setData({
unlinkFile:'a/2.txt'
})
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/3.txt'
})
await btnUnLinkFileButton.tap()
await isDone()
// 清除文件夹 // 清除文件夹
const btnRmDirButton = await page.$('.btn-remove-dir') const btnRmDirButton = await page.$('.btn-remove-dir')
...@@ -200,17 +194,18 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -200,17 +194,18 @@ describe('ExtApi-FileManagerTest', () => {
fileListSuccess = await getData('fileListSuccess') fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\",\"3.txt\"]") expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\",\"3.txt\"]")
}); });
it('TEMP_PATH test', async () => { it('TEMP_PATH test', async () => {
// 测试 TEMP_PATH // 测试 TEMP_PATH
let globalTempPath = await getData('globalTempPath') let globalTempPath = await getData('globalTempPath')
await page.setData({ await page.setData({
logAble:false,
recursiveVal: true, recursiveVal: true,
basePath: globalTempPath, basePath: globalTempPath,
copyToBasePath:globalTempPath, copyToBasePath:globalTempPath,
rmDirFile:'a', rmDirFile:'a',
mkdirFile: 'a',
unlinkFile:'a/我们经历了一场兵慌马乱的战争.1@2#3$4%5^6&7*8(9)0+-qwertyuiopasdfghjklzxcvbnm;,/中文路径/张三/name/中文文件.mock' unlinkFile:'a/我们经历了一场兵慌马乱的战争.1@2#3$4%5^6&7*8(9)0+-qwertyuiopasdfghjklzxcvbnm;,/中文路径/张三/name/中文文件.mock'
}) })
...@@ -220,12 +215,6 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -220,12 +215,6 @@ describe('ExtApi-FileManagerTest', () => {
await btnUnLinkFileButton.tap() await btnUnLinkFileButton.tap()
await isDone() await isDone()
await page.setData({
unlinkFile:'a/提前创建的目录/4.txt'
})
await btnUnLinkFileButton.tap()
await isDone()
// 清除文件夹 // 清除文件夹
const btnRmDirButton = await page.$('.btn-remove-dir') const btnRmDirButton = await page.$('.btn-remove-dir')
...@@ -244,9 +233,9 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -244,9 +233,9 @@ describe('ExtApi-FileManagerTest', () => {
// 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录
let fileListComplete = await getData('fileListComplete') let fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual("[\"b\"]") expect(JSON.stringify(fileListComplete)).toEqual("[]")
let fileListSuccess = await getData('fileListSuccess') let fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\"]") expect(JSON.stringify(fileListSuccess)).toEqual("[]")
// 测试 创建多层级文件目录 // 测试 创建多层级文件目录
await page.setData({ await page.setData({
...@@ -286,10 +275,8 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -286,10 +275,8 @@ describe('ExtApi-FileManagerTest', () => {
* 从资源文件中读取图片为base64,测试写入较大文件场景 * 从资源文件中读取图片为base64,测试写入较大文件场景
* 'static/list-mock/safe.png' 注意,依赖这个资源文件,不能删除 * 'static/list-mock/safe.png' 注意,依赖这个资源文件,不能删除
*/ */
let globalAppResourcePath = await getData('globalAppResourcePath')
await page.setData({ await page.setData({
basePath: "",
basePath: globalAppResourcePath,
readFile:'static/list-mock/safe.png', readFile:'static/list-mock/safe.png',
readFileEncoding:'base64' readFileEncoding:'base64'
}) })
...@@ -434,7 +421,8 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -434,7 +421,8 @@ describe('ExtApi-FileManagerTest', () => {
expect(JSON.stringify(fileListSuccess)).toEqual("[\"4.txt\"]") expect(JSON.stringify(fileListSuccess)).toEqual("[\"4.txt\"]")
await page.setData({ await page.setData({
unlinkFile:'a/提前创建的目录/4.txt' unlinkFile:'a/提前创建的目录/4.txt',
rmDirFile:'a/提前创建的目录'
}) })
await btnUnLinkFileButton.tap() await btnUnLinkFileButton.tap()
await isDone() await isDone()
...@@ -447,12 +435,10 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -447,12 +435,10 @@ describe('ExtApi-FileManagerTest', () => {
fileListSuccess = await getData('fileListSuccess') fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[]") expect(JSON.stringify(fileListSuccess)).toEqual("[]")
}); });
it('CROSS DIR test', async () => { it('CROSS DIR test', async () => {
/** /**
* 跨越用户目录和代码资源目录 * 跨越用户目录和代码资源目录
...@@ -460,6 +446,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -460,6 +446,7 @@ describe('ExtApi-FileManagerTest', () => {
let globalRootPath = await getData('globalRootPath') let globalRootPath = await getData('globalRootPath')
await page.setData({ await page.setData({
recursiveVal: true, recursiveVal: true,
logAble:false,
basePath: globalRootPath, basePath: globalRootPath,
readDir:'a', readDir:'a',
rmDirFile:'a', rmDirFile:'a',
...@@ -470,8 +457,8 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -470,8 +457,8 @@ describe('ExtApi-FileManagerTest', () => {
// 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败
const btnUnLinkFileButton = await page.$('.btn-unlink-file') const btnClearFileButton = await page.$('.btn-clear-file')
await btnUnLinkFileButton.tap() await btnClearFileButton.tap()
await isDone() await isDone()
...@@ -505,9 +492,8 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -505,9 +492,8 @@ describe('ExtApi-FileManagerTest', () => {
// 准备从资源目录拷贝png // 准备从资源目录拷贝png
let globalAppResourcePath = await getData('globalAppResourcePath')
await page.setData({ await page.setData({
basePath: globalAppResourcePath, basePath: "",
unlinkFile:'static/list-mock/safe.png', unlinkFile:'static/list-mock/safe.png',
accessFile:'static/list-mock/safe.png', accessFile:'static/list-mock/safe.png',
}) })
...@@ -519,6 +505,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -519,6 +505,7 @@ describe('ExtApi-FileManagerTest', () => {
expect(accessFileRet).toEqual('access:ok') expect(accessFileRet).toEqual('access:ok')
// 尝试删除资源,期望失败 // 尝试删除资源,期望失败
const btnUnLinkFileButton = await page.$('.btn-unlink-file')
await btnUnLinkFileButton.tap() await btnUnLinkFileButton.tap()
await isDone() await isDone()
...@@ -542,6 +529,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -542,6 +529,7 @@ describe('ExtApi-FileManagerTest', () => {
basePath:globalRootPath, basePath:globalRootPath,
unlinkFile:'a/从代码目录拷贝的资源.png', unlinkFile:'a/从代码目录拷贝的资源.png',
accessFile:'a/从代码目录拷贝的资源.png', accessFile:'a/从代码目录拷贝的资源.png',
rmDirFile:'a',
}) })
await btnAccessFileButton.tap() await btnAccessFileButton.tap()
await isDone() await isDone()
...@@ -549,6 +537,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -549,6 +537,7 @@ describe('ExtApi-FileManagerTest', () => {
accessFileRet = await getData("accessFileRet") accessFileRet = await getData("accessFileRet")
expect(accessFileRet).toEqual('access:ok') expect(accessFileRet).toEqual('access:ok')
await btnUnLinkFileButton.tap() await btnUnLinkFileButton.tap()
await isDone() await isDone()
...@@ -558,6 +547,31 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -558,6 +547,31 @@ describe('ExtApi-FileManagerTest', () => {
accessFileRet = await getData("accessFileRet") accessFileRet = await getData("accessFileRet")
expect(accessFileRet).toEqual('') expect(accessFileRet).toEqual('')
// 从页面的按钮触发一次文件复制
const btnCopyStaticFileButton = await page.$('.btn-copyStatic-file')
await btnCopyStaticFileButton.tap()
await isDone()
await btnReadDirButton.tap()
await isDone()
fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual("[\"mock.json\"]")
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[\"mock.json\"]")
// 从页面的按钮触发一次文件清空
await btnClearFileButton.tap()
await isDone()
await btnReadDirButton.tap()
await isDone()
fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual("[]")
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual("[]")
}); });
...@@ -568,6 +582,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -568,6 +582,7 @@ describe('ExtApi-FileManagerTest', () => {
let globalTempPath = await getData('globalTempPath') let globalTempPath = await getData('globalTempPath')
await page.setData({ await page.setData({
recursiveVal: true, recursiveVal: true,
logAble:false,
basePath: globalTempPath, basePath: globalTempPath,
readDir:'d', readDir:'d',
rmDirFile:'d', rmDirFile:'d',
...@@ -700,98 +715,172 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -700,98 +715,172 @@ describe('ExtApi-FileManagerTest', () => {
}); });
// it('stat and asset test', async () => { it('stat and asset test', async () => {
// // 测试 USER_DATA_PATH // 测试 USER_DATA_PATH //globalTempPath
// let globalInnerRootPath = await getData('globalInnerRootPath') let globalRootPath = await getData('globalRootPath')
// await page.setData({ await page.setData({
// recursiveVal: true, recursiveVal: true,
// copyToBasePath:globalInnerRootPath, copyToBasePath:globalRootPath,
// basePath: globalInnerRootPath, basePath: globalRootPath,
// rmDirFile:'a', rmDirFile:'a',
// mkdirFile:'a', mkdirFile:'a',
// unlinkFile:'a/1.txt', unlinkFile:'a/1.txt',
// }) })
// // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败
// const btnUnLinkFileButton = await page.$('.btn-unlink-file') const btnUnLinkFileButton = await page.$('.btn-unlink-file')
// await btnUnLinkFileButton.tap() await btnUnLinkFileButton.tap()
// await isDone() await isDone()
// await page.setData({ await page.setData({
// unlinkFile:'a/2.txt', unlinkFile:'a/2.txt',
// }) })
// await btnUnLinkFileButton.tap() await btnUnLinkFileButton.tap()
// await isDone() await isDone()
// await page.setData({ await page.setData({
// unlinkFile:'a/m/3.txt', unlinkFile:'a/m/3.txt',
// }) })
// await btnUnLinkFileButton.tap() await btnUnLinkFileButton.tap()
// await isDone() await isDone()
// // // 清除文件夹 // // 清除文件夹
// const btnRmDirButton = await page.$('.btn-remove-dir') const btnRmDirButton = await page.$('.btn-remove-dir')
// await btnRmDirButton.tap() await btnRmDirButton.tap()
// await isDone() await isDone()
// // // 重新创建测试目录 // // 重新创建测试目录
// const btnMkdDirButton = await page.$('.btn-mkdir') const btnMkdDirButton = await page.$('.btn-mkdir')
// await btnMkdDirButton.tap() await btnMkdDirButton.tap()
// await isDone() await isDone()
// const btnReadDirButton = await page.$('.btn-read-dir') const btnReadDirButton = await page.$('.btn-read-dir')
// await btnReadDirButton.tap() await btnReadDirButton.tap()
// await isDone() await isDone()
// // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录
// let fileListComplete = await getData('fileListComplete') let fileListComplete = await getData('fileListComplete')
// expect(JSON.stringify(fileListComplete)).toEqual('[]') expect(JSON.stringify(fileListComplete)).toEqual('[]')
// let fileListSuccess = await getData('fileListSuccess') let fileListSuccess = await getData('fileListSuccess')
// expect(JSON.stringify(fileListSuccess)).toEqual('[]') expect(JSON.stringify(fileListSuccess)).toEqual('[]')
// // 写入一个文件 // 写入一个文件
// await page.setData({ await page.setData({
// writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦", writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦",
// writeFileEncoding:"utf-8", writeFileEncoding:"utf-8",
// writeFile:'a/1.txt', writeFile:'a/1.txt',
// recursiveVal:false, recursiveVal:false,
// statFile:'a/1.txt', statFile:'a/1.txt',
// }) })
let lastFailError = await getData('lastFailError')
console.log(lastFailError)
// let lastFailError = await getData('lastFailError')
// console.log(lastFailError) const btnWriteFileButton = await page.$('.btn-write-file')
await btnWriteFileButton.tap()
// // const btnWriteFileButton = await page.$('.btn-write-file') await isDone()
// // await btnWriteFileButton.tap()
// // await isDone() const btnStatFileButton = await page.$('.btn-stat-file')
await btnStatFileButton.tap()
// // const btnStatFileButton = await page.$('.btn-stat-file') await isDone()
// // await btnStatFileButton.tap()
// // await isDone() // 读取单个文件信息
let statsRet = await getData('statsRet')
// // // 读取单个文件信息 expect(statsRet.length).toEqual(1)
// // let statsRet = await getData('statsRet') expect(statsRet[0].path).toEqual('/storage/emulated/0/Android/data/io.dcloud.uniappx/a/1.txt')
// // console.log(statsRet) expect(statsRet[0].stats.size).toEqual(69)
// // expect(statsRet.path).toEqual('')
/**
// // await page.setData({ * 创建子目录和子目录文件,测试recursive参数
// // recursiveVal:true, */
// // statFile:'a/1.txt', await page.setData({
// // }) writeFileContent: "1234567890",
writeFileEncoding:"ascii",
// // await btnStatFileButton.tap() writeFile:'a/2.txt',
// // await isDone() basePath: globalRootPath,
recursiveVal:false,
// // // 读取单个文件信息 statFile:'a',
// // statsRet = await getData('statsRet') mkdirFile:'a/m',
// // console.log(statsRet) })
// // expect(statsRet.path).toEqual('')
await btnWriteFileButton.tap()
await isDone()
// });
// 创建子目录
await btnMkdDirButton.tap()
await isDone()
// 复制一份文件到 /a/m/3.txt
await page.setData({
// asset 只能正式版测试,这里只能模拟返回路径
basePath:'',
copyFromFile:'file:///android_asset/uni-uts/uni-prompt/toast_error.png',
copyToFile:'a/m/3.txt',
})
const btnCopyFileButton = await page.$('.btn-copy-file')
await btnCopyFileButton.tap()
await isDone()
await page.setData({
basePath: globalRootPath,
recursiveVal:true,
statFile:'a',
})
await btnStatFileButton.tap()
await isDone()
// 读取全部文件信息
statsRet = await getData('statsRet')
console.log(statsRet)
expect(statsRet.length).toEqual(5)
expect(statsRet[0].path).toEqual('/storage/emulated/0/Android/data/io.dcloud.uniappx/a')
expect(statsRet[0].stats.size).toEqual(0)
expect(statsRet[2].path).toEqual('/storage/emulated/0/Android/data/io.dcloud.uniappx/a/2.txt')
expect(statsRet[2].stats.size).toEqual(10)
expect(statsRet[4].path).toEqual('/storage/emulated/0/Android/data/io.dcloud.uniappx/a/m/3.txt')
expect(statsRet[4].stats.size).toEqual(5842)
// 清理文件,避免影响其他测试用例
await page.setData({
unlinkFile:'a/1.txt',
})
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/2.txt',
})
await btnUnLinkFileButton.tap()
await isDone()
await page.setData({
unlinkFile:'a/m/3.txt',
rmDirFile:'a',
readDir:'a',
recursiveVal:true,
})
await btnUnLinkFileButton.tap()
await isDone()
await btnRmDirButton.tap()
await isDone()
await btnReadDirButton.tap()
await isDone()
// 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录
fileListComplete = await getData('fileListComplete')
expect(JSON.stringify(fileListComplete)).toEqual('[]')
fileListSuccess = await getData('fileListSuccess')
expect(JSON.stringify(fileListSuccess)).toEqual('[]')
});
}); });
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册