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
Léo-Paul Géneau
gitlab-ce
Commits
015e15f4
Commit
015e15f4
authored
Feb 02, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Converted right_sidebar.js to use axios
parent
deaf6aee
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
29 deletions
+24
-29
app/assets/javascripts/right_sidebar.js
app/assets/javascripts/right_sidebar.js
+11
-20
spec/javascripts/right_sidebar_spec.js
spec/javascripts/right_sidebar_spec.js
+13
-9
No files found.
app/assets/javascripts/right_sidebar.js
View file @
015e15f4
...
...
@@ -2,6 +2,8 @@
import
_
from
'
underscore
'
;
import
Cookies
from
'
js-cookie
'
;
import
flash
from
'
./flash
'
;
import
axios
from
'
./lib/utils/axios_utils
'
;
function
Sidebar
(
currentUser
)
{
this
.
toggleTodo
=
this
.
toggleTodo
.
bind
(
this
);
...
...
@@ -62,7 +64,7 @@ Sidebar.prototype.sidebarToggleClicked = function (e, triggered) {
Sidebar
.
prototype
.
toggleTodo
=
function
(
e
)
{
var
$btnText
,
$this
,
$todoLoading
,
ajaxType
,
url
;
$this
=
$
(
e
.
currentTarget
);
ajaxType
=
$this
.
attr
(
'
data-delete-path
'
)
?
'
DELETE
'
:
'
POST
'
;
ajaxType
=
$this
.
attr
(
'
data-delete-path
'
)
?
'
delete
'
:
'
post
'
;
if
(
$this
.
attr
(
'
data-delete-path
'
))
{
url
=
""
+
(
$this
.
attr
(
'
data-delete-path
'
));
}
else
{
...
...
@@ -71,25 +73,14 @@ Sidebar.prototype.toggleTodo = function(e) {
$this
.
tooltip
(
'
hide
'
);
return
$
.
ajax
({
url
:
url
,
type
:
ajaxType
,
dataType
:
'
json
'
,
data
:
{
issuable_id
:
$this
.
data
(
'
issuable-id
'
),
issuable_type
:
$this
.
data
(
'
issuable-type
'
)
},
beforeSend
:
(
function
(
_this
)
{
return
function
()
{
$
(
'
.js-issuable-todo
'
).
disable
()
.
addClass
(
'
is-loading
'
);
};
})(
this
)
}).
done
((
function
(
_this
)
{
return
function
(
data
)
{
return
_this
.
todoUpdateDone
(
data
);
};
})(
this
));
$
(
'
.js-issuable-todo
'
).
disable
().
addClass
(
'
is-loading
'
);
return
axios
[
ajaxType
](
url
,
{
issuable_id
:
$this
.
data
(
'
issuable-id
'
),
issuable_type
:
$this
.
data
(
'
issuable-type
'
),
}).
then
(({
data
})
=>
{
this
.
todoUpdateDone
(
data
);
});
};
Sidebar
.
prototype
.
todoUpdateDone
=
function
(
data
)
{
...
...
spec/javascripts/right_sidebar_spec.js
View file @
015e15f4
/* eslint-disable space-before-function-paren, no-var, one-var, one-var-declaration-per-line, new-parens, no-return-assign, new-cap, vars-on-top, max-len */
import
MockAdapter
from
'
axios-mock-adapter
'
;
import
'
~/commons/bootstrap
'
;
import
axios
from
'
~/lib/utils/axios_utils
'
;
import
Sidebar
from
'
~/right_sidebar
'
;
(
function
()
{
...
...
@@ -35,10 +37,12 @@ import Sidebar from '~/right_sidebar';
var
fixtureName
=
'
issues/open-issue.html.raw
'
;
preloadFixtures
(
fixtureName
);
loadJSONFixtures
(
'
todos/todos.json
'
);
let
mock
;
beforeEach
(
function
()
{
loadFixtures
(
fixtureName
);
this
.
sidebar
=
new
Sidebar
;
mock
=
new
MockAdapter
(
axios
);
this
.
sidebar
=
new
Sidebar
();
$aside
=
$
(
'
.right-sidebar
'
);
$page
=
$
(
'
.layout-page
'
);
$icon
=
$aside
.
find
(
'
i
'
);
...
...
@@ -63,20 +67,20 @@ import Sidebar from '~/right_sidebar';
return
assertSidebarState
(
'
collapsed
'
);
});
it
(
'
should broadcast todo:toggle event when add todo clicked
'
,
function
()
{
it
(
'
should broadcast todo:toggle event when add todo clicked
'
,
function
(
done
)
{
var
todos
=
getJSONFixture
(
'
todos/todos.json
'
);
spyOn
(
jQuery
,
'
ajax
'
).
and
.
callFake
(
function
()
{
var
d
=
$
.
Deferred
();
var
response
=
todos
;
d
.
resolve
(
response
);
return
d
.
promise
();
});
spyOn
(
axios
,
'
get
'
).
and
.
callThrough
();
mock
.
onAny
(
`
${
gl
.
TEST_HOST
}
/frontend-fixtures/issues-project/todos`
).
reply
(
200
,
todos
);
var
todoToggleSpy
=
spyOnEvent
(
document
,
'
todo:toggle
'
);
$
(
'
.issuable-sidebar-header .js-issuable-todo
'
).
click
();
expect
(
todoToggleSpy
.
calls
.
count
()).
toEqual
(
1
);
setTimeout
(()
=>
{
expect
(
todoToggleSpy
.
calls
.
count
()).
toEqual
(
1
);
done
();
});
});
it
(
'
should not hide collapsed icons
'
,
()
=>
{
...
...
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