Skip to content
代码片段 群组 项目
未验证 提交 82808a2a 编辑于 作者: Anastasia Khomchenko's avatar Anastasia Khomchenko 提交者: GitLab
浏览文件

Add temporary tooltip to relationship icons

上级 a719694e
No related branches found
No related tags found
无相关合并请求
<script> <script>
import { GlIcon } from '@gitlab/ui'; import { GlIcon, GlTooltipDirective } from '@gitlab/ui';
import { n__, sprintf } from '~/locale'; import { n__, sprintf } from '~/locale';
import { LINKED_CATEGORIES_MAP, sprintfWorkItem } from '../../constants'; import { LINKED_CATEGORIES_MAP, sprintfWorkItem } from '../../constants';
...@@ -7,6 +7,9 @@ export default { ...@@ -7,6 +7,9 @@ export default {
components: { components: {
GlIcon, GlIcon,
}, },
directives: {
GlTooltip: GlTooltipDirective,
},
props: { props: {
linkedWorkItems: { linkedWorkItems: {
type: Array, type: Array,
...@@ -28,7 +31,7 @@ export default { ...@@ -28,7 +31,7 @@ export default {
return item.linkType === LINKED_CATEGORIES_MAP.BLOCKS; return item.linkType === LINKED_CATEGORIES_MAP.BLOCKS;
}); });
}, },
blockedByAriaLabel() { blockedByLabel() {
const message = sprintf( const message = sprintf(
n__( n__(
'WorkItem|%{workItemType} is blocked by 1 item', 'WorkItem|%{workItemType} is blocked by 1 item',
...@@ -39,7 +42,7 @@ export default { ...@@ -39,7 +42,7 @@ export default {
); );
return sprintfWorkItem(message, this.workItemType); return sprintfWorkItem(message, this.workItemType);
}, },
blocksAriaLabel() { blocksLabel() {
const message = sprintf( const message = sprintf(
n__( n__(
'WorkItem|%{workItemType} blocks 1 item', 'WorkItem|%{workItemType} blocks 1 item',
...@@ -58,17 +61,20 @@ export default { ...@@ -58,17 +61,20 @@ export default {
<span class="gl-flex gl-gap-3"> <span class="gl-flex gl-gap-3">
<span <span
v-if="itemsBlockedBy.length" v-if="itemsBlockedBy.length"
:aria-label="blockedByAriaLabel" v-gl-tooltip
:title="blockedByLabel"
:aria-label="blockedByLabel"
class="gl-text-sm gl-text-secondary" class="gl-text-sm gl-text-secondary"
data-testid="relationship-blocked-by-icon" data-testid="relationship-blocked-by-icon"
> >
<gl-icon name="entity-blocked" class="gl-text-red-500" /> <gl-icon name="entity-blocked" class="gl-text-red-500" />
{{ itemsBlockedBy.length }} {{ itemsBlockedBy.length }}
</span> </span>
<span <span
v-if="itemsBlocks.length" v-if="itemsBlocks.length"
:aria-label="blocksAriaLabel" v-gl-tooltip
:title="blocksLabel"
:aria-label="blocksLabel"
class="gl-text-sm gl-text-secondary" class="gl-text-sm gl-text-secondary"
data-testid="relationship-blocks-icon" data-testid="relationship-blocks-icon"
> >
......
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import WorkItemRelationshipIcons from '~/work_items/components/shared/work_item_relationship_icons.vue'; import WorkItemRelationshipIcons from '~/work_items/components/shared/work_item_relationship_icons.vue';
import { LINKED_CATEGORIES_MAP } from '~/work_items/constants'; import { LINKED_CATEGORIES_MAP } from '~/work_items/constants';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
import { mockLinkedItems } from '../../mock_data'; import { mockLinkedItems } from '../../mock_data';
...@@ -9,6 +10,9 @@ describe('WorkItemRelationshipIcons', () => { ...@@ -9,6 +10,9 @@ describe('WorkItemRelationshipIcons', () => {
const createComponent = () => { const createComponent = () => {
wrapper = shallowMountExtended(WorkItemRelationshipIcons, { wrapper = shallowMountExtended(WorkItemRelationshipIcons, {
directives: {
GlTooltip: createMockDirective('gl-tooltip'),
},
propsData: { propsData: {
linkedWorkItems: mockLinkedItems.linkedItems.nodes, linkedWorkItems: mockLinkedItems.linkedItems.nodes,
workItemType: 'Task', workItemType: 'Task',
...@@ -18,6 +22,7 @@ describe('WorkItemRelationshipIcons', () => { ...@@ -18,6 +22,7 @@ describe('WorkItemRelationshipIcons', () => {
const findBlockedIcon = () => wrapper.findByTestId('relationship-blocked-by-icon'); const findBlockedIcon = () => wrapper.findByTestId('relationship-blocked-by-icon');
const findBlockingIcon = () => wrapper.findByTestId('relationship-blocks-icon'); const findBlockingIcon = () => wrapper.findByTestId('relationship-blocks-icon');
const findTooltip = (icon) => getBinding(icon.element, 'gl-tooltip');
const blockedItems = mockLinkedItems.linkedItems.nodes.filter( const blockedItems = mockLinkedItems.linkedItems.nodes.filter(
(item) => item.linkType === LINKED_CATEGORIES_MAP.IS_BLOCKED_BY, (item) => item.linkType === LINKED_CATEGORIES_MAP.IS_BLOCKED_BY,
...@@ -58,4 +63,13 @@ describe('WorkItemRelationshipIcons', () => { ...@@ -58,4 +63,13 @@ describe('WorkItemRelationshipIcons', () => {
expect(findBlockedIcon().exists()).toBe(true); expect(findBlockedIcon().exists()).toBe(true);
expect(findBlockingIcon().text()).toContain(blockedItems.length.toString()); expect(findBlockingIcon().text()).toContain(blockedItems.length.toString());
}); });
it('renders tooltips with correct text', () => {
createComponent();
expect(findTooltip(findBlockingIcon())).toBeDefined();
expect(findTooltip(findBlockedIcon())).toBeDefined();
expect(findBlockedIcon().attributes('title')).toBe('Task is blocked by 1 item');
expect(findBlockingIcon().attributes('title')).toBe('Task blocks 1 item');
});
}); });
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册