Commit 25f9fb66 authored by Kushal Pandya's avatar Kushal Pandya

Add IssuableHeader component

Adds IssuableHeader component to use with
Issuable Show app.
parent 6e7e1982
<script>
import { GlIcon, GlButton, GlTooltipDirective, GlAvatarLink, GlAvatarLabeled } from '@gitlab/ui';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
export default {
components: {
GlIcon,
GlButton,
GlAvatarLink,
GlAvatarLabeled,
TimeAgoTooltip,
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
createdAt: {
type: String,
required: true,
},
author: {
type: Object,
required: true,
},
statusBadgeClass: {
type: String,
required: false,
default: '',
},
statusIcon: {
type: String,
required: false,
default: '',
},
blocked: {
type: Boolean,
required: false,
default: false,
},
confidential: {
type: Boolean,
required: false,
default: false,
},
},
computed: {
authorId() {
return getIdFromGraphQLId(`${this.author.id}`);
},
},
mounted() {
this.toggleSidebarButtonEl = document.querySelector('.js-toggle-right-sidebar-button');
},
methods: {
handleRightSidebarToggleClick() {
if (this.toggleSidebarButtonEl) {
this.toggleSidebarButtonEl.dispatchEvent(new Event('click'));
}
},
},
};
</script>
<template>
<div class="detail-page-header">
<div class="detail-page-header-body">
<div data-testid="status" class="issuable-status-box status-box" :class="statusBadgeClass">
<gl-icon v-if="statusIcon" :name="statusIcon" class="d-block d-sm-none" />
<span class="d-none d-sm-block"><slot name="status-badge"></slot></span>
</div>
<div class="issuable-meta gl-display-flex gl-align-items-center">
<div class="gl-display-inline-block">
<div v-if="blocked" data-testid="blocked" class="issuable-warning-icon inline">
<gl-icon name="lock" :aria-label="__('Blocked')" />
</div>
<div v-if="confidential" data-testid="confidential" class="issuable-warning-icon inline">
<gl-icon name="eye-slash" :aria-label="__('Confidential')" />
</div>
</div>
<span>
{{ __('Opened') }}
<time-ago-tooltip data-testid="startTimeItem" :time="createdAt" />
{{ __('by') }}
</span>
<gl-avatar-link
data-testid="avatar"
:data-user-id="authorId"
:data-username="author.username"
:data-name="author.name"
:href="author.webUrl"
target="_blank"
class="js-user-link gl-ml-2"
>
<gl-avatar-labeled
:size="24"
:src="author.avatarUrl"
:label="author.name"
class="d-none d-sm-inline-flex gl-ml-1"
/>
<strong class="author d-sm-none d-inline">@{{ author.username }}</strong>
</gl-avatar-link>
</div>
<gl-button
data-testid="sidebar-toggle"
icon="chevron-double-lg-left"
class="d-block d-sm-none gutter-toggle issuable-gutter-toggle"
:aria-label="__('Expand sidebar')"
@click="handleRightSidebarToggleClick"
/>
</div>
<div
data-testid="header-actions"
class="detail-page-header-actions js-issuable-actions js-issuable-buttons gl-display-flex gl-display-md-block"
>
<slot name="header-actions"></slot>
</div>
</div>
</template>
import { shallowMount } from '@vue/test-utils';
import { GlIcon, GlAvatarLabeled } from '@gitlab/ui';
import IssuableHeader from '~/issuable_show/components/issuable_header.vue';
import { mockIssuableShowProps, mockIssuable } from '../mock_data';
const issuableHeaderProps = {
...mockIssuable,
...mockIssuableShowProps,
};
const createComponent = (propsData = issuableHeaderProps) =>
shallowMount(IssuableHeader, {
propsData,
slots: {
'status-badge': 'Open',
'header-actions': `
<button class="js-close">Close issuable</button>
<a class="js-new" href="/gitlab-org/gitlab-shell/-/issues/new">New issuable</a>
`,
},
});
describe('IssuableHeader', () => {
let wrapper;
const findByTestId = testId => wrapper.find(`[data-testid="${testId}"]`);
beforeEach(() => {
wrapper = createComponent();
});
afterEach(() => {
wrapper.destroy();
});
describe('computed', () => {
describe('authorId', () => {
it('returns numeric ID from GraphQL ID of `author` prop', () => {
expect(wrapper.vm.authorId).toBe(1);
});
});
});
describe('handleRightSidebarToggleClick', () => {
beforeEach(() => {
setFixtures('<button class="js-toggle-right-sidebar-button">Collapse sidebar</button>');
});
it('dispatches `click` event on sidebar toggle button', () => {
wrapper.vm.toggleSidebarButtonEl = document.querySelector('.js-toggle-right-sidebar-button');
jest.spyOn(wrapper.vm.toggleSidebarButtonEl, 'dispatchEvent').mockImplementation(jest.fn);
wrapper.vm.handleRightSidebarToggleClick();
expect(wrapper.vm.toggleSidebarButtonEl.dispatchEvent).toHaveBeenCalledWith(
expect.objectContaining({
type: 'click',
}),
);
});
});
describe('template', () => {
it('renders issuable status icon and text', () => {
const statusBoxEl = findByTestId('status');
expect(statusBoxEl.exists()).toBe(true);
expect(statusBoxEl.find(GlIcon).props('name')).toBe(mockIssuableShowProps.statusIcon);
expect(statusBoxEl.text()).toContain('Open');
});
it('renders blocked icon when issuable is blocked', async () => {
wrapper.setProps({
blocked: true,
});
await wrapper.vm.$nextTick();
const blockedEl = findByTestId('blocked');
expect(blockedEl.exists()).toBe(true);
expect(blockedEl.find(GlIcon).props('name')).toBe('lock');
});
it('renders confidential icon when issuable is confidential', async () => {
wrapper.setProps({
confidential: true,
});
await wrapper.vm.$nextTick();
const confidentialEl = findByTestId('confidential');
expect(confidentialEl.exists()).toBe(true);
expect(confidentialEl.find(GlIcon).props('name')).toBe('eye-slash');
});
it('renders issuable author avatar', () => {
const { username, name, webUrl, avatarUrl } = mockIssuable.author;
const avatarElAttrs = {
'data-user-id': '1',
'data-username': username,
'data-name': name,
href: webUrl,
target: '_blank',
};
const avatarEl = findByTestId('avatar');
expect(avatarEl.exists()).toBe(true);
expect(avatarEl.attributes()).toMatchObject(avatarElAttrs);
expect(avatarEl.find(GlAvatarLabeled).attributes()).toMatchObject({
size: '24',
src: avatarUrl,
label: name,
});
});
it('renders sidebar toggle button', () => {
const toggleButtonEl = findByTestId('sidebar-toggle');
expect(toggleButtonEl.exists()).toBe(true);
expect(toggleButtonEl.props('icon')).toBe('chevron-double-lg-left');
});
it('renders header actions', () => {
const actionsEl = findByTestId('header-actions');
expect(actionsEl.find('button.js-close').exists()).toBe(true);
expect(actionsEl.find('a.js-new').exists()).toBe(true);
});
});
});
import { mockIssuable as issuable } from '../issuable_list/mock_data';
export const mockIssuable = {
...issuable,
id: 'gid://gitlab/Issue/30',
title: 'Sample title',
titleHtml: 'Sample title',
description: '# Summary',
descriptionHtml:
'<h1 data-sourcepos="1:1-1:25" dir="auto">&#x000A;<a id="user-content-magnoque-it-lurida-deus" class="anchor" href="#magnoque-it-lurida-deus" aria-hidden="true"></a>Summary</h1>',
state: 'opened',
blocked: false,
confidential: false,
currentUserTodos: {
nodes: [
{
id: 'gid://gitlab/Todo/489',
state: 'done',
},
],
},
};
export const mockIssuableShowProps = {
issuable: mockIssuable,
descriptionHelpPath: '/help/user/markdown',
descriptionPreviewPath: '/gitlab-org/gitlab-shell/preview_markdown',
editFormVisible: false,
enableAutocomplete: true,
enableEdit: true,
statusBadgeClass: 'status-box-open',
statusIcon: 'issue-open-m',
};
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