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
ee73ddad
Commit
ee73ddad
authored
Apr 03, 2017
by
Clement Ho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[skip ci] add spec for store
parent
a78ff257
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
158 additions
and
3 deletions
+158
-3
app/assets/javascripts/vue_sidebar_assignees/index.js
app/assets/javascripts/vue_sidebar_assignees/index.js
+6
-1
app/assets/javascripts/vue_sidebar_assignees/stores/sidebar_assignees_store.js
...s/vue_sidebar_assignees/stores/sidebar_assignees_store.js
+4
-2
spec/javascripts/vue_sidebar_assignees/mock_data.js
spec/javascripts/vue_sidebar_assignees/mock_data.js
+3
-0
spec/javascripts/vue_sidebar_assignees/stores/sidebar_assignees_store_spec.js
..._sidebar_assignees/stores/sidebar_assignees_store_spec.js
+145
-0
No files found.
app/assets/javascripts/vue_sidebar_assignees/index.js
View file @
ee73ddad
...
...
@@ -25,7 +25,12 @@ const sidebarAssigneesOptions = () => ({
const
currentUserId
=
parseInt
(
element
.
dataset
.
userId
,
10
);
const
service
=
new
SidebarAssigneesService
(
path
,
field
);
const
store
=
new
SidebarAssigneesStore
(
currentUserId
,
service
,
rootPath
,
editable
);
const
store
=
new
SidebarAssigneesStore
({
currentUserId
,
service
,
rootPath
,
editable
,
});
return
{
store
,
...
...
app/assets/javascripts/vue_sidebar_assignees/stores/sidebar_assignees_store.js
View file @
ee73ddad
...
...
@@ -2,7 +2,9 @@
import
'
~/flash
'
;
export
default
class
SidebarAssigneesStore
{
constructor
(
currentUserId
,
service
,
rootPath
,
editable
)
{
constructor
(
store
)
{
const
{
currentUserId
,
service
,
rootPath
,
editable
}
=
store
;
this
.
currentUserId
=
currentUserId
;
this
.
service
=
service
;
this
.
rootPath
=
rootPath
;
...
...
@@ -42,7 +44,7 @@ export default class SidebarAssigneesStore {
saveUsers
()
{
const
ids
=
this
.
users
.
map
(
u
=>
u
.
id
);
// If there are no ids, that means we have to unassign (which is id = 0)
const
payload
=
ids
.
length
>
0
?
ids
:
0
;
const
payload
=
ids
.
length
>
0
?
ids
:
[
0
]
;
this
.
loading
=
true
;
this
.
service
.
update
(
payload
)
...
...
spec/javascripts/vue_sidebar_assignees/mock_data.js
View file @
ee73ddad
const
mockUser
=
{
id
:
1
,
name
:
'
Clark Kent
'
,
username
:
'
superman
'
,
avatarUrl
:
'
https://superman.com/avatar.png
'
,
};
const
mockUser2
=
{
id
:
2
,
name
:
'
Bruce Wayne
'
,
username
:
'
batman
'
,
avatarUrl
:
'
https://batman.com/avatar.png
'
,
};
const
mockUser3
=
{
id
:
3
,
name
:
'
Tony Stark
'
,
username
:
'
ironman
'
,
avatarUrl
:
'
https://ironman.com/avatar.png
'
,
...
...
spec/javascripts/vue_sidebar_assignees/stores/sidebar_assignees_store_spec.js
0 → 100644
View file @
ee73ddad
import
'
~/flash
'
;
import
SidebarAssigneesStore
from
'
~/vue_sidebar_assignees/stores/sidebar_assignees_store
'
;
import
{
mockUser
}
from
'
../mock_data
'
;
describe
(
'
SidebarAssigneesStore
'
,
()
=>
{
let
params
;
beforeEach
(()
=>
{
params
=
{
currentUserId
:
1
,
service
:
{
update
:
()
=>
{},
},
rootPath
:
'
rootPath
'
,
editable
:
true
,
};
});
const
getStore
=
p
=>
new
SidebarAssigneesStore
(
p
);
it
(
'
should store information
'
,
()
=>
{
const
store
=
getStore
(
params
);
Object
.
keys
(
params
).
forEach
((
k
)
=>
{
expect
(
store
[
k
]).
toEqual
(
params
[
k
]);
});
});
describe
(
'
addUser
'
,
()
=>
{
let
store
;
beforeEach
(()
=>
{
store
=
getStore
(
params
);
});
it
(
'
should add user to users array
'
,
()
=>
{
expect
(
store
.
users
.
length
).
toEqual
(
0
);
store
.
addUser
(
mockUser
);
expect
(
store
.
users
.
length
).
toEqual
(
1
);
expect
(
store
.
users
[
0
]).
toEqual
(
mockUser
);
expect
(
store
.
saved
).
toEqual
(
false
);
});
it
(
'
should set saved flag to true if second param is true
'
,
()
=>
{
store
.
addUser
(
mockUser
,
true
);
expect
(
store
.
saved
).
toEqual
(
true
);
});
});
describe
(
'
addCurrentUser
'
,
()
=>
{
let
store
;
beforeEach
(()
=>
{
store
=
getStore
(
params
);
spyOn
(
store
,
'
saveUsers
'
).
and
.
callFake
(()
=>
{});
});
it
(
'
should add current user to users array
'
,
()
=>
{
spyOn
(
store
,
'
addUser
'
).
and
.
callThrough
();
store
.
addCurrentUser
();
expect
(
store
.
addUser
).
toHaveBeenCalledWith
({
id
:
1
,
});
});
it
(
'
should call saveUsers
'
,
()
=>
{
store
.
addCurrentUser
();
expect
(
store
.
saveUsers
).
toHaveBeenCalled
();
});
});
describe
(
'
removeUser
'
,
()
=>
{
let
store
;
beforeEach
(()
=>
{
store
=
getStore
(
params
);
store
.
addUser
(
mockUser
,
true
);
});
it
(
'
should remove user from users array
'
,
()
=>
{
expect
(
store
.
users
.
length
).
toEqual
(
1
);
store
.
removeUser
(
mockUser
.
id
);
expect
(
store
.
users
.
length
).
toEqual
(
0
);
});
it
(
'
should set saved flag to false
'
,
()
=>
{
expect
(
store
.
saved
).
toEqual
(
true
);
store
.
removeUser
(
mockUser
.
id
);
expect
(
store
.
saved
).
toEqual
(
false
);
});
});
describe
(
'
saveUsers
'
,
()
=>
{
it
(
'
should save unassigned user when there are no users2
'
,
()
=>
{
const
spyParams
=
Object
.
assign
({},
params
);
const
store
=
getStore
(
spyParams
);
spyOn
(
spyParams
.
service
,
'
update
'
).
and
.
callFake
(()
=>
new
Promise
(
resolve
=>
resolve
({
data
:
{
assignees
:
[],
},
}),
),
);
store
.
saveUsers
();
expect
(
spyParams
.
service
.
update
).
toHaveBeenCalledWith
([
0
]);
expect
(
store
.
users
.
length
).
toEqual
(
0
);
});
it
(
'
should catch error
'
,
()
=>
{
const
spyParams
=
Object
.
assign
({},
params
);
const
store
=
getStore
(
spyParams
);
spyOn
(
window
,
'
Flash
'
).
and
.
callThrough
();
spyOn
(
spyParams
.
service
,
'
update
'
).
and
.
callFake
(()
=>
new
Promise
((
resolve
,
reject
)
=>
reject
()),
);
store
.
saveUsers
();
setTimeout
(()
=>
{
expect
(
window
.
Flash
).
toHaveBeenCalled
();
});
});
it
(
'
should save unassigned user when there are no users
'
,
()
=>
{
const
spyParams
=
Object
.
assign
({},
params
);
const
store
=
getStore
(
spyParams
);
spyOn
(
spyParams
.
service
,
'
update
'
).
and
.
callFake
(()
=>
new
Promise
(
resolve
=>
resolve
({
data
:
{
assignees
:
[],
},
}),
),
);
store
.
saveUsers
();
expect
(
spyParams
.
service
.
update
).
toHaveBeenCalledWith
([
0
]);
expect
(
store
.
users
.
length
).
toEqual
(
0
);
});
});
});
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