Commit 888a0346 authored by Andrew Fontaine's avatar Andrew Fontaine

Merge branch 'Tiny-fixes-to-render-user-inline-avatars-with-gl-avatar' into 'master'

Add CSS class for UserAvatarInline rendered with `GlAvatar`

See merge request gitlab-org/gitlab!83344
parents d9b30205 c66555e9
...@@ -96,11 +96,12 @@ export default { ...@@ -96,11 +96,12 @@ export default {
/> />
<gl-tooltip <gl-tooltip
v-if="tooltipText || $slots.default"
:target="() => $refs.userAvatar.$el" :target="() => $refs.userAvatar.$el"
:placement="tooltipPlacement" :placement="tooltipPlacement"
boundary="window" boundary="window"
> >
<slot> {{ tooltipText }}</slot> <slot>{{ tooltipText }}</slot>
</gl-tooltip> </gl-tooltip>
</span> </span>
</template> </template>
...@@ -100,11 +100,12 @@ export default { ...@@ -100,11 +100,12 @@ export default {
class="avatar" class="avatar"
/> />
<gl-tooltip <gl-tooltip
v-if="tooltipText || $slots.default"
:target="() => $refs.userAvatarImage" :target="() => $refs.userAvatarImage"
:placement="tooltipPlacement" :placement="tooltipPlacement"
boundary="window" boundary="window"
> >
<slot> {{ tooltipText }}</slot> <slot>{{ tooltipText }}</slot>
</gl-tooltip> </gl-tooltip>
</span> </span>
</template> </template>
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import glFeatureFlagMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { sprintf, __ } from '~/locale'; import { sprintf, __ } from '~/locale';
import UserAvatarLink from './user_avatar_link.vue'; import UserAvatarLink from './user_avatar_link.vue';
...@@ -8,6 +9,7 @@ export default { ...@@ -8,6 +9,7 @@ export default {
UserAvatarLink, UserAvatarLink,
GlButton, GlButton,
}, },
mixins: [glFeatureFlagMixin()],
props: { props: {
items: { items: {
type: Array, type: Array,
...@@ -57,6 +59,9 @@ export default { ...@@ -57,6 +59,9 @@ export default {
return sprintf(__('%{count} more'), { count }); return sprintf(__('%{count} more'), { count });
}, },
imgCssClasses() {
return this.glFeatures.glAvatarForAllUserAvatars ? 'gl-mr-3' : '';
},
}, },
methods: { methods: {
expand() { expand() {
...@@ -80,6 +85,7 @@ export default { ...@@ -80,6 +85,7 @@ export default {
:img-alt="item.name" :img-alt="item.name"
:tooltip-text="item.name" :tooltip-text="item.name"
:img-size="imgSize" :img-size="imgSize"
:img-css-classes="imgCssClasses"
/> />
<template v-if="hasBreakpoint"> <template v-if="hasBreakpoint">
<gl-button v-if="hasHiddenItems" variant="link" @click="expand"> <gl-button v-if="hasHiddenItems" variant="link" @click="expand">
......
...@@ -109,19 +109,33 @@ describe('User Avatar Image Component', () => { ...@@ -109,19 +109,33 @@ describe('User Avatar Image Component', () => {
default: ['Action!'], default: ['Action!'],
}; };
beforeEach(() => { describe('when `tooltipText` is provided and no default slot', () => {
wrapper = shallowMount(UserAvatarImage, { beforeEach(() => {
propsData: PROVIDED_PROPS, wrapper = shallowMount(UserAvatarImage, {
slots, propsData: { ...PROVIDED_PROPS },
});
}); });
});
it('renders the tooltip slot', () => { it('renders the tooltip with `tooltipText` as content', () => {
expect(wrapper.findComponent(GlTooltip).exists()).toBe(true); expect(wrapper.findComponent(GlTooltip).text()).toBe(PROVIDED_PROPS.tooltipText);
});
}); });
it('renders the tooltip content', () => { describe('when `tooltipText` and default slot is provided', () => {
expect(wrapper.findComponent(GlTooltip).text()).toContain(slots.default[0]); beforeEach(() => {
wrapper = shallowMount(UserAvatarImage, {
propsData: { ...PROVIDED_PROPS },
slots,
});
});
it('does not render `tooltipText` inside the tooltip', () => {
expect(wrapper.findComponent(GlTooltip).text()).not.toBe(PROVIDED_PROPS.tooltipText);
});
it('renders the content provided via default slot', () => {
expect(wrapper.findComponent(GlTooltip).text()).toContain(slots.default[0]);
});
}); });
}); });
}); });
...@@ -90,33 +90,38 @@ describe('User Avatar Image Component', () => { ...@@ -90,33 +90,38 @@ describe('User Avatar Image Component', () => {
}); });
}); });
describe('dynamic tooltip content', () => { describe('Dynamic tooltip content', () => {
const props = PROVIDED_PROPS;
const slots = { const slots = {
default: ['Action!'], default: ['Action!'],
}; };
beforeEach(() => { describe('when `tooltipText` is provided and no default slot', () => {
wrapper = shallowMount(UserAvatarImage, { beforeEach(() => {
propsData: { props }, wrapper = shallowMount(UserAvatarImage, {
slots, propsData: { ...PROVIDED_PROPS },
});
}); });
});
it('renders the tooltip slot', () => { it('renders the tooltip with `tooltipText` as content', () => {
expect(wrapper.findComponent(GlTooltip).exists()).toBe(true); expect(wrapper.findComponent(GlTooltip).text()).toBe(PROVIDED_PROPS.tooltipText);
});
}); });
it('renders the tooltip content', () => { describe('when `tooltipText` and default slot is provided', () => {
expect(wrapper.findComponent(GlTooltip).text()).toContain(slots.default[0]); beforeEach(() => {
}); wrapper = shallowMount(UserAvatarImage, {
propsData: { ...PROVIDED_PROPS },
slots,
});
});
it('does not render tooltip data attributes on avatar image', () => { it('does not render `tooltipText` inside the tooltip', () => {
const avatarImg = wrapper.find('img'); expect(wrapper.findComponent(GlTooltip).text()).not.toBe(PROVIDED_PROPS.tooltipText);
});
expect(avatarImg.attributes('title')).toBeFalsy(); it('renders the content provided via default slot', () => {
expect(avatarImg.attributes('data-placement')).not.toBeDefined(); expect(wrapper.findComponent(GlTooltip).text()).toContain(slots.default[0]);
expect(avatarImg.attributes('data-container')).not.toBeDefined(); });
}); });
}); });
}); });
...@@ -153,4 +153,29 @@ describe('UserAvatarList', () => { ...@@ -153,4 +153,29 @@ describe('UserAvatarList', () => {
}); });
}); });
}); });
describe('additional styling for the image', () => {
it('should not add CSS class when feature flag `glAvatarForAllUserAvatars` is disabled', () => {
factory({
propsData: { items: createList(1) },
});
const link = wrapper.findComponent(UserAvatarLink);
expect(link.props('imgCssClasses')).not.toBe('gl-mr-3');
});
it('should add CSS class when feature flag `glAvatarForAllUserAvatars` is enabled', () => {
factory({
propsData: { items: createList(1) },
provide: {
glFeatures: {
glAvatarForAllUserAvatars: true,
},
},
});
const link = wrapper.findComponent(UserAvatarLink);
expect(link.props('imgCssClasses')).toBe('gl-mr-3');
});
});
}); });
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