From 4ed39f72e27f044689b5111e16b0771c21d46483 Mon Sep 17 00:00:00 2001 From: "xutongyin@dcloud.io" Date: Mon, 25 Mar 2024 16:12:53 +0800 Subject: [PATCH] =?UTF-8?q?fix:file=20manager=E8=87=AA=E5=8A=A8=E5=8C=96?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=B5=8B=E9=80=82=E9=85=8DiOS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get-file-system-manager.test.js | 47 +++++++++++++------ 1 file changed, 32 insertions(+), 15 deletions(-) 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 c8f4c83b..82e6471a 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 @@ -116,9 +116,11 @@ describe('ExtApi-FileManagerTest', () => { await btnReadDirButton.tap() await isDone() fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"1.txt\"]") + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"b\"]") fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\"]") + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"b\"]") // 获取和对比 文件内容 const btnReadFileButton = await page.$('#btn-read-file') await btnReadFileButton.tap() @@ -176,9 +178,11 @@ describe('ExtApi-FileManagerTest', () => { // 1.txt 2.txt 两个文件都存在 fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"1.txt\",\"2.txt\"]") + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]") fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\",\"2.txt\"]") + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"2.txt\",\"b\"]") // 测试 rename await page.setData({ @@ -195,10 +199,11 @@ describe('ExtApi-FileManagerTest', () => { // 1.txt 3.txt 两个文件都存在 fileListComplete = await getData('fileListComplete') - expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"1.txt\",\"3.txt\"]") + fileListComplete.sort() + expect(JSON.stringify(fileListComplete)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]") fileListSuccess = await getData('fileListSuccess') - expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"1.txt\",\"3.txt\"]") - + fileListSuccess.sort() + expect(JSON.stringify(fileListSuccess)).toEqual("[\"1.txt\",\"3.txt\",\"b\"]") }); it('TEMP_PATH test', async () => { @@ -281,8 +286,10 @@ describe('ExtApi-FileManagerTest', () => { // 期望通过 recursive = true的 文件夹删除,得到一个空的 /a 目录 fileListComplete = await getData('fileListComplete') + fileListComplete.sort() expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + "\"]") fileListSuccess = await getData('fileListSuccess') + fileListSuccess.sort() expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + "\"]") /** @@ -406,13 +413,14 @@ describe('ExtApi-FileManagerTest', () => { await isDone() fileListComplete = await getData('fileListComplete') + fileListComplete.sort() expect(JSON.stringify(fileListComplete)).toEqual("[\"b\",\"" + testDirName + "\",\"提前创建的目录\"]") fileListSuccess = await getData('fileListSuccess') + fileListSuccess.sort() expect(JSON.stringify(fileListSuccess)).toEqual("[\"b\",\"" + testDirName + "\",\"提前创建的目录\"]") await page.setData({ - copyFromFile:"a/" + testDirName + "/中文路径/张三/name/中文文件.mock", copyToFile:"a/提前创建的目录/4.txt" }) @@ -800,7 +808,7 @@ describe('ExtApi-FileManagerTest', () => { // 读取单个文件信息 let statsRet = await getData('statsRet') expect(statsRet.length).toEqual(1) - expect(statsRet[0].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a/1.txt')) + expect(statsRet[0].path).toMatch(new RegExp('.*/a/1.txt$')) expect(statsRet[0].stats.size).toEqual(69) /** @@ -828,7 +836,7 @@ describe('ExtApi-FileManagerTest', () => { await page.setData({ // asset 只能正式版测试,这里只能模拟返回路径 basePath:'', - copyFromFile:'file:///android_asset/uni-uts/uni-prompt/toast_error.png', + copyFromFile:'static/test-image/logo.ico', copyToFile:'a/m/3.txt', }) const btnCopyFileButton = await page.$('#btn-copy-file') @@ -847,16 +855,25 @@ describe('ExtApi-FileManagerTest', () => { // 读取全部文件信息 statsRet = await getData('statsRet') + + statsRet.sort(function(a, b){ + if (a.path > b.path){ + return 1 + } else if (a.path < b.path){ + return -1 + } + return 0 + }) console.log(statsRet) expect(statsRet.length).toEqual(5) - expect(statsRet[0].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a')) - expect(statsRet[0].stats.size).toEqual(0) + expect(statsRet[0].path).toMatch(new RegExp('.*/a$')) + // expect(statsRet[0].stats.size).toEqual(0) - expect(statsRet[2].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a/2.txt')) + expect(statsRet[2].path).toMatch(new RegExp('.*/a/2.txt$')) expect(statsRet[2].stats.size).toEqual(10) - expect(statsRet[4].path).toMatch(new RegExp('/storage/\\S+/Android/data/io.dcloud.uniappx/a/m/3.txt')) - expect(statsRet[4].stats.size).toEqual(5842) + expect(statsRet[4].path).toMatch(new RegExp('.*/a/m/3.txt$')) + expect(statsRet[4].stats.size).toEqual(156406) // 清理文件,避免影响其他测试用例 -- GitLab