Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export to Gist #2522

Merged
merged 3 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
"nightwatch_local_solidityUnittests": "nightwatch ./test-browser/tests/solidityUnittests.js --config nightwatch.js --env chrome ",
"nightwatch_local_remixd": "nightwatch ./test-browser/tests/remix.js --config nightwatch.js --env chrome ",
"nightwatch_local_console": "nightwatch ./test-browser/tests/console.js --config nightwatch.js --env chrome ",
"nightwatch_local_gist": "nightwatch ./test-browser/tests/gist.js --config nightwatch.js --env chrome ",
"onchange": "onchange build/app.js -- npm-run-all lint",
"prepublish": "mkdirp build; npm-run-all -ls downloadsolc_root build",
"remixd": "remixd -s ./contracts --remix-ide http://127.0.0.1:8080",
Expand Down
8 changes: 5 additions & 3 deletions src/app/files/file-explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,9 @@ fileExplorer.prototype.toGist = function (id) {
return data.files || []
}

this.packageFiles(this.files, 'browser/gists/' + id, (error, packaged) => {
// If 'id' is not defined, it is not a gist update but a creation so we have to take the files from the browser explorer.
const folder = id ? 'browser/gists/' + id : 'browser/'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to have the comment here

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"If 'id' is not defined, it is not a gist update but a creation. we have to take the file from the browser explorer."

this.packageFiles(this.files, folder, (error, packaged) => {
if (error) {
console.log(error)
modalDialogCustom.alert('Failed to create gist: ' + error)
Expand Down Expand Up @@ -632,7 +634,7 @@ fileExplorer.prototype.renderMenuItems = function () {
items = this.menuItems.map(({action, title, icon}) => {
if (action === 'uploadFile') {
return yo`
<label class="${icon} ${css.newFile}" title="${title}">
<label id=${action} class="${icon} ${css.newFile}" title="${title}">
<input type="file" onchange=${(event) => {
event.stopPropagation()
this.uploadFile(event)
Expand All @@ -641,7 +643,7 @@ fileExplorer.prototype.renderMenuItems = function () {
`
} else {
return yo`
<span onclick=${(event) => { event.stopPropagation(); this[ action ]() }} class="newFile ${icon} ${css.newFile}" title=${title}></span>
<span id=${action} onclick=${(event) => { event.stopPropagation(); this[ action ]() }} class="newFile ${icon} ${css.newFile}" title=${title}></span>
`
}
})
Expand Down
1 change: 1 addition & 0 deletions test-browser/commands/executeScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ExecuteScript extends EventEmitter {
.click('#terminalCli')
.keys(script)
.keys(this.api.Keys.ENTER)
.keys(this.api.Keys.ENTER) // that's a bug... sometimes we need to press 2 times to execute a command
.perform(() => {
this.emit('complete')
})
Expand Down
16 changes: 16 additions & 0 deletions test-browser/commands/getModalBody.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const EventEmitter = require('events')

class GetModalBody extends EventEmitter {
command (callback) {
this.api.waitForElementVisible('.modal-body')
.getText('.modal-body', (result) => {
console.log(result)
callback(result.value, () => {
this.emit('complete')
})
})
return this
}
}

module.exports = GetModalBody
17 changes: 17 additions & 0 deletions test-browser/commands/modalFooterCancelClick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const EventEmitter = require('events')

class ModalFooterOKClick extends EventEmitter {
command () {
this.api.waitForElementVisible('#modal-footer-cancel').perform((client, done) => {
this.api.execute(function () {
document.querySelector('#modal-footer-cancel').click()
}, [], (result) => {
done()
this.emit('complete')
})
})
return this
}
}

module.exports = ModalFooterOKClick
2 changes: 1 addition & 1 deletion test-browser/commands/modalFooterOKClick.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const EventEmitter = require('events')

class ModalFooterOKClick extends EventEmitter {
command () {
this.api.perform((client, done) => {
this.api.waitForElementVisible('#modal-footer-ok').perform((client, done) => {
this.api.execute(function () {
document.querySelector('#modal-footer-ok').click()
}, [], (result) => {
Expand Down
1 change: 1 addition & 0 deletions test-browser/commands/switchFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class SwitchFile extends EventEmitter {
// click on fileExplorer can toggle it. We go through settings to be sure FE is open
function switchFile (browser, name, done) {
browser.clickLaunchIcon('settings').clickLaunchIcon('fileExplorers')
.waitForElementVisible('li[key="' + name + '"]')
.click('li[key="' + name + '"]')
.pause(2000)
.perform(() => {
Expand Down
45 changes: 45 additions & 0 deletions test-browser/tests/gist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict'
const init = require('../helpers/init')
const sauce = require('./sauce')
// 99266d6da54cc12f37f11586e8171546c7700d67

module.exports = {
before: function (browser, done) {
init(browser, done)
},
'UploadToGists': function (browser) {
/*
- set the access token
- publish to gist
- retrieve the gist
- switch to a file in the new gist
*/
console.log('token', process.env.gist_token)
browser
.waitForElementVisible('#icon-panel', 10000)
.clickLaunchIcon('settings')
.setValue('#gistaccesstoken', process.env.gist_token)
.click('#savegisttoken')
.clickLaunchIcon('fileExplorers')
.click('#publishToGist')
.modalFooterOKClick()
.getModalBody((value, done) => {
const reg = /gist.github.com\/([^.]+)/
const id = value.match(reg)
console.log('gist regex', id)
if (!id) {
browser.assert.fail('cannot get the gist id', '', '')
} else {
let gistid = id[1]
browser
.modalFooterCancelClick()
.executeScript(`remix.loadgist('${gistid}')`)
.switchFile('browser/gists')
.switchFile(`browser/gists/${gistid}`)
.switchFile(`browser/gists/${gistid}/1_Storage.sol`)
.end()
}
})
},
tearDown: sauce
}