Commit 3e390725 authored by Diana Zubova's avatar Diana Zubova Committed by Paul Slaughter

Migrate UserAvatarLink to standard avatar

Use Pajamas components instead
Refactor related test
https://gitlab.com/gitlab-org/gitlab/-/merge_requests/84087
parent d008ab74
<script> <script>
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue'; import { GlAvatarLink, GlAvatar, GlTooltipDirective } from '@gitlab/ui';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin'; import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
export default { export default {
components: { components: {
UserAvatarLink, GlAvatarLink,
GlAvatar,
},
directives: {
GlTooltip: GlTooltipDirective,
}, },
mixins: [glFeatureFlagMixin()], mixins: [glFeatureFlagMixin()],
props: { props: {
...@@ -22,15 +26,11 @@ export default { ...@@ -22,15 +26,11 @@ export default {
</script> </script>
<template> <template>
<div class="pipeline-triggerer" data-testid="pipeline-triggerer"> <div class="pipeline-triggerer" data-testid="pipeline-triggerer">
<user-avatar-link <gl-avatar-link v-if="user" v-gl-tooltip :href="user.path" :title="user.name" class="gl-ml-3">
v-if="user" <gl-avatar :size="32" :src="user.avatar_url" />
:link-href="user.path" </gl-avatar-link>
:img-src="user.avatar_url"
:img-size="32" <span v-else class="gl-ml-3">
:tooltip-text="user.name"
class="gl-ml-3 js-pipeline-url-user"
/>
<span v-else class="gl-ml-3 js-pipeline-url-api api">
{{ s__('Pipelines|API') }} {{ s__('Pipelines|API') }}
</span> </span>
</div> </div>
......
import { shallowMount } from '@vue/test-utils'; import { GlAvatar, GlAvatarLink } from '@gitlab/ui';
import { nextTick } from 'vue'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import pipelineTriggerer from '~/pipelines/components/pipelines_list/pipeline_triggerer.vue'; import pipelineTriggerer from '~/pipelines/components/pipelines_list/pipeline_triggerer.vue';
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
describe('Pipelines Triggerer', () => { describe('Pipelines Triggerer', () => {
let wrapper; let wrapper;
const expectComponentWithProps = (Component, props = {}) => {
const componentWrapper = wrapper.find(Component);
expect(componentWrapper.isVisible()).toBe(true);
expect(componentWrapper.props()).toEqual(expect.objectContaining(props));
};
const mockData = { const mockData = {
pipeline: { pipeline: {
user: { user: {
...@@ -22,40 +16,65 @@ describe('Pipelines Triggerer', () => { ...@@ -22,40 +16,65 @@ describe('Pipelines Triggerer', () => {
}, },
}; };
const createComponent = () => { const createComponent = (props) => {
wrapper = shallowMount(pipelineTriggerer, { wrapper = shallowMountExtended(pipelineTriggerer, {
propsData: mockData, propsData: {
...props,
},
directives: {
GlTooltip: createMockDirective(),
},
}); });
}; };
beforeEach(() => {
createComponent();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
const findAvatarLink = () => wrapper.findComponent(GlAvatarLink);
const findAvatar = () => wrapper.findComponent(GlAvatar);
const findTriggerer = () => wrapper.findByText('API');
describe('when user was a triggerer', () => {
beforeEach(() => {
createComponent(mockData);
});
it('should render pipeline triggerer table cell', () => { it('should render pipeline triggerer table cell', () => {
expect(wrapper.find('[data-testid="pipeline-triggerer"]').exists()).toBe(true); expect(wrapper.find('[data-testid="pipeline-triggerer"]').exists()).toBe(true);
}); });
it('should pass triggerer information when triggerer is provided', () => { it('should render only user avatar', () => {
expectComponentWithProps(UserAvatarLink, { expect(findAvatarLink().exists()).toBe(true);
linkHref: mockData.pipeline.user.path, expect(findTriggerer().exists()).toBe(false);
tooltipText: mockData.pipeline.user.name, });
imgSrc: mockData.pipeline.user.avatar_url,
it('should set correct props on avatar link component', () => {
expect(findAvatarLink().attributes()).toMatchObject({
title: mockData.pipeline.user.name,
href: mockData.pipeline.user.path,
}); });
}); });
it('should render "API" when no triggerer is provided', async () => { it('should add tooltip to avatar link', () => {
wrapper.setProps({ const tooltip = getBinding(findAvatarLink().element, 'gl-tooltip');
pipeline: {
user: null, expect(tooltip).toBeDefined();
},
}); });
await nextTick(); it('should set correct props on avatar component', () => {
expect(wrapper.find('.js-pipeline-url-api').text()).toEqual('API'); expect(findAvatar().attributes().src).toBe(mockData.pipeline.user.avatar_url);
});
});
describe('when API was a triggerer', () => {
beforeEach(() => {
createComponent({ pipeline: {} });
});
it('should render label only', () => {
expect(findAvatarLink().exists()).toBe(false);
expect(findTriggerer().exists()).toBe(true);
});
}); });
}); });
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