diff --git a/pages/API/get-file-system-manager/get-file-system-manager.test.js b/pages/API/get-file-system-manager/get-file-system-manager.test.js index 956e34b6001b40067954d56e48ab1fe1ab083cad..c2518f93ae80607ccd324b67a66a373192414762 100644 --- a/pages/API/get-file-system-manager/get-file-system-manager.test.js +++ b/pages/API/get-file-system-manager/get-file-system-manager.test.js @@ -700,98 +700,175 @@ describe('ExtApi-FileManagerTest', () => { }); -// it('stat and asset test', async () => { -// // 测试 USER_DATA_PATH -// let globalInnerRootPath = await getData('globalInnerRootPath') - -// await page.setData({ -// recursiveVal: true, -// copyToBasePath:globalInnerRootPath, -// basePath: globalInnerRootPath, -// rmDirFile:'a', -// mkdirFile:'a', -// unlinkFile:'a/1.txt', -// }) - -// // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 -// const btnUnLinkFileButton = await page.$('.btn-unlink-file') -// 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', -// }) -// await btnUnLinkFileButton.tap() -// await isDone() - -// // // 清除文件夹 -// const btnRmDirButton = await page.$('.btn-remove-dir') -// await btnRmDirButton.tap() -// await isDone() -// // // 重新创建测试目录 -// const btnMkdDirButton = await page.$('.btn-mkdir') -// await btnMkdDirButton.tap() -// await isDone() - -// const btnReadDirButton = await page.$('.btn-read-dir') -// await btnReadDirButton.tap() -// await isDone() - - -// // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 -// let fileListComplete = await getData('fileListComplete') -// expect(JSON.stringify(fileListComplete)).toEqual('[]') -// let fileListSuccess = await getData('fileListSuccess') -// expect(JSON.stringify(fileListSuccess)).toEqual('[]') - -// // 写入一个文件 -// await page.setData({ -// writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦", -// writeFileEncoding:"utf-8", -// writeFile:'a/1.txt', -// recursiveVal:false, -// statFile:'a/1.txt', -// }) - - - -// let lastFailError = await getData('lastFailError') -// console.log(lastFailError) - -// // const btnWriteFileButton = await page.$('.btn-write-file') -// // await btnWriteFileButton.tap() -// // await isDone() - -// // const btnStatFileButton = await page.$('.btn-stat-file') -// // await btnStatFileButton.tap() -// // await isDone() - -// // // 读取单个文件信息 -// // let statsRet = await getData('statsRet') -// // console.log(statsRet) -// // expect(statsRet.path).toEqual('') - -// // await page.setData({ -// // recursiveVal:true, -// // statFile:'a/1.txt', -// // }) - -// // await btnStatFileButton.tap() -// // await isDone() - -// // // 读取单个文件信息 -// // statsRet = await getData('statsRet') -// // console.log(statsRet) -// // expect(statsRet.path).toEqual('') - - - -// }); + it('stat and asset test', async () => { + // 测试 USER_DATA_PATH //globalTempPath + let globalRootPath = await getData('globalRootPath') + + await page.setData({ + recursiveVal: true, + copyToBasePath:globalRootPath, + basePath: globalRootPath, + rmDirFile:'a', + mkdirFile:'a', + unlinkFile:'a/1.txt', + }) + + // 先清除文件,需要清除全部可能存在的历史测试文件,避免运行失败 + const btnUnLinkFileButton = await page.$('.btn-unlink-file') + 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', + }) + await btnUnLinkFileButton.tap() + await isDone() + + // // 清除文件夹 + const btnRmDirButton = await page.$('.btn-remove-dir') + await btnRmDirButton.tap() + await isDone() + // // 重新创建测试目录 + const btnMkdDirButton = await page.$('.btn-mkdir') + await btnMkdDirButton.tap() + await isDone() + + const btnReadDirButton = await page.$('.btn-read-dir') + await btnReadDirButton.tap() + await isDone() + + + // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 + let fileListComplete = await getData('fileListComplete') + expect(JSON.stringify(fileListComplete)).toEqual('[]') + let fileListSuccess = await getData('fileListSuccess') + expect(JSON.stringify(fileListSuccess)).toEqual('[]') + + // 写入一个文件 + await page.setData({ + writeFileContent: "锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦", + writeFileEncoding:"utf-8", + writeFile:'a/1.txt', + recursiveVal:false, + statFile:'a/1.txt', + }) + + let lastFailError = await getData('lastFailError') + console.log(lastFailError) + + const btnWriteFileButton = await page.$('.btn-write-file') + await btnWriteFileButton.tap() + await isDone() + + const btnStatFileButton = await page.$('.btn-stat-file') + await btnStatFileButton.tap() + await isDone() + + // 读取单个文件信息 + let statsRet = await getData('statsRet') + expect(statsRet.length).toEqual(1) + expect(statsRet[0].path).toEqual('/storage/emulated/0/Android/data/io.dcloud.uniappx/a/1.txt') + expect(statsRet[0].stats.size).toEqual(69) + + /** + * 创建子目录和子目录文件,测试recursive参数 + */ + await page.setData({ + writeFileContent: "1234567890", + writeFileEncoding:"ascii", + writeFile:'a/2.txt', + basePath: globalRootPath, + recursiveVal:false, + statFile:'a', + mkdirFile:'a/m', + }) + + + 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('[]') + + + + + + }); });