Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
f8c7308c
Commit
f8c7308c
authored
Feb 19, 2019
by
Grandschtroumpf
Committed by
yann300
Mar 04, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify gist handler for testing
parent
eaba9b71
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
64 deletions
+46
-64
gist-handler-test.js
test/gist-handler-test.js
+46
-64
No files found.
test/gist-handler-test.js
View file @
f8c7308c
'use strict'
'use strict'
var
modalDialogCustom
var
test
=
require
(
'tape'
)
if
(
typeof
window
!==
'undefined'
)
{
modalDialogCustom
=
require
(
'../app/ui/modal-dialog-custom'
)
var
GistHandler
=
require
(
'../src/lib/gist-handler'
)
}
// ^ this class can be load in a non browser context when running node unit testing.
test
(
'gistHandler.handleLoad with no gist param'
,
function
(
t
)
{
// should not load UI in that case
t
.
plan
(
1
)
// Allowing window to be overriden for testing
var
gistHandler
=
new
GistHandler
({})
function
GistHandler
(
_window
)
{
if
(
_window
!==
undefined
)
{
var
params
=
{}
modalDialogCustom
=
_window
var
result
=
gistHandler
.
handleLoad
(
params
,
null
)
t
.
equal
(
result
,
false
)
})
test
(
'gistHandler.handleLoad with blank gist param, and invalid user input'
,
function
(
t
)
{
t
.
plan
(
3
)
var
fakeWindow
=
{
prompt
:
function
(
title
,
message
,
input
,
cb
)
{
t
.
ok
(
message
)
t
.
ok
(
message
.
match
(
/gist/i
))
cb
(
'invalid'
)
}}
var
gistHandler
=
new
GistHandler
(
fakeWindow
)
var
params
=
{
'gist'
:
''
}
var
result
=
gistHandler
.
handleLoad
(
params
,
null
)
t
.
equal
(
result
,
true
)
})
test
(
'gistHandler.handleLoad with blank gist param, and valid user input'
,
function
(
t
)
{
t
.
plan
(
4
)
var
fakeWindow
=
{
prompt
:
function
(
title
,
message
,
input
,
cb
)
{
t
.
ok
(
message
)
t
.
ok
(
message
.
match
(
/gist/i
))
cb
(
'Beef1234'
)
}}
var
cb
=
function
(
gistId
)
{
t
.
equal
(
gistId
,
'Beef1234'
)
}
}
var
gistHandler
=
new
GistHandler
(
fakeWindow
)
this
.
handleLoad
=
function
(
params
,
cb
)
{
if
(
!
cb
)
cb
=
()
=>
{}
var
params
=
{
'gist'
:
''
}
var
loadingFromGist
=
false
var
result
=
gistHandler
.
handleLoad
(
params
,
cb
)
var
gistId
if
(
params
[
'gist'
]
===
''
)
{
t
.
equal
(
result
,
true
)
loadingFromGist
=
true
})
modalDialogCustom
.
prompt
(
null
,
test
(
'gistHandler.handleLoad with gist param'
,
function
(
t
)
{
'Enter the URL or ID of the Gist you would like to load.'
,
t
.
plan
(
2
)
null
,
target
=>
{
var
gistHandler
=
new
GistHandler
({})
if
(
target
!==
''
)
{
gistId
=
getGistId
(
target
)
var
params
=
{
'gist'
:
'abc'
}
if
(
gistId
)
{
cb
(
gistId
)
var
cb
=
function
(
gistId
)
{
}
t
.
equal
(
gistId
,
'abc'
)
}
}
)
return
loadingFromGist
}
else
{
gistId
=
params
[
'gist'
]
loadingFromGist
=
!!
gistId
}
if
(
loadingFromGist
)
{
cb
(
gistId
)
}
return
loadingFromGist
}
}
var
result
=
gistHandler
.
handleLoad
(
params
,
cb
)
function
getGistId
(
str
)
{
var
idr
=
/
[
0-9A-Fa-f
]{8,}
/
var
match
=
idr
.
exec
(
str
)
return
match
?
match
[
0
]
:
null
}
}
t
.
equal
(
result
,
true
)
module
.
exports
=
GistHandler
})
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment