diff options
Diffstat (limited to 'spec/frontend/sidebar/components/assignees/assignee_avatar_link_spec.js')
-rw-r--r-- | spec/frontend/sidebar/components/assignees/assignee_avatar_link_spec.js | 96 |
1 files changed, 17 insertions, 79 deletions
diff --git a/spec/frontend/sidebar/components/assignees/assignee_avatar_link_spec.js b/spec/frontend/sidebar/components/assignees/assignee_avatar_link_spec.js index 81b65f4f050..52355806487 100644 --- a/spec/frontend/sidebar/components/assignees/assignee_avatar_link_spec.js +++ b/spec/frontend/sidebar/components/assignees/assignee_avatar_link_spec.js @@ -1,15 +1,12 @@ import { shallowMount } from '@vue/test-utils'; import { GlLink } from '@gitlab/ui'; -import { TEST_HOST } from 'helpers/test_constants'; import { TYPENAME_USER } from '~/graphql_shared/constants'; import { convertToGraphQLId } from '~/graphql_shared/utils'; import AssigneeAvatar from '~/sidebar/components/assignees/assignee_avatar.vue'; import AssigneeAvatarLink from '~/sidebar/components/assignees/assignee_avatar_link.vue'; import userDataMock from '../../user_data_mock'; -const TOOLTIP_PLACEMENT = 'bottom'; -const { name: USER_NAME } = userDataMock(); -const TEST_ISSUABLE_TYPE = 'merge_request'; +const TEST_ISSUABLE_TYPE = 'issue'; describe('AssigneeAvatarLink component', () => { let wrapper; @@ -17,10 +14,6 @@ describe('AssigneeAvatarLink component', () => { function createComponent(props = {}) { const propsData = { user: userDataMock(), - showLess: true, - rootPath: TEST_HOST, - tooltipPlacement: TOOLTIP_PLACEMENT, - singleUser: false, issuableType: TEST_ISSUABLE_TYPE, ...props, }; @@ -30,7 +23,6 @@ describe('AssigneeAvatarLink component', () => { }); } - const findTooltipText = () => wrapper.attributes('title'); const findUserLink = () => wrapper.findComponent(GlLink); it('has the root url present in the assigneeUrl method', () => { @@ -50,69 +42,6 @@ describe('AssigneeAvatarLink component', () => { ); }); - describe.each` - issuableType | tooltipHasName | canMerge | expected - ${'merge_request'} | ${true} | ${true} | ${USER_NAME} - ${'merge_request'} | ${true} | ${false} | ${`${USER_NAME} (cannot merge)`} - ${'merge_request'} | ${false} | ${true} | ${''} - ${'merge_request'} | ${false} | ${false} | ${'Cannot merge'} - ${'issue'} | ${true} | ${true} | ${USER_NAME} - ${'issue'} | ${true} | ${false} | ${USER_NAME} - ${'issue'} | ${false} | ${true} | ${''} - ${'issue'} | ${false} | ${false} | ${''} - `( - 'with $issuableType and tooltipHasName=$tooltipHasName and canMerge=$canMerge', - ({ issuableType, tooltipHasName, canMerge, expected }) => { - beforeEach(() => { - createComponent({ - issuableType, - tooltipHasName, - user: { - ...userDataMock(), - can_merge: canMerge, - }, - }); - }); - - it('sets tooltip', () => { - expect(findTooltipText()).toBe(expected); - }); - }, - ); - - describe.each` - tooltipHasName | name | availability | canMerge | expected - ${true} | ${"Rabbit O'Hare"} | ${''} | ${true} | ${"Rabbit O'Hare"} - ${true} | ${"Rabbit O'Hare"} | ${'Busy'} | ${false} | ${"Rabbit O'Hare (Busy) (cannot merge)"} - ${true} | ${'Root'} | ${'Busy'} | ${false} | ${'Root (Busy) (cannot merge)'} - ${true} | ${'Root'} | ${'Busy'} | ${true} | ${'Root (Busy)'} - ${true} | ${'Root'} | ${''} | ${false} | ${'Root (cannot merge)'} - ${true} | ${'Root'} | ${''} | ${true} | ${'Root'} - ${false} | ${'Root'} | ${'Busy'} | ${false} | ${'Cannot merge'} - ${false} | ${'Root'} | ${'Busy'} | ${true} | ${''} - ${false} | ${'Root'} | ${''} | ${false} | ${'Cannot merge'} - ${false} | ${'Root'} | ${''} | ${true} | ${''} - `( - "with name=$name tooltipHasName=$tooltipHasName and availability='$availability' and canMerge=$canMerge", - ({ name, tooltipHasName, availability, canMerge, expected }) => { - beforeEach(() => { - createComponent({ - tooltipHasName, - user: { - ...userDataMock(), - name, - can_merge: canMerge, - availability, - }, - }); - }); - - it(`sets tooltip to "${expected}"`, () => { - expect(findTooltipText()).toBe(expected); - }); - }, - ); - it('passes the correct user id for REST API', () => { createComponent({ tooltipHasName: true, @@ -135,15 +64,24 @@ describe('AssigneeAvatarLink component', () => { expect(findUserLink().attributes('data-user-id')).toBe(String(userId)); }); - it.each` - issuableType | userId - ${'merge_request'} | ${undefined} - ${'issue'} | ${'1'} - `('sets data-user-id as $userId for $issuableType', ({ issuableType, userId }) => { + it('passes the correct username, cannotMerge, and CSS class for popover support', () => { + const moctUserData = userDataMock(); + const { id, username } = moctUserData; + createComponent({ - issuableType, + tooltipHasName: true, + issuableType: 'merge_request', + user: { ...moctUserData, can_merge: false }, }); - expect(findUserLink().attributes('data-user-id')).toBe(userId); + const userLink = findUserLink(); + + expect(userLink.attributes()).toMatchObject({ + 'data-user-id': `${id}`, + 'data-username': username, + 'data-cannot-merge': 'true', + 'data-placement': 'left', + }); + expect(userLink.classes()).toContain('js-user-link'); }); }); |