Commit e637fab5 authored by Phil Hughes's avatar Phil Hughes

Merge branch '209993-refactor-event-item' into '209990-refactor-vulnerability-header-footer'

Refactor event item component to use callback functions instead of $emit

See merge request gitlab-org/gitlab!29115
parents a94741e9 7077ffcf
...@@ -77,12 +77,12 @@ export default { ...@@ -77,12 +77,12 @@ export default {
return [ return [
{ {
iconName: 'pencil', iconName: 'pencil',
emit: 'editVulnerabilityDismissalComment', onClick: () => this.$emit('editVulnerabilityDismissalComment'),
title: __('Edit Comment'), title: __('Edit Comment'),
}, },
{ {
iconName: 'remove', iconName: 'remove',
emit: 'showDismissalDeleteButtons', onClick: () => this.$emit('showDismissalDeleteButtons'),
title: __('Delete Comment'), title: __('Delete Comment'),
}, },
]; ];
...@@ -97,7 +97,7 @@ export default { ...@@ -97,7 +97,7 @@ export default {
:author="feedback.author" :author="feedback.author"
:created-at="feedback.created_at" :created-at="feedback.created_at"
icon-name="cancel" icon-name="cancel"
icon-style="ci-status-icon-pending" icon-class="ci-status-icon-pending"
> >
<div v-if="feedback.created_at" v-html="eventText"></div> <div v-if="feedback.created_at" v-html="eventText"></div>
</event-item> </event-item>
...@@ -110,15 +110,11 @@ export default { ...@@ -110,15 +110,11 @@ export default {
:show-right-slot="isShowingDeleteButtons" :show-right-slot="isShowingDeleteButtons"
:show-action-buttons="showDismissalCommentActions" :show-action-buttons="showDismissalCommentActions"
icon-name="comment" icon-name="comment"
icon-style="ci-status-icon-pending" icon-class="ci-status-icon-pending"
@editVulnerabilityDismissalComment="$emit('editVulnerabilityDismissalComment')"
@showDismissalDeleteButtons="$emit('showDismissalDeleteButtons')"
@hideDismissalDeleteButtons="$emit('hideDismissalDeleteButtons')"
@deleteDismissalComment="$emit('deleteDismissalComment')"
> >
{{ commentDetails.comment }} {{ commentDetails.comment }}
<template v-slot:right-content> <template #right-content>
<div class="d-flex flex-grow-1 align-self-start flex-row-reverse"> <div class="d-flex flex-grow-1 align-self-start flex-row-reverse">
<loading-button <loading-button
:label="__('Delete comment')" :label="__('Delete comment')"
......
...@@ -28,7 +28,7 @@ export default { ...@@ -28,7 +28,7 @@ export default {
required: false, required: false,
default: 'plus', default: 'plus',
}, },
iconStyle: { iconClass: {
type: String, type: String,
required: false, required: false,
default: 'ci-status-icon-success', default: 'ci-status-icon-success',
...@@ -54,16 +54,16 @@ export default { ...@@ -54,16 +54,16 @@ export default {
<template> <template>
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<div class="circle-icon-container" :class="iconStyle"> <div class="circle-icon-container" :class="iconClass">
<icon :size="16" :name="iconName" /> <icon :size="16" :name="iconName" />
</div> </div>
<div class="ml-3" data-qa-selector="event_item_content"> <div class="ml-3 flex-grow-1" data-qa-selector="event_item_content">
<div class="note-header-info pb-0"> <div class="note-header-info pb-0">
<a <a
:href="author.path" :href="author.path"
:data-user-id="author.id" :data-user-id="author.id"
:data-username="author.username" :data-username="author.username"
class="js-author" class="js-author js-user-link"
> >
<strong class="note-header-author-name">{{ author.name }}</strong> <strong class="note-header-author-name">{{ author.name }}</strong>
<span v-if="author.status_tooltip_html" v-html="author.status_tooltip_html"></span> <span v-if="author.status_tooltip_html" v-html="author.status_tooltip_html"></span>
...@@ -81,21 +81,18 @@ export default { ...@@ -81,21 +81,18 @@ export default {
<slot v-if="showRightSlot" name="right-content"></slot> <slot v-if="showRightSlot" name="right-content"></slot>
<div v-else class="d-flex flex-grow-1 align-self-start flex-row-reverse"> <div v-else-if="showActionButtons" class="align-self-start">
<div v-if="showActionButtons" class="action-buttons"> <gl-deprecated-button
<gl-deprecated-button v-for="button in actionButtons"
v-for="button in actionButtons" :key="button.title"
:key="button.title" v-gl-tooltip
ref="button" class="px-1"
v-gl-tooltip variant="transparent"
class="px-1" :title="button.title"
variant="transparent" @click="button.onClick"
:title="button.title" >
@click="$emit(button.emit)" <icon :name="button.iconName" class="link-highlight" />
> </gl-deprecated-button>
<icon :name="button.iconName" class="link-highlight" />
</gl-deprecated-button>
</div>
</div> </div>
</div> </div>
</template> </template>
import { GlDeprecatedButton } from '@gitlab/ui';
import Component from 'ee/vue_shared/security_reports/components/event_item.vue'; import Component from 'ee/vue_shared/security_reports/components/event_item.vue';
import { shallowMount, mount } from '@vue/test-utils'; import { shallowMount, mount } from '@vue/test-utils';
...@@ -37,7 +38,7 @@ describe('Event Item', () => { ...@@ -37,7 +38,7 @@ describe('Event Item', () => {
}); });
it('uses the fallback icon class', () => { it('uses the fallback icon class', () => {
expect(wrapper.props().iconStyle).toBe('ci-status-icon-success'); expect(wrapper.props().iconClass).toBe('ci-status-icon-success');
}); });
it('renders the action buttons tontainer', () => { it('renders the action buttons tontainer', () => {
...@@ -53,12 +54,12 @@ describe('Event Item', () => { ...@@ -53,12 +54,12 @@ describe('Event Item', () => {
actionButtons: [ actionButtons: [
{ {
iconName: 'pencil', iconName: 'pencil',
emit: 'fooEvent', onClick: jest.fn(),
title: 'Foo Action', title: 'Foo Action',
}, },
{ {
iconName: 'remove', iconName: 'remove',
emit: 'barEvent', onClick: jest.fn(),
title: 'Bar Action', title: 'Bar Action',
}, },
], ],
...@@ -77,12 +78,12 @@ describe('Event Item', () => { ...@@ -77,12 +78,12 @@ describe('Event Item', () => {
}); });
it('renders the action buttons', () => { it('renders the action buttons', () => {
expect(wrapper.findAll('.action-buttons > button').length).toBe(2); expect(wrapper.findAll(GlDeprecatedButton).length).toBe(2);
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });
it('emits the button events when clicked', () => { it('emits the button events when clicked', () => {
const buttons = wrapper.findAll('.action-buttons > button'); const buttons = wrapper.findAll(GlDeprecatedButton);
buttons.at(0).trigger('click'); buttons.at(0).trigger('click');
return wrapper.vm return wrapper.vm
.$nextTick() .$nextTick()
...@@ -91,8 +92,8 @@ describe('Event Item', () => { ...@@ -91,8 +92,8 @@ describe('Event Item', () => {
return wrapper.vm.$nextTick(); return wrapper.vm.$nextTick();
}) })
.then(() => { .then(() => {
expect(wrapper.emitted().fooEvent.length).toEqual(1); expect(propsData.actionButtons[0].onClick).toHaveBeenCalledTimes(1);
expect(wrapper.emitted().barEvent.length).toEqual(1); expect(propsData.actionButtons[1].onClick).toHaveBeenCalledTimes(1);
}); });
}); });
}); });
......
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