pull/1/head
yann300 7 years ago
parent f46089f130
commit fe462d91b6
  1. 10
      src/lib/gist-handler.js
  2. 10
      test/gist-handler-test.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

@ -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) {

Loading…
Cancel
Save