Skip to content
Snippets Groups Projects
Commit 1752660e authored by Deepika Guliani's avatar Deepika Guliani 2️⃣
Browse files

Show tooltip on hover on work item icons

Changelog: added
parent 8c0f64d3
No related branches found
No related tags found
2 merge requests!96059Draft: Add GraphQL query for deployment details,!95563Show tooltip on hover on work item icons
......@@ -232,7 +232,11 @@ export default {
</span>
</div>
<div class="issuable-info">
<work-item-type-icon v-if="showWorkItemTypeIcon" :work-item-type="issuable.type" />
<work-item-type-icon
v-if="showWorkItemTypeIcon"
:work-item-type="issuable.type"
show-tooltip-on-hover
/>
<slot v-if="hasSlotContents('reference')" name="reference"></slot>
<span v-else data-testid="issuable-reference" class="issuable-reference">
{{ reference }}
......
<script>
import { GlIcon } from '@gitlab/ui';
import { GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { WORK_ITEMS_TYPE_MAP } from '../constants';
export default {
components: {
GlIcon,
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
workItemType: {
type: String,
......@@ -22,6 +25,11 @@ export default {
required: false,
default: '',
},
showTooltipOnHover: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
iconName() {
......@@ -32,13 +40,21 @@ export default {
workItemTypeName() {
return WORK_ITEMS_TYPE_MAP[this.workItemType]?.name;
},
workItemTooltipTitle() {
return this.showTooltipOnHover ? this.workItemTypeName : '';
},
},
};
</script>
<template>
<span>
<gl-icon :name="iconName" class="gl-mr-2" />
<gl-icon
v-gl-tooltip.hover="showTooltipOnHover"
:name="iconName"
:title="workItemTooltipTitle"
class="gl-mr-2"
/>
<span v-if="workItemTypeName" :class="{ 'gl-sr-only': !showText }">{{ workItemTypeName }}</span>
</span>
</template>
import { GlIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import WorkItemTypeIcon from '~/work_items/components/work_item_type_icon.vue';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
let wrapper;
function createComponent(propsData) {
wrapper = shallowMount(WorkItemTypeIcon, { propsData });
wrapper = shallowMount(WorkItemTypeIcon, {
propsData,
directives: {
GlTooltip: createMockDirective(),
},
});
}
describe('Work Item type component', () => {
......@@ -16,22 +22,23 @@ describe('Work Item type component', () => {
});
describe.each`
workItemType | workItemIconName | iconName | text
${'TASK'} | ${''} | ${'issue-type-task'} | ${'Task'}
${''} | ${'issue-type-task'} | ${'issue-type-task'} | ${''}
${'ISSUE'} | ${''} | ${'issue-type-issue'} | ${'Issue'}
${''} | ${'issue-type-issue'} | ${'issue-type-issue'} | ${''}
${'REQUIREMENTS'} | ${''} | ${'issue-type-requirements'} | ${'Requirements'}
${'INCIDENT'} | ${''} | ${'issue-type-incident'} | ${'Incident'}
${'TEST_CASE'} | ${''} | ${'issue-type-test-case'} | ${'Test case'}
${'random-issue-type'} | ${''} | ${'issue-type-issue'} | ${''}
workItemType | workItemIconName | iconName | text | showTooltipOnHover
${'TASK'} | ${''} | ${'issue-type-task'} | ${'Task'} | ${false}
${''} | ${'issue-type-task'} | ${'issue-type-task'} | ${''} | ${true}
${'ISSUE'} | ${''} | ${'issue-type-issue'} | ${'Issue'} | ${true}
${''} | ${'issue-type-issue'} | ${'issue-type-issue'} | ${''} | ${true}
${'REQUIREMENTS'} | ${''} | ${'issue-type-requirements'} | ${'Requirements'} | ${true}
${'INCIDENT'} | ${''} | ${'issue-type-incident'} | ${'Incident'} | ${false}
${'TEST_CASE'} | ${''} | ${'issue-type-test-case'} | ${'Test case'} | ${true}
${'random-issue-type'} | ${''} | ${'issue-type-issue'} | ${''} | ${true}
`(
'with workItemType set to "$workItemType" and workItemIconName set to "$workItemIconName"',
({ workItemType, workItemIconName, iconName, text }) => {
({ workItemType, workItemIconName, iconName, text, showTooltipOnHover }) => {
beforeEach(() => {
createComponent({
workItemType,
workItemIconName,
showTooltipOnHover,
});
});
......@@ -42,6 +49,12 @@ describe('Work Item type component', () => {
it(`renders correct text`, () => {
expect(wrapper.text()).toBe(text);
});
it('shows tooltip on hover when props passed', () => {
const tooltip = getBinding(findIcon().element, 'gl-tooltip');
expect(tooltip.value).toBe(showTooltipOnHover);
});
},
);
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment