Commit ae638fcc authored by Mark Florian's avatar Mark Florian

Merge branch '55650-add-default-emojis-to-awards-list' into 'master'

Add defaultAwards props to awards_list awards

Closes #55650

See merge request gitlab-org/gitlab!29813
parents 4865b421 ef41204d
......@@ -34,10 +34,21 @@ export default {
required: false,
default: '',
},
defaultAwards: {
type: Array,
required: false,
default: () => [],
},
},
computed: {
groupedDefaultAwards() {
return this.defaultAwards.reduce((obj, key) => Object.assign(obj, { [key]: [] }), {});
},
groupedAwards() {
const { thumbsup, thumbsdown, ...rest } = groupBy(this.awards, x => x.name);
const { thumbsup, thumbsdown, ...rest } = {
...this.groupedDefaultAwards,
...groupBy(this.awards, x => x.name),
};
return [
...(thumbsup ? [this.createAwardList('thumbsup', thumbsup)] : []),
......@@ -73,6 +84,10 @@ export default {
};
},
getAwardListTitle(awardsList) {
if (!awardsList.length) {
return '';
}
const hasReactionByCurrentUser = this.hasReactionByCurrentUser(awardsList);
const TOOLTIP_NAME_COUNT = hasReactionByCurrentUser ? 9 : 10;
let awardList = awardsList;
......
......@@ -210,4 +210,46 @@ describe('vue_shared/components/awards_list', () => {
expect(buttons.wrappers.every(x => x.classes('disabled'))).toBe(true);
});
});
describe('with default awards', () => {
beforeEach(() => {
createComponent({
awards: [createAward(EMOJI_SMILE, USERS.marie), createAward(EMOJI_100, USERS.marie)],
canAwardEmoji: true,
currentUserId: USERS.root.id,
// Let's assert that it puts thumbsup and thumbsdown in the right order still
defaultAwards: [EMOJI_THUMBSDOWN, EMOJI_100, EMOJI_THUMBSUP],
});
});
it('shows awards in correct order', () => {
expect(findAwardsData()).toEqual([
{
classes: ['btn', 'award-control'],
count: 0,
html: matchingEmojiTag(EMOJI_THUMBSUP),
title: '',
},
{
classes: ['btn', 'award-control'],
count: 0,
html: matchingEmojiTag(EMOJI_THUMBSDOWN),
title: '',
},
// We expect the EMOJI_100 before the EMOJI_SMILE because it was given as a defaultAward
{
classes: ['btn', 'award-control'],
count: 1,
html: matchingEmojiTag(EMOJI_100),
title: 'Marie',
},
{
classes: ['btn', 'award-control'],
count: 1,
html: matchingEmojiTag(EMOJI_SMILE),
title: 'Marie',
},
]);
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment