From fe462d91b6536e9dc2733479eeac4a20e7d9228d Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 28 Sep 2017 13:30:34 +0200 Subject: [PATCH] fix test --- src/lib/gist-handler.js | 10 +++++++--- test/gist-handler-test.js | 10 +++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/lib/gist-handler.js b/src/lib/gist-handler.js index d023268d27..b66db8ef22 100644 --- a/src/lib/gist-handler.js +++ b/src/lib/gist-handler.js @@ -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 diff --git a/test/gist-handler-test.js b/test/gist-handler-test.js index e2aa74d6f7..367fc58bf5 100644 --- a/test/gist-handler-test.js +++ b/test/gist-handler-test.js @@ -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) { 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) @@ -29,16 +29,16 @@ test('gistHandler.handleLoad with blank gist param, and invalid user input', fun 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) {