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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
07ec93ac
Commit
07ec93ac
authored
Mar 09, 2020
by
Nicolò Maria Mezzopera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move balsamiq_viewer_spec to jest
parent
a03444a7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
40 deletions
+50
-40
spec/frontend/blob/balsamiq/balsamiq_viewer_spec.js
spec/frontend/blob/balsamiq/balsamiq_viewer_spec.js
+50
-40
No files found.
spec/
javascripts
/blob/balsamiq/balsamiq_viewer_spec.js
→
spec/
frontend
/blob/balsamiq/balsamiq_viewer_spec.js
View file @
07ec93ac
...
...
@@ -3,6 +3,8 @@ import axios from '~/lib/utils/axios_utils';
import
BalsamiqViewer
from
'
~/blob/balsamiq/balsamiq_viewer
'
;
import
ClassSpecHelper
from
'
../../helpers/class_spec_helper
'
;
jest
.
mock
(
'
sql.js
'
);
describe
(
'
BalsamiqViewer
'
,
()
=>
{
const
mockArrayBuffer
=
new
ArrayBuffer
(
10
);
let
balsamiqViewer
;
...
...
@@ -34,22 +36,22 @@ describe('BalsamiqViewer', () => {
});
it
(
'
should call `axios.get` on `endpoint` param with responseType set to `arraybuffer
'
,
()
=>
{
spyOn
(
axios
,
'
get
'
).
and
.
r
eturnValue
(
requestSuccess
);
spyOn
(
bv
,
'
renderFile
'
).
and
.
stub
();
jest
.
spyOn
(
axios
,
'
get
'
).
mockR
eturnValue
(
requestSuccess
);
jest
.
spyOn
(
bv
,
'
renderFile
'
).
mockReturnValue
();
bv
.
loadFile
(
endpoint
);
expect
(
axios
.
get
).
toHaveBeenCalledWith
(
endpoint
,
jasmine
.
objectContaining
({
expect
.
objectContaining
({
responseType
:
'
arraybuffer
'
,
}),
);
});
it
(
'
should call `renderFile` on request success
'
,
done
=>
{
spyOn
(
axios
,
'
get
'
).
and
.
r
eturnValue
(
requestSuccess
);
spyOn
(
bv
,
'
renderFile
'
).
and
.
callFake
(()
=>
{});
jest
.
spyOn
(
axios
,
'
get
'
).
mockR
eturnValue
(
requestSuccess
);
jest
.
spyOn
(
bv
,
'
renderFile
'
).
mockImplementation
(()
=>
{});
bv
.
loadFile
(
endpoint
)
.
then
(()
=>
{
...
...
@@ -60,8 +62,8 @@ describe('BalsamiqViewer', () => {
});
it
(
'
should not call `renderFile` on request failure
'
,
done
=>
{
spyOn
(
axios
,
'
get
'
).
and
.
r
eturnValue
(
Promise
.
reject
());
spyOn
(
bv
,
'
renderFile
'
);
jest
.
spyOn
(
axios
,
'
get
'
).
mockR
eturnValue
(
Promise
.
reject
());
jest
.
spyOn
(
bv
,
'
renderFile
'
).
mockImplementation
(()
=>
{}
);
bv
.
loadFile
(
endpoint
)
.
then
(()
=>
{
...
...
@@ -80,19 +82,21 @@ describe('BalsamiqViewer', () => {
let
previews
;
beforeEach
(()
=>
{
viewer
=
jasmine
.
createSpyObj
(
'
viewer
'
,
[
'
appendChild
'
]);
viewer
=
{
appendChild
:
jest
.
fn
(),
};
previews
=
[
document
.
createElement
(
'
ul
'
),
document
.
createElement
(
'
ul
'
)];
balsamiqViewer
=
jasmine
.
createSpyObj
(
'
balsamiqViewer
'
,
[
'
initDatabase
'
,
'
getPreviews
'
,
'
renderPreview
'
,
])
;
balsamiqViewer
=
{
initDatabase
:
jest
.
fn
()
,
getPreviews
:
jest
.
fn
()
,
renderPreview
:
jest
.
fn
()
,
}
;
balsamiqViewer
.
viewer
=
viewer
;
balsamiqViewer
.
getPreviews
.
and
.
r
eturnValue
(
previews
);
balsamiqViewer
.
renderPreview
.
and
.
callFake
(
preview
=>
preview
);
viewer
.
appendChild
.
and
.
callFake
(
containerElement
=>
{
balsamiqViewer
.
getPreviews
.
mockR
eturnValue
(
previews
);
balsamiqViewer
.
renderPreview
.
mockImplementation
(
preview
=>
preview
);
viewer
.
appendChild
.
mockImplementation
(
containerElement
=>
{
container
=
containerElement
;
});
...
...
@@ -108,7 +112,7 @@ describe('BalsamiqViewer', () => {
});
it
(
'
should call .renderPreview for each preview
'
,
()
=>
{
const
allArgs
=
balsamiqViewer
.
renderPreview
.
calls
.
allArgs
()
;
const
allArgs
=
balsamiqViewer
.
renderPreview
.
mock
.
calls
;
expect
(
allArgs
.
length
).
toBe
(
2
);
...
...
@@ -132,19 +136,15 @@ describe('BalsamiqViewer', () => {
});
describe
(
'
initDatabase
'
,
()
=>
{
let
database
;
let
uint8Array
;
let
data
;
beforeEach
(()
=>
{
uint8Array
=
{};
database
=
{};
data
=
'
data
'
;
balsamiqViewer
=
{};
spyOn
(
window
,
'
Uint8Array
'
).
and
.
returnValue
(
uint8Array
);
spyOn
(
sqljs
,
'
Database
'
).
and
.
returnValue
(
database
);
window
.
Uint8Array
=
jest
.
fn
();
window
.
Uint8Array
.
mockReturnValue
(
uint8Array
);
BalsamiqViewer
.
prototype
.
initDatabase
.
call
(
balsamiqViewer
,
data
);
});
...
...
@@ -158,7 +158,7 @@ describe('BalsamiqViewer', () => {
});
it
(
'
should set .database
'
,
()
=>
{
expect
(
balsamiqViewer
.
database
).
toBe
(
database
);
expect
(
balsamiqViewer
.
database
).
not
.
toBe
(
null
);
});
});
...
...
@@ -168,15 +168,17 @@ describe('BalsamiqViewer', () => {
let
getPreviews
;
beforeEach
(()
=>
{
database
=
jasmine
.
createSpyObj
(
'
database
'
,
[
'
exec
'
]);
database
=
{
exec
:
jest
.
fn
(),
};
thumbnails
=
[{
values
:
[
0
,
1
,
2
]
}];
balsamiqViewer
=
{
database
,
};
spyOn
(
BalsamiqViewer
,
'
parsePreview
'
).
and
.
callFake
(
preview
=>
preview
.
toString
());
database
.
exec
.
and
.
r
eturnValue
(
thumbnails
);
jest
.
spyOn
(
BalsamiqViewer
,
'
parsePreview
'
).
mockImplementation
(
preview
=>
preview
.
toString
());
database
.
exec
.
mockR
eturnValue
(
thumbnails
);
getPreviews
=
BalsamiqViewer
.
prototype
.
getPreviews
.
call
(
balsamiqViewer
);
});
...
...
@@ -186,7 +188,7 @@ describe('BalsamiqViewer', () => {
});
it
(
'
should call .parsePreview for each value
'
,
()
=>
{
const
allArgs
=
BalsamiqViewer
.
parsePreview
.
calls
.
allArgs
()
;
const
allArgs
=
BalsamiqViewer
.
parsePreview
.
mock
.
calls
;
expect
(
allArgs
.
length
).
toBe
(
3
);
...
...
@@ -207,7 +209,9 @@ describe('BalsamiqViewer', () => {
let
getResource
;
beforeEach
(()
=>
{
database
=
jasmine
.
createSpyObj
(
'
database
'
,
[
'
exec
'
]);
database
=
{
exec
:
jest
.
fn
(),
};
resourceID
=
4
;
resource
=
[
'
resource
'
];
...
...
@@ -215,7 +219,7 @@ describe('BalsamiqViewer', () => {
database
,
};
database
.
exec
.
and
.
r
eturnValue
(
resource
);
database
.
exec
.
mockR
eturnValue
(
resource
);
getResource
=
BalsamiqViewer
.
prototype
.
getResource
.
call
(
balsamiqViewer
,
resourceID
);
});
...
...
@@ -241,14 +245,18 @@ describe('BalsamiqViewer', () => {
innerHTML
=
'
<a>innerHTML</a>
'
;
previewElement
=
{
outerHTML
:
'
<p>outerHTML</p>
'
,
classList
:
jasmine
.
createSpyObj
(
'
classList
'
,
[
'
add
'
]),
classList
:
{
add
:
jest
.
fn
(),
},
};
preview
=
{};
balsamiqViewer
=
jasmine
.
createSpyObj
(
'
balsamiqViewer
'
,
[
'
renderTemplate
'
]);
balsamiqViewer
=
{
renderTemplate
:
jest
.
fn
(),
};
spyOn
(
document
,
'
createElement
'
).
and
.
r
eturnValue
(
previewElement
);
balsamiqViewer
.
renderTemplate
.
and
.
r
eturnValue
(
innerHTML
);
jest
.
spyOn
(
document
,
'
createElement
'
).
mockR
eturnValue
(
previewElement
);
balsamiqViewer
.
renderTemplate
.
mockR
eturnValue
(
innerHTML
);
renderPreview
=
BalsamiqViewer
.
prototype
.
renderPreview
.
call
(
balsamiqViewer
,
preview
);
});
...
...
@@ -290,10 +298,12 @@ describe('BalsamiqViewer', () => {
</div>
`
;
balsamiqViewer
=
jasmine
.
createSpyObj
(
'
balsamiqViewer
'
,
[
'
getResource
'
]);
balsamiqViewer
=
{
getResource
:
jest
.
fn
(),
};
spyOn
(
BalsamiqViewer
,
'
parseTitle
'
).
and
.
r
eturnValue
(
name
);
balsamiqViewer
.
getResource
.
and
.
r
eturnValue
(
resource
);
jest
.
spyOn
(
BalsamiqViewer
,
'
parseTitle
'
).
mockR
eturnValue
(
name
);
balsamiqViewer
.
getResource
.
mockR
eturnValue
(
resource
);
renderTemplate
=
BalsamiqViewer
.
prototype
.
renderTemplate
.
call
(
balsamiqViewer
,
preview
);
});
...
...
@@ -306,7 +316,7 @@ describe('BalsamiqViewer', () => {
expect
(
BalsamiqViewer
.
parseTitle
).
toHaveBeenCalledWith
(
resource
);
});
it
(
'
should return the template string
'
,
function
()
{
it
(
'
should return the template string
'
,
()
=>
{
expect
(
renderTemplate
.
replace
(
/
\s
/g
,
''
)).
toEqual
(
template
.
replace
(
/
\s
/g
,
''
));
});
});
...
...
@@ -318,7 +328,7 @@ describe('BalsamiqViewer', () => {
beforeEach
(()
=>
{
preview
=
[
'
{}
'
,
'
{ "id": 1 }
'
];
spyOn
(
JSON
,
'
parse
'
).
and
.
callThrough
(
);
jest
.
spyOn
(
JSON
,
'
parse
'
);
parsePreview
=
BalsamiqViewer
.
parsePreview
(
preview
);
});
...
...
@@ -337,7 +347,7 @@ describe('BalsamiqViewer', () => {
beforeEach
(()
=>
{
title
=
{
values
:
[[
'
{}
'
,
'
{}
'
,
'
{"name":"name"}
'
]]
};
spyOn
(
JSON
,
'
parse
'
).
and
.
callThrough
(
);
jest
.
spyOn
(
JSON
,
'
parse
'
);
parseTitle
=
BalsamiqViewer
.
parseTitle
(
title
);
});
...
...
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