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
a16cdd0b
Commit
a16cdd0b
authored
Jan 26, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
converted blob viewer to axios
parent
e0b4d919
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
33 deletions
+25
-33
app/assets/javascripts/blob/viewer/index.js
app/assets/javascripts/blob/viewer/index.js
+8
-14
spec/javascripts/blob/viewer/index_spec.js
spec/javascripts/blob/viewer/index_spec.js
+17
-19
No files found.
app/assets/javascripts/blob/viewer/index.js
View file @
a16cdd0b
import
Flash
from
'
../../flash
'
;
import
Flash
from
'
../../flash
'
;
import
{
handleLocationHash
}
from
'
../../lib/utils/common_utils
'
;
import
{
handleLocationHash
}
from
'
../../lib/utils/common_utils
'
;
import
axios
from
'
../../lib/utils/axios_utils
'
;
export
default
class
BlobViewer
{
export
default
class
BlobViewer
{
constructor
()
{
constructor
()
{
...
@@ -127,25 +128,18 @@ export default class BlobViewer {
...
@@ -127,25 +128,18 @@ export default class BlobViewer {
const
viewer
=
viewerParam
;
const
viewer
=
viewerParam
;
const
url
=
viewer
.
getAttribute
(
'
data-url
'
);
const
url
=
viewer
.
getAttribute
(
'
data-url
'
);
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
!
url
||
viewer
.
getAttribute
(
'
data-loaded
'
)
||
viewer
.
getAttribute
(
'
data-loading
'
))
{
if
(
!
url
||
viewer
.
getAttribute
(
'
data-loaded
'
)
||
viewer
.
getAttribute
(
'
data-loading
'
))
{
resolve
(
viewer
);
return
Promise
.
resolve
(
viewer
);
return
;
}
}
viewer
.
setAttribute
(
'
data-loading
'
,
'
true
'
);
viewer
.
setAttribute
(
'
data-loading
'
,
'
true
'
);
$
.
ajax
({
return
axios
.
get
(
url
)
url
,
.
then
(({
data
})
=>
{
dataType
:
'
JSON
'
,
})
.
fail
(
reject
)
.
done
((
data
)
=>
{
viewer
.
innerHTML
=
data
.
html
;
viewer
.
innerHTML
=
data
.
html
;
viewer
.
setAttribute
(
'
data-loaded
'
,
'
true
'
);
viewer
.
setAttribute
(
'
data-loaded
'
,
'
true
'
);
resolve
(
viewer
);
return
viewer
;
});
});
});
}
}
}
}
spec/javascripts/blob/viewer/index_spec.js
View file @
a16cdd0b
/* eslint-disable no-new */
/* eslint-disable no-new */
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
BlobViewer
from
'
~/blob/viewer/index
'
;
import
BlobViewer
from
'
~/blob/viewer/index
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
describe
(
'
Blob viewer
'
,
()
=>
{
describe
(
'
Blob viewer
'
,
()
=>
{
let
blob
;
let
blob
;
let
mock
;
preloadFixtures
(
'
snippets/show.html.raw
'
);
preloadFixtures
(
'
snippets/show.html.raw
'
);
beforeEach
(()
=>
{
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
loadFixtures
(
'
snippets/show.html.raw
'
);
loadFixtures
(
'
snippets/show.html.raw
'
);
$
(
'
#modal-upload-blob
'
).
remove
();
$
(
'
#modal-upload-blob
'
).
remove
();
blob
=
new
BlobViewer
();
blob
=
new
BlobViewer
();
spyOn
(
$
,
'
ajax
'
).
and
.
callFake
(()
=>
{
mock
.
onGet
(
'
http://test.host/snippets/1.json?viewer=rich
'
).
reply
(
200
,
{
const
d
=
$
.
Deferred
();
d
.
resolve
({
html
:
'
<div>testing</div>
'
,
html
:
'
<div>testing</div>
'
,
});
});
return
d
.
promise
();
mock
.
onGet
(
'
http://test.host/snippets/1.json?viewer=simple
'
).
reply
(
200
,
{
html
:
'
<div>testing</div>
'
,
});
});
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
();
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
mock
.
restore
();
location
.
hash
=
''
;
location
.
hash
=
''
;
});
});
...
@@ -30,7 +37,6 @@ describe('Blob viewer', () => {
...
@@ -30,7 +37,6 @@ describe('Blob viewer', () => {
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
setTimeout
(()
=>
{
setTimeout
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
expect
(
expect
(
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
.
classList
.
contains
(
'
hidden
'
),
.
classList
.
contains
(
'
hidden
'
),
...
@@ -46,7 +52,6 @@ describe('Blob viewer', () => {
...
@@ -46,7 +52,6 @@ describe('Blob viewer', () => {
new
BlobViewer
();
new
BlobViewer
();
setTimeout
(()
=>
{
setTimeout
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
expect
(
expect
(
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
)
.
classList
.
contains
(
'
hidden
'
),
.
classList
.
contains
(
'
hidden
'
),
...
@@ -64,12 +69,8 @@ describe('Blob viewer', () => {
...
@@ -64,12 +69,8 @@ describe('Blob viewer', () => {
});
});
asyncClick
()
asyncClick
()
.
then
(()
=>
asyncClick
())
.
then
(()
=>
{
.
then
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
return
asyncClick
();
})
.
then
(()
=>
{
expect
(
$
.
ajax
.
calls
.
count
()).
toBe
(
1
);
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
'
);
...
@@ -122,7 +123,6 @@ describe('Blob viewer', () => {
...
@@ -122,7 +123,6 @@ describe('Blob viewer', () => {
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
setTimeout
(()
=>
{
setTimeout
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
expect
(
expect
(
copyButton
.
classList
.
contains
(
'
disabled
'
),
copyButton
.
classList
.
contains
(
'
disabled
'
),
).
toBeFalsy
();
).
toBeFalsy
();
...
@@ -135,8 +135,6 @@ describe('Blob viewer', () => {
...
@@ -135,8 +135,6 @@ describe('Blob viewer', () => {
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
document
.
querySelector
(
'
.js-blob-viewer-switch-btn[data-viewer="simple"]
'
).
click
();
setTimeout
(()
=>
{
setTimeout
(()
=>
{
expect
(
$
.
ajax
).
toHaveBeenCalled
();
expect
(
expect
(
copyButton
.
getAttribute
(
'
data-original-title
'
),
copyButton
.
getAttribute
(
'
data-original-title
'
),
).
toBe
(
'
Copy source to clipboard
'
);
).
toBe
(
'
Copy source to clipboard
'
);
...
@@ -171,14 +169,14 @@ describe('Blob viewer', () => {
...
@@ -171,14 +169,14 @@ describe('Blob viewer', () => {
it
(
'
sends AJAX request when switching to simple view
'
,
()
=>
{
it
(
'
sends AJAX request when switching to simple view
'
,
()
=>
{
blob
.
switchToViewer
(
'
simple
'
);
blob
.
switchToViewer
(
'
simple
'
);
expect
(
$
.
ajax
).
toHaveBeenCalled
();
expect
(
axios
.
get
).
toHaveBeenCalled
();
});
});
it
(
'
does not send AJAX request when switching to rich view
'
,
()
=>
{
it
(
'
does not send AJAX request when switching to rich view
'
,
()
=>
{
blob
.
switchToViewer
(
'
simple
'
);
blob
.
switchToViewer
(
'
simple
'
);
blob
.
switchToViewer
(
'
rich
'
);
blob
.
switchToViewer
(
'
rich
'
);
expect
(
$
.
ajax
.
calls
.
count
()).
toBe
(
1
);
expect
(
axios
.
get
.
calls
.
count
()).
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