Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
897d8d54
Commit
897d8d54
authored
Apr 11, 2017
by
Luke "Jared" Bennett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Further review changes
parent
b72e18b0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
40 deletions
+98
-40
app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js
app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js
+19
-9
spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js
spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js
+79
-31
No files found.
app/assets/javascripts/blob/balsamiq/balsamiq_viewer.js
View file @
897d8d54
/* global Flash */
import
sqljs
from
'
sql.js
'
;
import
_
from
'
underscore
'
;
import
Spinner
from
'
../../spinner
'
;
class
BalsamiqViewer
{
...
...
@@ -52,6 +53,10 @@ class BalsamiqViewer {
return
thumbnails
[
0
].
values
.
map
(
BalsamiqViewer
.
parsePreview
);
}
getTitle
(
resourceID
)
{
return
this
.
database
.
exec
(
`SELECT * FROM resources WHERE id = '
${
resourceID
}
'`
);
}
renderPreview
(
preview
)
{
const
previewElement
=
document
.
createElement
(
'
li
'
);
...
...
@@ -62,13 +67,14 @@ class BalsamiqViewer {
}
renderTemplate
(
preview
)
{
let
template
=
BalsamiqViewer
.
PREVIEW_TEMPLATE
;
const
title
=
this
.
database
.
exec
(
`SELECT * FROM resources WHERE id = '
${
preview
.
resourceID
}
'`
);
const
name
=
JSON
.
parse
(
title
[
0
].
values
[
0
][
2
]).
name
;
const
title
=
this
.
getTitle
(
preview
.
resourceID
);
const
name
=
BalsamiqViewer
.
parseTitle
(
title
);
const
image
=
preview
.
image
;
template
=
template
.
replace
(
/{{name}}/g
,
name
).
replace
(
/{{image}}/g
,
image
);
const
template
=
BalsamiqViewer
.
PREVIEW_TEMPLATE
({
name
,
image
,
});
return
template
;
}
...
...
@@ -77,6 +83,10 @@ class BalsamiqViewer {
return
JSON
.
parse
(
preview
[
1
]);
}
static
parseTitle
(
title
)
{
return
JSON
.
parse
(
title
[
0
].
values
[
0
][
2
]).
name
;
}
static
onError
()
{
const
flash
=
new
Flash
(
'
Balsamiq file could not be loaded.
'
);
...
...
@@ -84,13 +94,13 @@ class BalsamiqViewer {
}
}
BalsamiqViewer
.
PREVIEW_TEMPLATE
=
`
BalsamiqViewer
.
PREVIEW_TEMPLATE
=
_
.
template
(
`
<div class="panel panel-default">
<div class="panel-heading">
{{name}}
</div>
<div class="panel-heading">
<%- name %>
</div>
<div class="panel-body">
<img class="img-thumbnail" src="data:image/png;base64,
{{image}}
"/>
<img class="img-thumbnail" src="data:image/png;base64,
<%- image %>
"/>
</div>
</div>
`
;
`
)
;
export
default
BalsamiqViewer
;
spec/javascripts/blob/balsamiq/balsamiq_viewer_spec.js
View file @
897d8d54
...
...
@@ -216,6 +216,35 @@ describe('BalsamiqViewer', () => {
});
});
describe
(
'
getTitle
'
,
()
=>
{
let
database
;
let
resourceID
;
let
resource
;
let
getTitle
;
beforeEach
(()
=>
{
database
=
jasmine
.
createSpyObj
(
'
database
'
,
[
'
exec
'
]);
resourceID
=
4
;
resource
=
'
resource
'
;
balsamiqViewer
=
{
database
,
};
database
.
exec
.
and
.
returnValue
(
resource
);
getTitle
=
BalsamiqViewer
.
prototype
.
getTitle
.
call
(
balsamiqViewer
,
resourceID
);
});
it
(
'
should call database.exec
'
,
()
=>
{
expect
(
database
.
exec
).
toHaveBeenCalledWith
(
`SELECT * FROM resources WHERE id = '
${
resourceID
}
'`
);
});
it
(
'
should return the selected resource
'
,
()
=>
{
expect
(
getTitle
).
toBe
(
resource
);
});
});
describe
(
'
renderPreview
'
,
()
=>
{
let
previewElement
;
let
innerHTML
;
...
...
@@ -261,54 +290,50 @@ describe('BalsamiqViewer', () => {
describe
(
'
renderTemplate
'
,
()
=>
{
let
preview
;
let
databas
e
;
let
nam
e
;
let
title
;
let
template
;
let
renderTemplate
;
beforeEach
(()
=>
{
preview
=
{
reosourceID
:
1
,
image
:
'
image
'
};
title
=
[{
values
:
[[
'
{}
'
,
'
{}
'
,
'
{ "name": "name" }
'
]]
}];
database
=
jasmine
.
createSpyObj
(
'
database
'
,
[
'
exec
'
]);
database
.
exec
.
and
.
returnValue
(
title
);
preview
=
{
resourceID
:
1
,
image
:
'
image
'
};
name
=
'
name
'
;
title
=
'
title
'
;
template
=
`
<div class="panel panel-default">
<div class="panel-heading">name</div>
<div class="panel-body">
<img class="img-thumbnail" src="data:image/png;base64,image"/>
</div>
</div>
`
;
balsamiqViewer
=
{
database
,
};
balsamiqViewer
=
jasmine
.
createSpyObj
(
'
balsamiqViewer
'
,
[
'
getTitle
'
]);
spyOn
(
JSON
,
'
parse
'
).
and
.
callThrough
();
spyOn
(
String
.
prototype
,
'
replace
'
).
and
.
callThrough
();
spyOn
(
BalsamiqViewer
,
'
parseTitle
'
).
and
.
returnValue
(
name
);
spyOn
(
BalsamiqViewer
,
'
PREVIEW_TEMPLATE
'
).
and
.
returnValue
(
template
);
balsamiqViewer
.
getTitle
.
and
.
returnValue
(
title
);
renderTemplate
=
BalsamiqViewer
.
prototype
.
renderTemplate
.
call
(
balsamiqViewer
,
preview
);
});
it
(
'
should call
database.exec
'
,
()
=>
{
expect
(
database
.
exec
).
toHaveBeenCalledWith
(
`SELECT * FROM resources WHERE id = '
${
preview
.
resourceID
}
'`
);
it
(
'
should call
.getTitle
'
,
()
=>
{
expect
(
balsamiqViewer
.
getTitle
).
toHaveBeenCalledWith
(
preview
.
resourceID
);
});
it
(
'
should call
JSON.pars
e
'
,
()
=>
{
expect
(
JSON
.
parse
).
toHaveBeenCalledWith
(
title
[
0
].
values
[
0
][
2
]
);
it
(
'
should call
.parseTitl
e
'
,
()
=>
{
expect
(
BalsamiqViewer
.
parseTitle
).
toHaveBeenCalledWith
(
title
);
});
it
(
'
should call String.prototype.replace
'
,
()
=>
{
const
allArgs
=
String
.
prototype
.
replace
.
calls
.
allArgs
();
expect
(
allArgs
.
length
).
toBe
(
2
);
expect
(
allArgs
[
0
]).
toEqual
([
/{{name}}/g
,
'
name
'
]);
expect
(
allArgs
[
1
]).
toEqual
([
/{{image}}/g
,
'
image
'
]);
it
(
'
should call .PREVIEW_TEMPLATE
'
,
()
=>
{
expect
(
BalsamiqViewer
.
PREVIEW_TEMPLATE
).
toHaveBeenCalledWith
({
name
,
image
:
preview
.
image
,
});
});
it
(
'
should return the template string
'
,
function
()
{
const
template
=
`
<div class="panel panel-default">
<div class="panel-heading">name</div>
<div class="panel-body">
<img class="img-thumbnail" src="data:image/png;base64,image"/>
</div>
</div>
`
;
expect
(
renderTemplate
.
replace
(
/
\s
/g
,
''
)).
toEqual
(
template
.
replace
(
/
\s
/g
,
''
));
expect
(
renderTemplate
.
trim
()).
toBe
(
template
.
trim
());
});
});
...
...
@@ -335,6 +360,29 @@ describe('BalsamiqViewer', () => {
});
});
describe
(
'
parseTitle
'
,
()
=>
{
let
title
;
let
parseTitle
;
beforeEach
(()
=>
{
title
=
[{
values
:
[[
'
{}
'
,
'
{}
'
,
'
{"name":"name"}
'
]]
}];
spyOn
(
JSON
,
'
parse
'
).
and
.
callThrough
();
parseTitle
=
BalsamiqViewer
.
parseTitle
(
title
);
});
ClassSpecHelper
.
itShouldBeAStaticMethod
(
BalsamiqViewer
,
'
parsePreview
'
);
it
(
'
should call JSON.parse
'
,
()
=>
{
expect
(
JSON
.
parse
).
toHaveBeenCalledWith
(
title
[
0
].
values
[
0
][
2
]);
});
it
(
'
should return the name value
'
,
()
=>
{
expect
(
parseTitle
).
toBe
(
'
name
'
);
});
});
describe
(
'
onError
'
,
()
=>
{
let
onError
;
...
...
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