diff --git a/apps/remix-ide-e2e/src/commands/openFile.ts b/apps/remix-ide-e2e/src/commands/openFile.ts index 05971583ef..262c9dddaf 100644 --- a/apps/remix-ide-e2e/src/commands/openFile.ts +++ b/apps/remix-ide-e2e/src/commands/openFile.ts @@ -1,5 +1,5 @@ import { NightwatchBrowser } from 'nightwatch' -import EventEmitter from "events" +import EventEmitter from 'events' class OpenFile extends EventEmitter { command (this: NightwatchBrowser, name: string) { diff --git a/apps/remix-ide-e2e/src/commands/renameFile.ts b/apps/remix-ide-e2e/src/commands/renameFile.ts new file mode 100644 index 0000000000..e7c95aaf73 --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/renameFile.ts @@ -0,0 +1,56 @@ +import EventEmitter from 'events' +import { NightwatchBrowser } from 'nightwatch' + +class RenameFile extends EventEmitter { + command (this: NightwatchBrowser, path: string, newFileName: string, renamedPath: string) { + this.api.perform((done) => { + renameFile(this.api, path, newFileName, renamedPath, () => { + done() + this.emit('complete') + }) + }) + return this + } +} + +function renameFile (browser: NightwatchBrowser, path: string, newFileName: string, renamedPath: string, done: VoidFunction) { + browser.execute(function (path: string) { + function contextMenuClick (element) { + const evt = element.ownerDocument.createEvent('MouseEvents') + const RIGHT_CLICK_BUTTON_CODE = 2 // the same for FF and IE + + evt.initMouseEvent('contextmenu', true, true, + element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, + false, false, false, RIGHT_CLICK_BUTTON_CODE, null) + if (Object.prototype.hasOwnProperty.call(document, 'createEventObject')) { + // dispatch for IE + return element.fireEvent('onclick', evt) + } else { + // dispatch for firefox + others + return !element.dispatchEvent(evt) + } + } + contextMenuClick(document.querySelector('[data-path="' + path + '"]')) + }, [path], function () { + browser + .click('#menuitemrename') + .perform((client, doneSetValue) => { + browser.execute(function (path, addvalue) { + document.querySelector('[data-path="' + path + '"]').innerHTML = addvalue + }, [path, newFileName], () => { + doneSetValue() + }) + }) + .click('body') // blur + .waitForElementVisible('#modal-footer-ok', 10000) + .pause(2000) + .click('#modal-footer-ok') + .waitForElementNotPresent('[data-path="' + path + '"]') + .waitForElementPresent('[data-path="' + renamedPath + '"]') + .perform(() => { + done() + }) + }) +} + +module.exports = RenameFile \ No newline at end of file diff --git a/apps/remix-ide-e2e/src/commands/rightClick.ts b/apps/remix-ide-e2e/src/commands/rightClick.ts new file mode 100644 index 0000000000..c373c99d6b --- /dev/null +++ b/apps/remix-ide-e2e/src/commands/rightClick.ts @@ -0,0 +1,37 @@ +import EventEmitter from 'events' +import { NightwatchBrowser } from 'nightwatch' + +class RightClick extends EventEmitter { + command (this: NightwatchBrowser, cssSelector: string) { + this.api.perform((done) => { + rightClick(this.api, cssSelector, () => { + done() + this.emit('complete') + }) + }) + return this + } +} + +function rightClick (browser: NightwatchBrowser, cssSelector: string, callback: VoidFunction) { + browser.execute(function (cssSelector: string) { + const element: any = document.querySelector(cssSelector) + const evt = element.ownerDocument.createEvent('MouseEvents') + const RIGHT_CLICK_BUTTON_CODE = 2 + + evt.initMouseEvent('contextmenu', true, true, + element.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, + false, false, false, RIGHT_CLICK_BUTTON_CODE, null) + if (Object.prototype.hasOwnProperty.call(document, 'createEventObject')) { + // dispatch for IE + return element.fireEvent('onclick', evt) + } else { + // dispatch for firefox + others + return !element.dispatchEvent(evt) + } + }, [cssSelector], function () { + callback() + }) +} + +module.exports = RightClick diff --git a/apps/remix-ide-e2e/src/tests/fileExplorer.test.ts b/apps/remix-ide-e2e/src/tests/fileExplorer.test.ts new file mode 100644 index 0000000000..37db537c19 --- /dev/null +++ b/apps/remix-ide-e2e/src/tests/fileExplorer.test.ts @@ -0,0 +1,111 @@ +'use strict' +import { NightwatchBrowser } from "nightwatch" + +const init = require('../helpers/init') +const sauce = require('./sauce') +const path = require('path') +const testData = { + testFile1: path.resolve(__dirname + '/editor.test.js'), // eslint-disable-line + testFile2: path.resolve(__dirname + '/fileExplorer.test.js'), // eslint-disable-line + testFile3: path.resolve(__dirname + '/generalSettings.test.js') // eslint-disable-line +} + +module.exports = { + + before: function (browser: NightwatchBrowser, done: VoidFunction) { + init(browser, done) + }, + + 'Should create a new file `5_New_contract.sol` in file explorer': function (browser: NightwatchBrowser) { + browser.waitForElementVisible('div[data-id="remixIdeSidePanel"]') + .clickLaunchIcon('fileExplorers') + .assert.containsText('h6[data-id="sidePanelSwapitTitle"]', 'FILE EXPLORERS') + .click('*[data-id="fileExplorerNewFilecreateNewFile"]') + .waitForElementVisible('*[data-id="modalDialogContainer"]') + .setValue('*[data-id="modalDialogCustomPromptText"]', '5_New_contract.sol') + .modalFooterOKClick() + .waitForElementVisible('*[data-id="treeViewLibrowser/5_New_contract.sol"]', 7000) + }, + + 'Should rename `5_New_contract.sol` to 5_Renamed_Contract.sol': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="treeViewLibrowser/5_New_contract.sol"]') + .renameFile('browser/5_New_contract.sol', '5_Renamed_Contract.sol', 'browser/5_Renamed_Contract.sol') + .waitForElementVisible('*[data-id="treeViewLibrowser/5_Renamed_Contract.sol"]') + }, + + 'Should delete file `5_Renamed_Contract.sol` from file explorer': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="treeViewLibrowser/5_Renamed_Contract.sol"]') + .rightClick('[data-path="browser/5_Renamed_Contract.sol"]') + .click('*[id="menuitemdelete"]') + .waitForElementVisible('*[data-id="modalDialogContainer"]') + .modalFooterOKClick() + .waitForElementNotPresent('*[data-id="treeViewLibrowser/5_Renamed_Contract.sol"') + }, + + 'Should create a new folder': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="treeViewLibrowser/1_Storage.sol"]') + .rightClick('[data-path="browser/1_Storage.sol"]') + .click('*[id="menuitemcreate folder"]') + .waitForElementVisible('*[data-id="modalDialogContainer"]') + .setValue('*[data-id="modalDialogCustomPromptText"]', 'Browser_Tests') + .modalFooterOKClick() + .waitForElementVisible('*[data-id="treeViewLibrowser/Browser_Tests"]') + }, + + 'Should rename Browser_Tests folder to Browser_E2E_Tests': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="treeViewLibrowser/Browser_Tests"]') + .rightClick('[data-path="browser/Browser_Tests"]') + .click('*[id="menuitemrename"]') + .sendKeys('[data-path="browser/Browser_Tests"]', 'Browser_E2E_Tests') + .sendKeys('[data-path="browser/Browser_Tests"]', browser.Keys.ENTER) + .waitForElementVisible('*[data-id="treeViewLibrowser/Browser_E2E_Tests"]') + }, + + 'Should delete Browser_E2E_Tests folder': function (browser: NightwatchBrowser) { + browser + .waitForElementVisible('*[data-id="treeViewLibrowser/Browser_E2E_Tests"]') + .rightClick('[data-path="browser/Browser_E2E_Tests"]') + .click('*[id="menuitemdelete"]') + .waitForElementVisible('*[data-id="modalDialogContainer"]') + .modalFooterOKClick() + .waitForElementNotPresent('*[data-id="treeViewLibrowser/Browser_E2E_Tests"]') + }, + + 'Should publish all explorer files to github gist': function (browser: NightwatchBrowser) { + const runtimeBrowser = browser.capabilities.browserName + + browser + .waitForElementVisible('*[data-id="fileExplorerNewFilepublishToGist"]') + .click('*[data-id="fileExplorerNewFilepublishToGist"]') + .waitForElementVisible('*[data-id="modalDialogContainer"]') + .modalFooterOKClick() + .waitForElementVisible('*[data-id="modalDialogContainer"]', 7000) + .modalFooterOKClick() + .pause(2000) + .perform((done) => { + if (runtimeBrowser === 'chrome') { + browser.switchBrowserTab(1) + .assert.urlContains('https://gist.github.com') + .switchBrowserTab(0) + } + done() + }) + }, + + 'Should open local filesystem explorer': function (browser: NightwatchBrowser) { + browser.waitForElementVisible('*[data-id="filePanelFileExplorerTree"]') + .setValue('*[data-id="fileExplorerFileUpload"]', testData.testFile1) + .setValue('*[data-id="fileExplorerFileUpload"]', testData.testFile2) + .setValue('*[data-id="fileExplorerFileUpload"]', testData.testFile3) + .waitForElementVisible('*[key="browser/editor.test.js"]') + .waitForElementVisible('*[key="browser/fileExplorer.test.js"]') + .waitForElementVisible('*[key="browser/generalSettings.test.js"]') + .end() + }, + + tearDown: sauce +} diff --git a/apps/remix-ide-e2e/src/types/index.d.ts b/apps/remix-ide-e2e/src/types/index.d.ts index 653b7bb577..1dd5a8eb6e 100644 --- a/apps/remix-ide-e2e/src/types/index.d.ts +++ b/apps/remix-ide-e2e/src/types/index.d.ts @@ -27,13 +27,18 @@ declare module "nightwatch" { debugTransaction(index: number): NightwatchBrowser, checkElementStyle(cssSelector: string, styleProperty: string, expectedResult: string): NightwatchBrowser, openFile(name: string): NightwatchBrowser, - editorScroll(direction: 'up' | 'down', numberOfTimes: number): NightwatchBrowser + editorScroll(direction: 'up' | 'down', numberOfTimes: number): NightwatchBrowser, + renameFile(path: string, newFileName: string, renamedPath: string): NightwatchBrowser, + rightClick(cssSelector: string): NightwatchBrowser } export interface NightwatchBrowser { api: this, emit: (status: string) => void, - fullscreenWindow: (result?: any) => this + fullscreenWindow: (result?: any) => this, + capabilities: { + browserName: string + } } export interface NightwatchContractContent {