Commit fe462d91 authored by yann300's avatar yann300

fix test

parent f46089f1
...@@ -2,21 +2,25 @@ ...@@ -2,21 +2,25 @@
var modalDialogCustom = require('../app/ui/modal-dialog-custom') var modalDialogCustom = require('../app/ui/modal-dialog-custom')
// Allowing window to be overriden for testing // Allowing window to be overriden for testing
function GistHandler (_window) { function GistHandler (_window) {
if (_window === undefined) _window = window if (_window !== undefined) {
modalDialogCustom = _window
}
this.handleLoad = function (params, cb) { this.handleLoad = function (params, cb) {
if (!cb) cb = () => {}
var loadingFromGist = false var loadingFromGist = false
var gistId var gistId
if (params['gist'] === '') { if (params['gist'] === '') {
loadingFromGist = true
modalDialogCustom.prompt(null, 'Enter the URL or ID of the Gist you would like to load.', null, (target) => { modalDialogCustom.prompt(null, 'Enter the URL or ID of the Gist you would like to load.', null, (target) => {
if (target !== '') { if (target !== '') {
gistId = getGistId(target) gistId = getGistId(target)
loadingFromGist = !!gistId if (gistId) {
if (loadingFromGist) {
cb(gistId) cb(gistId)
} }
} }
}) })
return loadingFromGist
} else { } else {
gistId = params['gist'] gistId = params['gist']
loadingFromGist = !!gistId loadingFromGist = !!gistId
......
...@@ -18,10 +18,10 @@ test('gistHandler.handleLoad with no gist param', function (t) { ...@@ -18,10 +18,10 @@ test('gistHandler.handleLoad with no gist param', function (t) {
test('gistHandler.handleLoad with blank gist param, and invalid user input', function (t) { test('gistHandler.handleLoad with blank gist param, and invalid user input', function (t) {
t.plan(3) t.plan(3)
var fakeWindow = {prompt: function (message) { var fakeWindow = {prompt: function (title, message, input, cb) {
t.ok(message) t.ok(message)
t.ok(message.match(/gist/i)) t.ok(message.match(/gist/i))
return 'invalid' cb('invalid')
}} }}
var gistHandler = new GistHandler(fakeWindow) var gistHandler = new GistHandler(fakeWindow)
...@@ -29,16 +29,16 @@ test('gistHandler.handleLoad with blank gist param, and invalid user input', fun ...@@ -29,16 +29,16 @@ test('gistHandler.handleLoad with blank gist param, and invalid user input', fun
var params = {'gist': ''} var params = {'gist': ''}
var result = gistHandler.handleLoad(params, null) 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) { test('gistHandler.handleLoad with blank gist param, and valid user input', function (t) {
t.plan(4) t.plan(4)
var fakeWindow = {prompt: function (message) { var fakeWindow = {prompt: function (title, message, input, cb) {
t.ok(message) t.ok(message)
t.ok(message.match(/gist/i)) t.ok(message.match(/gist/i))
return 'Beef1234' cb('Beef1234')
}} }}
var cb = function (gistId) { var cb = function (gistId) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment