diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-23 21:08:27 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-23 21:08:27 +0300 |
commit | 3ca896b640def57a58485def308748b2fccbd0bb (patch) | |
tree | 7aead6484759d2a473bf9776aa7d87632f1e105f /spec/frontend/work_items | |
parent | abdb550f6937ce69ec38954f24ef221d07637438 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/work_items')
-rw-r--r-- | spec/frontend/work_items/components/work_item_award_emoji_spec.js | 89 | ||||
-rw-r--r-- | spec/frontend/work_items/mock_data.js | 2 |
2 files changed, 89 insertions, 2 deletions
diff --git a/spec/frontend/work_items/components/work_item_award_emoji_spec.js b/spec/frontend/work_items/components/work_item_award_emoji_spec.js index f87c0e3f357..6abb941a834 100644 --- a/spec/frontend/work_items/components/work_item_award_emoji_spec.js +++ b/spec/frontend/work_items/components/work_item_award_emoji_spec.js @@ -53,6 +53,15 @@ describe('WorkItemAwardEmoji component', () => { ); const workItemUpdateFailureHandler = jest.fn().mockRejectedValue(new Error(errorMessage)); const mockWorkItem = workItemQueryResponse.data.workspace.workItems.nodes[0]; + const mockAwardEmojiDifferentUserThumbsUp = { + name: 'thumbsup', + __typename: 'AwardEmoji', + user: { + id: 'gid://gitlab/User/1', + name: 'John Doe', + __typename: 'UserCore', + }, + }; const createComponent = ({ mockWorkItemUpdateMutationHandler = [updateWorkItemMutation, workItemSuccessHandler], @@ -74,7 +83,8 @@ describe('WorkItemAwardEmoji component', () => { beforeEach(() => { isLoggedIn.mockReturnValue(true); window.gon = { - current_user_id: 1, + current_user_id: 5, + current_user_fullname: 'Dave Smith', }; createComponent(); @@ -85,7 +95,7 @@ describe('WorkItemAwardEmoji component', () => { expect(findAwardsList().props()).toEqual({ boundary: '', canAwardEmoji: true, - currentUserId: 1, + currentUserId: 5, defaultAwards: [EMOJI_THUMBSUP, EMOJI_THUMBSDOWN], selectedClass: 'selected', awards: [], @@ -101,6 +111,7 @@ describe('WorkItemAwardEmoji component', () => { name: EMOJI_THUMBSUP, user: { id: 5, + name: 'Dave Smith', }, }, { @@ -108,6 +119,35 @@ describe('WorkItemAwardEmoji component', () => { name: EMOJI_THUMBSDOWN, user: { id: 5, + name: 'Dave Smith', + }, + }, + ]); + }); + + it('renders awards list given by multiple users', () => { + createComponent({ + awardEmoji: { + ...mockAwardsWidget, + nodes: [mockAwardEmojiThumbsUp, mockAwardEmojiDifferentUserThumbsUp], + }, + }); + + expect(findAwardsList().props('awards')).toEqual([ + { + id: 1, + name: EMOJI_THUMBSUP, + user: { + id: 5, + name: 'Dave Smith', + }, + }, + { + id: 2, + name: EMOJI_THUMBSUP, + user: { + id: 1, + name: 'John Doe', }, }, ]); @@ -167,4 +207,49 @@ describe('WorkItemAwardEmoji component', () => { expect(findAwardsList().props('canAwardEmoji')).toBe(false); }); }); + + describe('when a different users awards same emoji', () => { + const awardEmojiDifferentUserSuccessHandler = jest.fn().mockResolvedValue( + updateWorkItemMutationResponseFactory({ + awardEmoji: { + ...mockAwardsWidget, + nodes: [mockAwardEmojiThumbsUp, mockAwardEmojiDifferentUserThumbsUp], + }, + }), + ); + + beforeEach(() => { + window.gon = { + current_user_id: 1, + current_user_fullname: 'John Doe', + }; + }); + + it('calls mutation succesfully', async () => { + createComponent({ + mockWorkItemUpdateMutationHandler: [ + updateWorkItemMutation, + awardEmojiDifferentUserSuccessHandler, + ], + awardEmoji: { + ...mockAwardsWidget, + nodes: [mockAwardEmojiThumbsUp], + }, + }); + + findAwardsList().vm.$emit('award', EMOJI_THUMBSUP); + + await waitForPromises(); + + expect(awardEmojiDifferentUserSuccessHandler).toHaveBeenCalledWith({ + input: { + id: mockWorkItem.id, + awardEmojiWidget: { + action: EMOJI_ACTION_ADD, + name: EMOJI_THUMBSUP, + }, + }, + }); + }); + }); }); diff --git a/spec/frontend/work_items/mock_data.js b/spec/frontend/work_items/mock_data.js index fd31074378b..96c14ef4dd1 100644 --- a/spec/frontend/work_items/mock_data.js +++ b/spec/frontend/work_items/mock_data.js @@ -51,6 +51,7 @@ export const mockAwardEmojiThumbsUp = { __typename: 'AwardEmoji', user: { id: 'gid://gitlab/User/5', + name: 'Dave Smith', __typename: 'UserCore', }, }; @@ -60,6 +61,7 @@ export const mockAwardEmojiThumbsDown = { __typename: 'AwardEmoji', user: { id: 'gid://gitlab/User/5', + name: 'Dave Smith', __typename: 'UserCore', }, }; |