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
37f8036a
Commit
37f8036a
authored
Feb 02, 2022
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab master
parents
81653ac9
0e8f4ae8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
11 deletions
+68
-11
app/assets/images/auth_buttons/atlassian_64.png
app/assets/images/auth_buttons/atlassian_64.png
+0
-0
app/assets/images/auth_buttons/facebook_64.png
app/assets/images/auth_buttons/facebook_64.png
+0
-0
app/assets/javascripts/emoji/awards_app/store/actions.js
app/assets/javascripts/emoji/awards_app/store/actions.js
+36
-5
spec/features/merge_request/user_awards_emoji_spec.rb
spec/features/merge_request/user_awards_emoji_spec.rb
+1
-0
spec/frontend/emoji/awards_app/store/actions_spec.js
spec/frontend/emoji/awards_app/store/actions_spec.js
+31
-6
No files found.
app/assets/images/auth_buttons/atlassian_64.png
View replaced file @
81653ac9
View file @
37f8036a
1.48 KB
|
W:
|
H:
1.33 KB
|
W:
|
H:
2-up
Swipe
Onion skin
app/assets/images/auth_buttons/facebook_64.png
View replaced file @
81653ac9
View file @
37f8036a
870 Bytes
|
W:
|
H:
1.01 KB
|
W:
|
H:
2-up
Swipe
Onion skin
app/assets/javascripts/emoji/awards_app/store/actions.js
View file @
37f8036a
...
...
@@ -33,20 +33,51 @@ export const fetchAwards = async ({ commit, dispatch, state }, page = '1') => {
}
};
/**
* Creates an intermediary award, used for display
* until the real award is loaded from the backend.
*/
const
newOptimisticAward
=
(
name
,
state
)
=>
{
const
freeId
=
Math
.
min
(...
state
.
awards
.
map
((
a
)
=>
a
.
id
),
Number
.
MAX_SAFE_INTEGER
)
-
1
;
return
{
id
:
freeId
,
name
,
user
:
{
id
:
window
.
gon
.
current_user_id
,
name
:
window
.
gon
.
current_user_fullname
,
username
:
window
.
gon
.
current_username
,
},
};
};
export
const
toggleAward
=
async
({
commit
,
state
},
name
)
=>
{
const
award
=
state
.
awards
.
find
((
a
)
=>
a
.
name
===
name
&&
a
.
user
.
id
===
state
.
currentUserId
);
try
{
if
(
award
)
{
await
axios
.
delete
(
joinPaths
(
gon
.
relative_url_root
||
''
,
`
${
state
.
path
}
/
${
award
.
id
}
`
));
commit
(
REMOVE_AWARD
,
award
.
id
);
await
axios
.
delete
(
joinPaths
(
gon
.
relative_url_root
||
''
,
`
${
state
.
path
}
/
${
award
.
id
}
`
))
.
catch
((
err
)
=>
{
commit
(
ADD_NEW_AWARD
,
award
);
throw
err
;
});
showToast
(
__
(
'
Award removed
'
));
}
else
{
const
{
data
}
=
await
axios
.
post
(
joinPaths
(
gon
.
relative_url_root
||
''
,
state
.
path
),
{
name
,
});
const
optimisticAward
=
newOptimisticAward
(
name
,
state
);
commit
(
ADD_NEW_AWARD
,
optimisticAward
);
const
{
data
}
=
await
axios
.
post
(
joinPaths
(
gon
.
relative_url_root
||
''
,
state
.
path
),
{
name
,
})
.
finally
(()
=>
{
commit
(
REMOVE_AWARD
,
optimisticAward
.
id
);
});
commit
(
ADD_NEW_AWARD
,
data
);
...
...
spec/features/merge_request/user_awards_emoji_spec.rb
View file @
37f8036a
...
...
@@ -27,6 +27,7 @@ RSpec.describe 'Merge request > User awards emoji', :js do
it
'removes award from merge request'
do
first
(
'[data-testid="award-button"]'
).
click
expect
(
first
(
'[data-testid="award-button"]'
)).
to
have_content
'1'
find
(
'[data-testid="award-button"].selected'
).
click
expect
(
first
(
'[data-testid="award-button"]'
)).
to
have_content
'0'
...
...
spec/frontend/emoji/awards_app/store/actions_spec.js
View file @
37f8036a
...
...
@@ -87,6 +87,26 @@ describe('Awards app actions', () => {
describe
(
'
toggleAward
'
,
()
=>
{
let
mock
;
const
optimisticAwardId
=
Number
.
MAX_SAFE_INTEGER
-
1
;
const
makeOptimisticAddMutation
=
(
id
=
optimisticAwardId
,
name
=
null
,
userId
=
window
.
gon
.
current_user_id
,
)
=>
({
type
:
'
ADD_NEW_AWARD
'
,
payload
:
{
id
,
name
,
user
:
{
id
:
userId
,
},
},
});
const
makeOptimisticRemoveMutation
=
(
id
=
optimisticAwardId
)
=>
({
type
:
'
REMOVE_AWARD
'
,
payload
:
id
,
});
beforeEach
(()
=>
{
mock
=
new
MockAdapter
(
axios
);
});
...
...
@@ -110,8 +130,10 @@ describe('Awards app actions', () => {
mock
.
onPost
(
`
${
relativeRootUrl
||
''
}
/awards`
).
reply
(
200
,
{
id
:
1
});
});
it
(
'
commits ADD_NEW_AWARD
'
,
async
()
=>
{
it
(
'
adds an optimistic award, removes it, and then
commits ADD_NEW_AWARD
'
,
async
()
=>
{
testAction
(
actions
.
toggleAward
,
null
,
{
path
:
'
/awards
'
,
awards
:
[]
},
[
makeOptimisticAddMutation
(),
makeOptimisticRemoveMutation
(),
{
type
:
'
ADD_NEW_AWARD
'
,
payload
:
{
id
:
1
}
},
]);
});
...
...
@@ -127,7 +149,7 @@ describe('Awards app actions', () => {
actions
.
toggleAward
,
null
,
{
path
:
'
/awards
'
,
awards
:
[]
},
[],
[
makeOptimisticAddMutation
(),
makeOptimisticRemoveMutation
()
],
[],
()
=>
{
expect
(
Sentry
.
captureException
).
toHaveBeenCalled
();
...
...
@@ -137,7 +159,7 @@ describe('Awards app actions', () => {
});
});
describe
(
'
removing a award
'
,
()
=>
{
describe
(
'
removing a
n
award
'
,
()
=>
{
const
mockData
=
{
id
:
1
,
name
:
'
thumbsup
'
,
user
:
{
id
:
1
}
};
describe
(
'
success
'
,
()
=>
{
...
...
@@ -160,6 +182,9 @@ describe('Awards app actions', () => {
});
describe
(
'
error
'
,
()
=>
{
const
currentUserId
=
1
;
const
name
=
'
thumbsup
'
;
beforeEach
(()
=>
{
mock
.
onDelete
(
`
${
relativeRootUrl
||
''
}
/awards/1`
).
reply
(
500
);
});
...
...
@@ -167,13 +192,13 @@ describe('Awards app actions', () => {
it
(
'
calls Sentry.captureException
'
,
async
()
=>
{
await
testAction
(
actions
.
toggleAward
,
'
thumbsup
'
,
name
,
{
path
:
'
/awards
'
,
currentUserId
:
1
,
currentUserId
,
awards
:
[
mockData
],
},
[],
[
makeOptimisticRemoveMutation
(
1
),
makeOptimisticAddMutation
(
1
,
name
,
currentUserId
)
],
[],
()
=>
{
expect
(
Sentry
.
captureException
).
toHaveBeenCalled
();
...
...
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