From c724790ec39b52ebbf4f5439a8211dc1d829cbdb Mon Sep 17 00:00:00 2001 From: WOSHIMAHAIFENG Date: Wed, 17 Apr 2024 15:26:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0file=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get-file-system-manager.test.js | 123 +++++++++--------- .../get-file-system-manager.uvue | 11 +- 2 files changed, 66 insertions(+), 68 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 8b47be79..7870ea3f 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 @@ -937,7 +937,7 @@ describe('ExtApi-FileManagerTest', () => { }); it('appendFileTest', async () => { - if(!isAndroid()){ + if (!isAndroid()) { return } @@ -994,7 +994,7 @@ describe('ExtApi-FileManagerTest', () => { //renameFileSync copyFileSyncTest appendFileSyncTest truncateFileTest truncateFileSyncTest it('sync test', async () => { - if(!isAndroid()){ + if (!isAndroid()) { return } @@ -1149,50 +1149,10 @@ describe('ExtApi-FileManagerTest', () => { } return true } - //saveFileTest saveFileSyncTest getSavedFileListTest removeSavedFileTest - it('savefile test', - async () => { - if(!isAndroid()){ - return - } - - - let globalTempPath = await getData('globalTempPath') - let basePath = await getData('basePath') - await page.setData({ - basePath: basePath - }) - await clearDir('') - - - await page.setData({ - basePath: globalTempPath, - temFile: 'save/1.txt', - mkdirFile: 'save', - writeFile: 'save/1.txt', - accessFile: '1.txt' - }) - await createFile() - - await page.setData({ - basePath: basePath, - temFile: 'save/1.txt', - }) - let btnSaveFile = await page.$('#btn-save-file') - await btnSaveFile.tap() - await isDone() - let saveFileRet = await getData("saveFileRet") - expect(saveFileRet).not.toBe(''); - await page.setData({ - saveFileRet: '' - }) - await clearDir('') - }); - it('saveFileSyncTest', async () => { - if(!isAndroid()){ + if (!isAndroid()) { return } @@ -1200,10 +1160,12 @@ describe('ExtApi-FileManagerTest', () => { let globalTempPath = await getData('globalTempPath') let basePath = await getData('basePath') await page.setData({ + logAble: false, basePath: basePath }) await clearDir('') await page.setData({ + logAble: false, basePath: globalTempPath, temFile: 'save/2.txt', mkdirFile: 'save', @@ -1217,32 +1179,21 @@ describe('ExtApi-FileManagerTest', () => { }) btnSaveFile = await page.$('#btn-save-file-sync') await btnSaveFile.tap() - await isDone() let btnRemoveSavedFileRet = await page.$('#btn-remove-saved-file') await btnRemoveSavedFileRet.tap() let removeSavedFileRet = await getData("removeSavedFileRet") expect(removeSavedFileRet).toEqual('removeSavedFile:ok') - + await isDone() await page.setData({ removeSavedFileRet: '' }) - - - let btnSavedFileList = await page.$('#btn-getsaved-filelist') - await btnSavedFileList.tap() - await isDone() - let fileListSuccess = await getData("fileListSuccess") - expect(fileListSuccess.length > 0).toEqual(true) - - - await clearDir('') }); it('getSavedFileListTest', async () => { - if(!isAndroid()){ + if (!isAndroid()) { return } @@ -1250,10 +1201,12 @@ describe('ExtApi-FileManagerTest', () => { let globalTempPath = await getData('globalTempPath') let basePath = await getData('basePath') await page.setData({ + logAble: false, basePath: basePath }) await clearDir('') await page.setData({ + logAble: false, basePath: globalTempPath, temFile: 'save/2.txt', mkdirFile: 'save', @@ -1267,7 +1220,6 @@ describe('ExtApi-FileManagerTest', () => { }) btnSaveFile = await page.$('#btn-save-file-sync') await btnSaveFile.tap() - await isDone() let btnSavedFileList = await page.$('#btn-getsaved-filelist') await btnSavedFileList.tap() @@ -1275,14 +1227,12 @@ describe('ExtApi-FileManagerTest', () => { let fileListSuccess = await getData("fileListSuccess") expect(fileListSuccess.length > 0).toEqual(true) - - await clearDir('') }); it('removeSavedFileTest', async () => { - if(!isAndroid()){ + if (!isAndroid()) { return } @@ -1290,10 +1240,12 @@ describe('ExtApi-FileManagerTest', () => { let globalTempPath = await getData('globalTempPath') let basePath = await getData('basePath') await page.setData({ + logAble: false, basePath: basePath }) await clearDir('') await page.setData({ + logAble: false, basePath: globalTempPath, temFile: 'save/2.txt', mkdirFile: 'save', @@ -1318,13 +1270,14 @@ describe('ExtApi-FileManagerTest', () => { //openFiletest openFileSynctest closeTest closeTestSync writeTest writeSyncTest it('openFiletest', async () => { - if(!isAndroid()){ + if (!isAndroid()) { return } await clearDir('') await page.setData({ + logAble: false, mkdirFile: 'fd', writeFile: 'fd/1.txt', readFile: 'fd/1.txt' @@ -1349,13 +1302,14 @@ describe('ExtApi-FileManagerTest', () => { }); // closeTest closeTestSync it('closeTest', async () => { - if(!isAndroid()){ + if (!isAndroid()) { return } await clearDir('') await page.setData({ + logAble: false, mkdirFile: 'fd', writeFile: 'fd/1.txt', readFile: 'fd/1.txt' @@ -1380,12 +1334,13 @@ describe('ExtApi-FileManagerTest', () => { }); //writeTest writeSyncTest it('writeTest', async () => { - if(!isAndroid()){ + if (!isAndroid()) { return } await clearDir('') await page.setData({ + logAble: false, mkdirFile: 'fd', writeFile: 'fd/1.txt', readFile: 'fd/1.txt', @@ -1443,4 +1398,46 @@ describe('ExtApi-FileManagerTest', () => { expect(fstat).not.toEqual('ftruncate:ok') }); + + //saveFileTest saveFileSyncTest getSavedFileListTest removeSavedFileTest + it('savefile test', + async () => { + if (!isAndroid()) { + return + } + + + let globalTempPath = await getData('globalTempPath') + let basePath = await getData('basePath') + await page.setData({ + logAble: false, + basePath: basePath + }) + await clearDir('') + + + await page.setData({ + basePath: globalTempPath, + temFile: 'save/1.txt', + mkdirFile: 'save', + writeFile: 'save/1.txt', + accessFile: '1.txt' + }) + await createFile() + + await page.setData({ + basePath: basePath, + temFile: 'save/1.txt', + }) + let btnSaveFile = await page.$('#btn-save-file') + await btnSaveFile.tap() + await isDone() + let saveFileRet = await getData("saveFileRet") + expect(saveFileRet).not.toBe(''); + await page.setData({ + saveFileRet: '' + }) + // await clearDir('') + }); + }); diff --git a/pages/API/get-file-system-manager/get-file-system-manager.uvue b/pages/API/get-file-system-manager/get-file-system-manager.uvue index 79f3eb2e..4d58b873 100644 --- a/pages/API/get-file-system-manager/get-file-system-manager.uvue +++ b/pages/API/get-file-system-manager/get-file-system-manager.uvue @@ -718,7 +718,6 @@ }, saveFileTest: function (_ : any) { const fileManager = uni.getFileSystemManager() - console.log('=====' + uni.env.USER_DATA_PATH) fileManager.saveFile({ tempFilePath: `${this.globalTempPath}${this.temFile}`, // filePath:`${this.basePath}local/`, @@ -728,13 +727,15 @@ } console.log('success', res) this.saveFileRet = res.savedFilePath + this.done = true }, fail: (res : UniError) => { if (this.logAble) { this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n' } - console.log('fail', res) + console.log('saveFileTest fail', res) this.lastFailError = res + this.done = true }, complete: (_) => { this.done = true @@ -752,7 +753,7 @@ //todo 后面打开 // this.saveFileRet=res } catch (e) { - console.log(e) + console.log('saveFileSyncTest:'+e) this.done = true } }, @@ -788,14 +789,14 @@ if (this.logAble) { this.log += 'getSavedFileListTest success:' + JSON.stringify(res) + '\n\n' } - console.log("success", res) + console.log("getSavedFileListTest success", res) this.fileListSuccess = res.fileList }, fail: (res : UniError) => { if (this.logAble) { this.log += 'getSavedFileListTest fail:' + JSON.stringify(res) + '\n\n' } - console.log('fail', res) + console.log('getSavedFileListTest fail', res) this.lastFailError = res }, complete: (res : any) => { -- GitLab