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', () => {
...
@@ -9,9 +9,14 @@ describe('Blob viewer', () => {
let
blob
;
let
blob
;
let
mock
;
let
mock
;
const
jQueryMock
=
{
tooltip
:
jest
.
fn
(),
};
preloadFixtures
(
'
snippets/show.html
'
);
preloadFixtures
(
'
snippets/show.html
'
);
beforeEach
(()
=>
{
beforeEach
(()
=>
{
$
.
fn
.
extend
(
jQueryMock
);
mock
=
new
MockAdapter
(
axios
);
mock
=
new
MockAdapter
(
axios
);
loadFixtures
(
'
snippets/show.html
'
);
loadFixtures
(
'
snippets/show.html
'
);
...
@@ -27,7 +32,7 @@ describe('Blob viewer', () => {
...
@@ -27,7 +32,7 @@ describe('Blob viewer', () => {
html
:
'
<div>testing</div>
'
,
html
:
'
<div>testing</div>
'
,
});
});
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
(
);
jest
.
spyOn
(
axios
,
'
get
'
);
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
...
@@ -38,7 +43,7 @@ describe('Blob viewer', () => {
...
@@ -38,7 +43,7 @@ describe('Blob viewer', () => {
it
(
'
loads source file after switching views
'
,
done
=>
{
it
(
'
loads source file after switching views
'
,
done
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
expect
(
document
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
...
@@ -54,7 +59,7 @@ describe('Blob viewer', () => {
...
@@ -54,7 +59,7 @@ describe('Blob viewer', () => {
new
BlobViewer
();
new
BlobViewer
();
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
expect
(
document
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
...
@@ -65,26 +70,20 @@ describe('Blob viewer', () => {
...
@@ -65,26 +70,20 @@ describe('Blob viewer', () => {
});
});
});
});
it
(
'
doesnt reload file if already loaded
'
,
done
=>
{
it
(
'
doesnt reload file if already loaded
'
,
()
=>
{
const
asyncClick
=
()
=>
const
asyncClick
=
()
=>
new
Promise
(
resolve
=>
{
new
Promise
(
resolve
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
set
Timeout
(
resolve
);
set
Immediate
(
resolve
);
});
});
asyncClick
()
return
asyncClick
()
.
then
(()
=>
asyncClick
())
.
then
(()
=>
asyncClick
())
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
expect
(
document
.
querySelector
(
'
.blob-viewer[data-type="simple"]
'
).
getAttribute
(
'
data-loaded
'
),
document
.
querySelector
(
'
.blob-viewer[data-type="simple"]
'
).
getAttribute
(
'
data-loaded
'
),
).
toBe
(
'
true
'
);
).
toBe
(
'
true
'
);
done
();
})
.
catch
(()
=>
{
fail
();
done
();
});
});
});
});
...
@@ -100,13 +99,13 @@ describe('Blob viewer', () => {
...
@@ -100,13 +99,13 @@ describe('Blob viewer', () => {
});
});
it
(
'
has tooltip when disabled
'
,
()
=>
{
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
'
,
'
Switch to the source to copy the file contents
'
,
);
);
});
});
it
(
'
is blurred when clicked and disabled
'
,
()
=>
{
it
(
'
is blurred when clicked and disabled
'
,
()
=>
{
spyOn
(
copyButton
,
'
blur
'
);
jest
.
spyOn
(
copyButton
,
'
blur
'
).
mockImplementation
(()
=>
{}
);
copyButton
.
click
();
copyButton
.
click
();
...
@@ -114,7 +113,7 @@ describe('Blob viewer', () => {
...
@@ -114,7 +113,7 @@ describe('Blob viewer', () => {
});
});
it
(
'
is not blurred when clicked and not disabled
'
,
()
=>
{
it
(
'
is not blurred when clicked and not disabled
'
,
()
=>
{
spyOn
(
copyButton
,
'
blur
'
);
jest
.
spyOn
(
copyButton
,
'
blur
'
).
mockImplementation
(()
=>
{}
);
copyButton
.
classList
.
remove
(
'
disabled
'
);
copyButton
.
classList
.
remove
(
'
disabled
'
);
copyButton
.
click
();
copyButton
.
click
();
...
@@ -125,7 +124,7 @@ describe('Blob viewer', () => {
...
@@ -125,7 +124,7 @@ describe('Blob viewer', () => {
it
(
'
enables after switching to simple view
'
,
done
=>
{
it
(
'
enables after switching to simple view
'
,
done
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
copyButton
.
classList
.
contains
(
'
disabled
'
)).
toBeFalsy
();
expect
(
copyButton
.
classList
.
contains
(
'
disabled
'
)).
toBeFalsy
();
done
();
done
();
...
@@ -135,8 +134,8 @@ describe('Blob viewer', () => {
...
@@ -135,8 +134,8 @@ describe('Blob viewer', () => {
it
(
'
updates tooltip after switching to simple view
'
,
done
=>
{
it
(
'
updates tooltip after switching to simple view
'
,
done
=>
{
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
set
Timeout
(()
=>
{
set
Immediate
(()
=>
{
expect
(
copyButton
.
getAttribute
(
'
data-original-
title
'
)).
toBe
(
'
Copy file contents
'
);
expect
(
copyButton
.
getAttribute
(
'
title
'
)).
toBe
(
'
Copy file contents
'
);
done
();
done
();
});
});
...
@@ -155,7 +154,7 @@ describe('Blob viewer', () => {
...
@@ -155,7 +154,7 @@ describe('Blob viewer', () => {
it
(
'
adds active class to new viewer button
'
,
()
=>
{
it
(
'
adds active class to new viewer button
'
,
()
=>
{
const
simpleBtn
=
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
);
const
simpleBtn
=
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
);
spyOn
(
simpleBtn
,
'
blur
'
);
jest
.
spyOn
(
simpleBtn
,
'
blur
'
).
mockImplementation
(()
=>
{}
);
blob
.
switchToViewer
(
'
simple
'
);
blob
.
switchToViewer
(
'
simple
'
);
...
@@ -174,7 +173,7 @@ describe('Blob viewer', () => {
...
@@ -174,7 +173,7 @@ describe('Blob viewer', () => {
blob
.
switchToViewer
(
'
simple
'
);
blob
.
switchToViewer
(
'
simple
'
);
blob
.
switchToViewer
(
'
rich
'
);
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