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
ec4ca6b4
Commit
ec4ca6b4
authored
Mar 09, 2020
by
Nicolò Maria Mezzopera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate blob viewer index_spec to jest
parent
2665e40c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
20 deletions
+19
-20
spec/frontend/blob/viewer/index_spec.js
spec/frontend/blob/viewer/index_spec.js
+19
-20
No files found.
spec/
javascripts
/blob/viewer/index_spec.js
→
spec/
frontend
/blob/viewer/index_spec.js
View file @
ec4ca6b4
...
...
@@ -9,9 +9,14 @@ describe('Blob viewer', () => {
let
blob
;
let
mock
;
const
jQueryMock
=
{
tooltip
:
jest
.
fn
(),
};
preloadFixtures
(
'
snippets/show.html
'
);
beforeEach
(()
=>
{
$
.
fn
.
extend
(
jQueryMock
);
mock
=
new
MockAdapter
(
axios
);
loadFixtures
(
'
snippets/show.html
'
);
...
...
@@ -27,7 +32,7 @@ describe('Blob viewer', () => {
html
:
'
<div>testing</div>
'
,
});
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
(
);
jest
.
spyOn
(
axios
,
'
get
'
);
});
afterEach
(()
=>
{
...
...
@@ -38,7 +43,7 @@ describe('Blob viewer', () => {
it
(
'
loads source file after switching views
'
,
done
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
...
...
@@ -54,7 +59,7 @@ describe('Blob viewer', () => {
new
BlobViewer
();
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
...
...
@@ -65,26 +70,20 @@ describe('Blob viewer', () => {
});
});
it
(
'
doesnt reload file if already loaded
'
,
done
=>
{
it
(
'
doesnt reload file if already loaded
'
,
()
=>
{
const
asyncClick
=
()
=>
new
Promise
(
resolve
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
set
Timeout
(
resolve
);
set
Immediate
(
resolve
);
});
asyncClick
()
return
asyncClick
()
.
then
(()
=>
asyncClick
())
.
then
(()
=>
{
expect
(
document
.
querySelector
(
'
.blob-viewer[data-type="simple"]
'
).
getAttribute
(
'
data-loaded
'
),
).
toBe
(
'
true
'
);
done
();
})
.
catch
(()
=>
{
fail
();
done
();
});
});
...
...
@@ -100,13 +99,13 @@ describe('Blob viewer', () => {
});
it
(
'
has tooltip when disabled
'
,
()
=>
{
expect
(
copyButton
.
getAttribute
(
'
data-original-
title
'
)).
toBe
(
expect
(
copyButton
.
getAttribute
(
'
title
'
)).
toBe
(
'
Switch to the source to copy the file contents
'
,
);
});
it
(
'
is blurred when clicked and disabled
'
,
()
=>
{
spyOn
(
copyButton
,
'
blur
'
);
jest
.
spyOn
(
copyButton
,
'
blur
'
).
mockImplementation
(()
=>
{}
);
copyButton
.
click
();
...
...
@@ -114,7 +113,7 @@ describe('Blob viewer', () => {
});
it
(
'
is not blurred when clicked and not disabled
'
,
()
=>
{
spyOn
(
copyButton
,
'
blur
'
);
jest
.
spyOn
(
copyButton
,
'
blur
'
).
mockImplementation
(()
=>
{}
);
copyButton
.
classList
.
remove
(
'
disabled
'
);
copyButton
.
click
();
...
...
@@ -125,7 +124,7 @@ describe('Blob viewer', () => {
it
(
'
enables after switching to simple view
'
,
done
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
copyButton
.
classList
.
contains
(
'
disabled
'
)).
toBeFalsy
();
done
();
...
...
@@ -135,8 +134,8 @@ describe('Blob viewer', () => {
it
(
'
updates tooltip after switching to simple view
'
,
done
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
set
Timeout
(()
=>
{
expect
(
copyButton
.
getAttribute
(
'
data-original-
title
'
)).
toBe
(
'
Copy file contents
'
);
set
Immediate
(()
=>
{
expect
(
copyButton
.
getAttribute
(
'
title
'
)).
toBe
(
'
Copy file contents
'
);
done
();
});
...
...
@@ -155,7 +154,7 @@ describe('Blob viewer', () => {
it
(
'
adds active class to new viewer button
'
,
()
=>
{
const
simpleBtn
=
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
);
spyOn
(
simpleBtn
,
'
blur
'
);
jest
.
spyOn
(
simpleBtn
,
'
blur
'
).
mockImplementation
(()
=>
{}
);
blob
.
switchToViewer
(
'
simple
'
);
...
...
@@ -174,7 +173,7 @@ describe('Blob viewer', () => {
blob
.
switchToViewer
(
'
simple
'
);
blob
.
switchToViewer
(
'
rich
'
);
expect
(
axios
.
get
.
calls
.
count
()
).
toBe
(
1
);
expect
(
axios
.
get
.
mock
.
calls
.
length
).
toBe
(
1
);
});
});
});
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