diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/frontend/work_items/components/work_item_assignees_spec.js | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/frontend/work_items/components/work_item_assignees_spec.js')
-rw-r--r-- | spec/frontend/work_items/components/work_item_assignees_spec.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/frontend/work_items/components/work_item_assignees_spec.js b/spec/frontend/work_items/components/work_item_assignees_spec.js new file mode 100644 index 00000000000..0552fe5050e --- /dev/null +++ b/spec/frontend/work_items/components/work_item_assignees_spec.js @@ -0,0 +1,93 @@ +import { GlLink, GlTokenSelector } from '@gitlab/ui'; +import { nextTick } from 'vue'; +import { mountExtended } from 'helpers/vue_test_utils_helper'; +import WorkItemAssignees from '~/work_items/components/work_item_assignees.vue'; +import localUpdateWorkItemMutation from '~/work_items/graphql/local_update_work_item.mutation.graphql'; + +const mockAssignees = [ + { + __typename: 'UserCore', + id: 'gid://gitlab/User/1', + avatarUrl: '', + webUrl: '', + name: 'John Doe', + username: 'doe_I', + }, + { + __typename: 'UserCore', + id: 'gid://gitlab/User/2', + avatarUrl: '', + webUrl: '', + name: 'Marcus Rutherford', + username: 'ruthfull', + }, +]; + +const workItemId = 'gid://gitlab/WorkItem/1'; + +const mutate = jest.fn(); + +describe('WorkItemAssignees component', () => { + let wrapper; + + const findAssigneeLinks = () => wrapper.findAllComponents(GlLink); + const findTokenSelector = () => wrapper.findComponent(GlTokenSelector); + + const findEmptyState = () => wrapper.findByTestId('empty-state'); + + const createComponent = ({ assignees = mockAssignees } = {}) => { + wrapper = mountExtended(WorkItemAssignees, { + propsData: { + assignees, + workItemId, + }, + mocks: { + $apollo: { + mutate, + }, + }, + attachTo: document.body, + }); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + it('should pass the correct data-user-id attribute', () => { + createComponent(); + + expect(findAssigneeLinks().at(0).attributes('data-user-id')).toBe('1'); + }); + + describe('when there are assignees', () => { + beforeEach(() => { + createComponent(); + }); + + it('should focus token selector on token removal', async () => { + findTokenSelector().vm.$emit('token-remove', mockAssignees[0].id); + await nextTick(); + + expect(findEmptyState().exists()).toBe(false); + expect(findTokenSelector().element.contains(document.activeElement)).toBe(true); + }); + + it('should call a mutation on clicking outside the token selector', async () => { + findTokenSelector().vm.$emit('input', [mockAssignees[0]]); + findTokenSelector().vm.$emit('token-remove'); + await nextTick(); + expect(mutate).not.toHaveBeenCalled(); + + findTokenSelector().vm.$emit('blur', new FocusEvent({ relatedTarget: null })); + await nextTick(); + + expect(mutate).toHaveBeenCalledWith({ + mutation: localUpdateWorkItemMutation, + variables: { + input: { id: workItemId, assigneeIds: [mockAssignees[0].id] }, + }, + }); + }); + }); +}); |