提交 c724790e 编写于 作者: W WOSHIMAHAIFENG

添加file测试用例

上级 716fcaa8
...@@ -937,7 +937,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -937,7 +937,7 @@ describe('ExtApi-FileManagerTest', () => {
}); });
it('appendFileTest', async () => { it('appendFileTest', async () => {
if(!isAndroid()){ if (!isAndroid()) {
return return
} }
...@@ -994,7 +994,7 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -994,7 +994,7 @@ describe('ExtApi-FileManagerTest', () => {
//renameFileSync copyFileSyncTest appendFileSyncTest truncateFileTest truncateFileSyncTest //renameFileSync copyFileSyncTest appendFileSyncTest truncateFileTest truncateFileSyncTest
it('sync test', it('sync test',
async () => { async () => {
if(!isAndroid()){ if (!isAndroid()) {
return return
} }
...@@ -1149,50 +1149,10 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1149,50 +1149,10 @@ describe('ExtApi-FileManagerTest', () => {
} }
return true 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', it('saveFileSyncTest',
async () => { async () => {
if(!isAndroid()){ if (!isAndroid()) {
return return
} }
...@@ -1200,10 +1160,12 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1200,10 +1160,12 @@ describe('ExtApi-FileManagerTest', () => {
let globalTempPath = await getData('globalTempPath') let globalTempPath = await getData('globalTempPath')
let basePath = await getData('basePath') let basePath = await getData('basePath')
await page.setData({ await page.setData({
logAble: false,
basePath: basePath basePath: basePath
}) })
await clearDir('') await clearDir('')
await page.setData({ await page.setData({
logAble: false,
basePath: globalTempPath, basePath: globalTempPath,
temFile: 'save/2.txt', temFile: 'save/2.txt',
mkdirFile: 'save', mkdirFile: 'save',
...@@ -1217,32 +1179,21 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1217,32 +1179,21 @@ describe('ExtApi-FileManagerTest', () => {
}) })
btnSaveFile = await page.$('#btn-save-file-sync') btnSaveFile = await page.$('#btn-save-file-sync')
await btnSaveFile.tap() await btnSaveFile.tap()
await isDone()
let btnRemoveSavedFileRet = await page.$('#btn-remove-saved-file') let btnRemoveSavedFileRet = await page.$('#btn-remove-saved-file')
await btnRemoveSavedFileRet.tap() await btnRemoveSavedFileRet.tap()
let removeSavedFileRet = await getData("removeSavedFileRet") let removeSavedFileRet = await getData("removeSavedFileRet")
expect(removeSavedFileRet).toEqual('removeSavedFile:ok') expect(removeSavedFileRet).toEqual('removeSavedFile:ok')
await isDone()
await page.setData({ await page.setData({
removeSavedFileRet: '' 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('') await clearDir('')
}); });
it('getSavedFileListTest', it('getSavedFileListTest',
async () => { async () => {
if(!isAndroid()){ if (!isAndroid()) {
return return
} }
...@@ -1250,10 +1201,12 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1250,10 +1201,12 @@ describe('ExtApi-FileManagerTest', () => {
let globalTempPath = await getData('globalTempPath') let globalTempPath = await getData('globalTempPath')
let basePath = await getData('basePath') let basePath = await getData('basePath')
await page.setData({ await page.setData({
logAble: false,
basePath: basePath basePath: basePath
}) })
await clearDir('') await clearDir('')
await page.setData({ await page.setData({
logAble: false,
basePath: globalTempPath, basePath: globalTempPath,
temFile: 'save/2.txt', temFile: 'save/2.txt',
mkdirFile: 'save', mkdirFile: 'save',
...@@ -1267,7 +1220,6 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1267,7 +1220,6 @@ describe('ExtApi-FileManagerTest', () => {
}) })
btnSaveFile = await page.$('#btn-save-file-sync') btnSaveFile = await page.$('#btn-save-file-sync')
await btnSaveFile.tap() await btnSaveFile.tap()
await isDone()
let btnSavedFileList = await page.$('#btn-getsaved-filelist') let btnSavedFileList = await page.$('#btn-getsaved-filelist')
await btnSavedFileList.tap() await btnSavedFileList.tap()
...@@ -1275,14 +1227,12 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1275,14 +1227,12 @@ describe('ExtApi-FileManagerTest', () => {
let fileListSuccess = await getData("fileListSuccess") let fileListSuccess = await getData("fileListSuccess")
expect(fileListSuccess.length > 0).toEqual(true) expect(fileListSuccess.length > 0).toEqual(true)
await clearDir('') await clearDir('')
}); });
it('removeSavedFileTest', it('removeSavedFileTest',
async () => { async () => {
if(!isAndroid()){ if (!isAndroid()) {
return return
} }
...@@ -1290,10 +1240,12 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1290,10 +1240,12 @@ describe('ExtApi-FileManagerTest', () => {
let globalTempPath = await getData('globalTempPath') let globalTempPath = await getData('globalTempPath')
let basePath = await getData('basePath') let basePath = await getData('basePath')
await page.setData({ await page.setData({
logAble: false,
basePath: basePath basePath: basePath
}) })
await clearDir('') await clearDir('')
await page.setData({ await page.setData({
logAble: false,
basePath: globalTempPath, basePath: globalTempPath,
temFile: 'save/2.txt', temFile: 'save/2.txt',
mkdirFile: 'save', mkdirFile: 'save',
...@@ -1318,13 +1270,14 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1318,13 +1270,14 @@ describe('ExtApi-FileManagerTest', () => {
//openFiletest openFileSynctest closeTest closeTestSync writeTest writeSyncTest //openFiletest openFileSynctest closeTest closeTestSync writeTest writeSyncTest
it('openFiletest', async () => { it('openFiletest', async () => {
if(!isAndroid()){ if (!isAndroid()) {
return return
} }
await clearDir('') await clearDir('')
await page.setData({ await page.setData({
logAble: false,
mkdirFile: 'fd', mkdirFile: 'fd',
writeFile: 'fd/1.txt', writeFile: 'fd/1.txt',
readFile: 'fd/1.txt' readFile: 'fd/1.txt'
...@@ -1349,13 +1302,14 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1349,13 +1302,14 @@ describe('ExtApi-FileManagerTest', () => {
}); });
// closeTest closeTestSync // closeTest closeTestSync
it('closeTest', async () => { it('closeTest', async () => {
if(!isAndroid()){ if (!isAndroid()) {
return return
} }
await clearDir('') await clearDir('')
await page.setData({ await page.setData({
logAble: false,
mkdirFile: 'fd', mkdirFile: 'fd',
writeFile: 'fd/1.txt', writeFile: 'fd/1.txt',
readFile: 'fd/1.txt' readFile: 'fd/1.txt'
...@@ -1380,12 +1334,13 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1380,12 +1334,13 @@ describe('ExtApi-FileManagerTest', () => {
}); });
//writeTest writeSyncTest //writeTest writeSyncTest
it('writeTest', async () => { it('writeTest', async () => {
if(!isAndroid()){ if (!isAndroid()) {
return return
} }
await clearDir('') await clearDir('')
await page.setData({ await page.setData({
logAble: false,
mkdirFile: 'fd', mkdirFile: 'fd',
writeFile: 'fd/1.txt', writeFile: 'fd/1.txt',
readFile: 'fd/1.txt', readFile: 'fd/1.txt',
...@@ -1443,4 +1398,46 @@ describe('ExtApi-FileManagerTest', () => { ...@@ -1443,4 +1398,46 @@ describe('ExtApi-FileManagerTest', () => {
expect(fstat).not.toEqual('ftruncate:ok') 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('')
});
}); });
...@@ -718,7 +718,6 @@ ...@@ -718,7 +718,6 @@
}, },
saveFileTest: function (_ : any) { saveFileTest: function (_ : any) {
const fileManager = uni.getFileSystemManager() const fileManager = uni.getFileSystemManager()
console.log('=====' + uni.env.USER_DATA_PATH)
fileManager.saveFile({ fileManager.saveFile({
tempFilePath: `${this.globalTempPath}${this.temFile}`, tempFilePath: `${this.globalTempPath}${this.temFile}`,
// filePath:`${this.basePath}local/`, // filePath:`${this.basePath}local/`,
...@@ -728,13 +727,15 @@ ...@@ -728,13 +727,15 @@
} }
console.log('success', res) console.log('success', res)
this.saveFileRet = res.savedFilePath this.saveFileRet = res.savedFilePath
this.done = true
}, },
fail: (res : UniError) => { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'saveFileTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('saveFileTest fail', res)
this.lastFailError = res this.lastFailError = res
this.done = true
}, },
complete: (_) => { complete: (_) => {
this.done = true this.done = true
...@@ -752,7 +753,7 @@ ...@@ -752,7 +753,7 @@
//todo 后面打开 //todo 后面打开
// this.saveFileRet=res // this.saveFileRet=res
} catch (e) { } catch (e) {
console.log(e) console.log('saveFileSyncTest:'+e)
this.done = true this.done = true
} }
}, },
...@@ -788,14 +789,14 @@ ...@@ -788,14 +789,14 @@
if (this.logAble) { if (this.logAble) {
this.log += 'getSavedFileListTest success:' + JSON.stringify(res) + '\n\n' this.log += 'getSavedFileListTest success:' + JSON.stringify(res) + '\n\n'
} }
console.log("success", res) console.log("getSavedFileListTest success", res)
this.fileListSuccess = res.fileList this.fileListSuccess = res.fileList
}, },
fail: (res : UniError) => { fail: (res : UniError) => {
if (this.logAble) { if (this.logAble) {
this.log += 'getSavedFileListTest fail:' + JSON.stringify(res) + '\n\n' this.log += 'getSavedFileListTest fail:' + JSON.stringify(res) + '\n\n'
} }
console.log('fail', res) console.log('getSavedFileListTest fail', res)
this.lastFailError = res this.lastFailError = res
}, },
complete: (res : any) => { complete: (res : any) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册