From 049643a2894bced865834759c1f6031197c49e23 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Mon, 22 Jun 2020 14:03:53 +0100 Subject: [PATCH 1/4] Filemanager external api e2e tests --- package.json | 1 + src/app/files/fileManager.js | 2 +- test-browser/tests/fileManager_api.test.js | 143 +++++++++++++++++++++ 3 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 test-browser/tests/fileManager_api.test.js diff --git a/package.json b/package.json index 56d94c86a83..d023f34f3e0 100644 --- a/package.json +++ b/package.json @@ -187,6 +187,7 @@ "nightwatch_local_editor": "nightwatch ./test-browser/tests/editor.test.js --config nightwatch.js --env chrome ", "nightwatch_local_compiler": "nightwatch ./test-browser/tests/compiler_api.test.js --config nightwatch.js --env chrome ", "nightwatch_local_txListener": "nightwatch ./test-browser/tests/txListener.test.js --config nightwatch.js --env chrome ", + "nightwatch_local_fileManager": "nightwatch ./test-browser/tests/fileManager_api.test.js --config nightwatch.js --env chrome ", "nightwatch_local_runAndDeploy": "nightwatch ./test-browser/tests/runAndDeploy.js --config nightwatch.js --env chrome-runAndDeploy ", "onchange": "onchange build/app.js -- npm-run-all lint", "prepublish": "mkdirp build; npm-run-all -ls downloadsolc_root build", diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index fe74117a3a4..12bd9f32daf 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -23,7 +23,7 @@ const profile = { icon: 'assets/img/fileManager.webp', permission: true, version: packageJson.version, - methods: ['file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'rename', 'readdir', 'remove', 'getCurrentFile', 'getFile', 'getFolder', 'setFile', 'switchFile'], + methods: ['file', 'exists', 'open', 'writeFile', 'readFile', 'copyFile', 'rename', 'mkdir', 'readdir', 'remove', 'getCurrentFile', 'getFile', 'getFolder', 'setFile', 'switchFile'], kind: 'file-system' } const errorMsg = { diff --git a/test-browser/tests/fileManager_api.test.js b/test-browser/tests/fileManager_api.test.js new file mode 100644 index 00000000000..62b4340c6d5 --- /dev/null +++ b/test-browser/tests/fileManager_api.test.js @@ -0,0 +1,143 @@ +'use strict' +var init = require('../helpers/init') +var sauce = require('./sauce') + +module.exports = { + before: function (browser, done) { + init(browser, done) + }, + + 'Should execute `file` api from file manager external api': function (browser) { + browser + .addFile('file.js', { content: executeFile }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .journalLastChildIncludes('browser/file.js') + }, + + 'Should execute `exists` api from file manager external api': function (browser) { + browser + .addFile('exists.js', { content: executeExists }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .journalChildIncludes('browser/exists.js true') + .journalChildIncludes('browser/non-exists.js false') + }, + + 'Should execute `open` api from file manager external api': function (browser) { + browser + .addFile('open.js', { content: executeOpen }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .journalLastChildIncludes('browser/3_Ballot.sol') + }, + + 'Should execute `writeFile` api from file manager external api': function (browser) { + browser + .addFile('writeFile.js', { content: executeWriteFile }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .openFile('browser/new_contract.sol') + .assert.containsText('[data-id="editorInput"]', 'pragma solidity ^0.6.0') + }, + + 'Should execute `readFile` api from file manager external api': function (browser) { + browser + .addFile('readFile.js', { content: executeReadFile }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .journalLastChildIncludes('pragma solidity ^0.6.0') + }, + + 'Should execute `copyFile` api from file manager external api': function (browser) { + browser + .addFile('copyFile.js', { content: executeCopyFile }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .journalLastChildIncludes('pragma solidity >=0.2.0 <0.7.0;') + }, + + 'Should execute `rename` api from file manager external api': function (browser) { + browser + .addFile('renameFile.js', { content: executeRename }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .pause(100000) + // .journalLastChildIncludes('pragma solidity >=0.2.0 <0.7.0;') + // .end() + }, + + tearDown: sauce +} + +const executeFile = ` + const run = async () => { + const result = await remix.call('fileManager', 'file') + + console.log(result) + } + + run() +` + +const executeExists = ` + const run = async () => { + const result1 = await remix.call('fileManager', 'exists', 'browser/exists.js') + const result2 = await remix.call('fileManager', 'exists', 'browser/non-exists.js') + + console.log('browser/exists.js ' + result1) + console.log('browser/non-exists.js ' + result2) + } + + run() +` + +const executeOpen = ` + const run = async () => { + await remix.call('fileManager', 'open', 'browser/3_Ballot.sol') + const result = await remix.call('fileManager', 'file') + + console.log(result) + } + + run() +` + +const executeWriteFile = ` + const run = async () => { + await remix.call('fileManager', 'writeFile', 'browser/new_contract.sol', 'pragma solidity ^0.6.0') + } + + run() +` + +const executeReadFile = ` + const run = async () => { + const result = await remix.call('fileManager', 'readFile', 'browser/new_contract.sol') + + console.log(result) + } + + run() +` + +const executeCopyFile = ` + const run = async () => { + await remix.call('fileManager', 'copyFile', 'browser/basic.sol', 'browser/new_contract.sol') + const result = await remix.call('fileManager', 'readFile', 'browser/new_contract.sol') + + console.log(result) + } + + run() +` + +const executeRename = ` + const run = async () => { + const result = await remix.call('fileManager', 'rename', 'browser/new_contract.sol', 'browser/old_contract.sol') + + console.log(result) + } + + run() +` \ No newline at end of file From 76bd92c97ef5b937cf17a1914a8fe630acb2c04e Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Tue, 23 Jun 2020 16:41:28 +0100 Subject: [PATCH 2/4] Fixed rename api in file manager --- src/app/files/fileManager.js | 18 ++++++++++++++++-- test-browser/tests/fileManager_api.test.js | 16 ++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 12bd9f32daf..6699179c067 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -194,10 +194,24 @@ class FileManager extends Plugin { * @returns {void} */ async rename (oldPath, newPath) { - await this.__handleExists(oldPath, `Cannot rename ${oldPath}`) + await this._handleExists(oldPath, `Cannot rename ${oldPath}`) const isFile = await this.isFile(oldPath) + const newPathExists = await this.exists(newPath) + const provider = this.fileProviderOf(oldPath) - this.fileRenamedEvent(oldPath, newPath, !isFile) + if (isFile) { + if (newPathExists) { + modalDialogCustom.alert('File already exists.') + return + } + return provider.rename(oldPath, newPath, false) + } else { + if (newPathExists) { + modalDialogCustom.alert('Folder already exists.') + return + } + return provider.rename(oldPath, newPath, true) + } } /** diff --git a/test-browser/tests/fileManager_api.test.js b/test-browser/tests/fileManager_api.test.js index 62b4340c6d5..2dd0435a529 100644 --- a/test-browser/tests/fileManager_api.test.js +++ b/test-browser/tests/fileManager_api.test.js @@ -62,11 +62,19 @@ module.exports = { .addFile('renameFile.js', { content: executeRename }) .executeScript(`remix.exeCurrent()`) .pause(2000) - .pause(100000) - // .journalLastChildIncludes('pragma solidity >=0.2.0 <0.7.0;') - // .end() + .waitForElementPresent('[data-id="treeViewLibrowser/old_contract.sol"]') + .end() }, + // 'Should execute `rename` api from file manager external api': function (browser) { + // browser + // .addFile('renameFile.js', { content: executeRename }) + // .executeScript(`remix.exeCurrent()`) + // .pause(2000) + // .waitForElementPresent('[data-id="treeViewLibrowser/new_contract.sol"]') + // .end() + // }, + tearDown: sauce } @@ -136,7 +144,7 @@ const executeRename = ` const run = async () => { const result = await remix.call('fileManager', 'rename', 'browser/new_contract.sol', 'browser/old_contract.sol') - console.log(result) + console.log('result: ', result) } run() From 8e8c38a40e02b45658bf569e0ff2d0bfbc59b67e Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 24 Jun 2020 16:07:07 +0100 Subject: [PATCH 3/4] mkdir, readdir and remove filemanager api e2e --- test-browser/tests/fileManager_api.test.js | 61 ++++++++++++++++++---- 1 file changed, 50 insertions(+), 11 deletions(-) diff --git a/test-browser/tests/fileManager_api.test.js b/test-browser/tests/fileManager_api.test.js index 2dd0435a529..7749d471a28 100644 --- a/test-browser/tests/fileManager_api.test.js +++ b/test-browser/tests/fileManager_api.test.js @@ -63,17 +63,32 @@ module.exports = { .executeScript(`remix.exeCurrent()`) .pause(2000) .waitForElementPresent('[data-id="treeViewLibrowser/old_contract.sol"]') - .end() }, - // 'Should execute `rename` api from file manager external api': function (browser) { - // browser - // .addFile('renameFile.js', { content: executeRename }) - // .executeScript(`remix.exeCurrent()`) - // .pause(2000) - // .waitForElementPresent('[data-id="treeViewLibrowser/new_contract.sol"]') - // .end() - // }, + 'Should execute `mkdir` api from file manager external api': function (browser) { + browser + .addFile('mkdirFile.js', { content: executeMkdir }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .waitForElementPresent('[data-id="treeViewLibrowser/Test_Folder"]') + }, + + 'Should execute `readdir` api from file manager external api': function (browser) { + browser + .addFile('readdirFile.js', { content: executeReaddir }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .journalLastChildIncludes('Test_Folder isDirectory true') + }, + + 'Should execute `remove` api from file manager external api': function (browser) { + browser + .addFile('removeFile.js', { content: executeRemove }) + .executeScript(`remix.exeCurrent()`) + .pause(2000) + .waitForElementNotVisible('[data-id="treeViewLibrowser/old_contract.sol"]') + .end() + }, tearDown: sauce } @@ -142,9 +157,33 @@ const executeCopyFile = ` const executeRename = ` const run = async () => { - const result = await remix.call('fileManager', 'rename', 'browser/new_contract.sol', 'browser/old_contract.sol') + await remix.call('fileManager', 'rename', 'browser/new_contract.sol', 'browser/old_contract.sol') + } + + run() +` + +const executeMkdir = ` + const run = async () => { + await remix.call('fileManager', 'mkdir', 'browser/Test_Folder/') + } + + run() +` - console.log('result: ', result) +const executeReaddir = ` + const run = async () => { + const result = await remix.call('fileManager', 'readdir', 'browser/') + + console.log('Test_Folder isDirectory ', result["Test_Folder"].isDirectory) + } + + run() +` + +const executeRemove = ` + const run = async () => { + await remix.call('fileManager', 'remove', 'browser/old_contract.sol') } run() From 0d3a63c48c676b80491983c9b47dbeab0add3e56 Mon Sep 17 00:00:00 2001 From: ioedeveloper Date: Wed, 24 Jun 2020 16:08:49 +0100 Subject: [PATCH 4/4] Fixed linting error --- test-browser/tests/fileManager_api.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-browser/tests/fileManager_api.test.js b/test-browser/tests/fileManager_api.test.js index 7749d471a28..681d354d2b3 100644 --- a/test-browser/tests/fileManager_api.test.js +++ b/test-browser/tests/fileManager_api.test.js @@ -187,4 +187,4 @@ const executeRemove = ` } run() -` \ No newline at end of file +`