Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
yann300 committed Sep 28, 2017
1 parent f46089f commit fe462d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 7 additions & 3 deletions src/lib/gist-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@
var modalDialogCustom = require('../app/ui/modal-dialog-custom')
// Allowing window to be overriden for testing
function GistHandler (_window) {
if (_window === undefined) _window = window
if (_window !== undefined) {
modalDialogCustom = _window
}

this.handleLoad = function (params, cb) {
if (!cb) cb = () => {}
var loadingFromGist = false
var gistId
if (params['gist'] === '') {
loadingFromGist = true
modalDialogCustom.prompt(null, 'Enter the URL or ID of the Gist you would like to load.', null, (target) => {
if (target !== '') {
gistId = getGistId(target)
loadingFromGist = !!gistId
if (loadingFromGist) {
if (gistId) {
cb(gistId)
}
}
})
return loadingFromGist
} else {
gistId = params['gist']
loadingFromGist = !!gistId
Expand Down
10 changes: 5 additions & 5 deletions test/gist-handler-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ test('gistHandler.handleLoad with no gist param', function (t) {
test('gistHandler.handleLoad with blank gist param, and invalid user input', function (t) {
t.plan(3)

var fakeWindow = {prompt: function (message) {
var fakeWindow = {prompt: function (title, message, input, cb) {
t.ok(message)
t.ok(message.match(/gist/i))
return 'invalid'
cb('invalid')
}}

var gistHandler = new GistHandler(fakeWindow)

var params = {'gist': ''}
var result = gistHandler.handleLoad(params, null)

t.equal(result, false)
t.equal(result, true)
})

test('gistHandler.handleLoad with blank gist param, and valid user input', function (t) {
t.plan(4)

var fakeWindow = {prompt: function (message) {
var fakeWindow = {prompt: function (title, message, input, cb) {
t.ok(message)
t.ok(message.match(/gist/i))
return 'Beef1234'
cb('Beef1234')
}}

var cb = function (gistId) {
Expand Down

0 comments on commit fe462d9

Please sign in to comment.