Commit 384836c9 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '229293-migrate-to-GlButton-note-form' into 'master'

Migrate to GlButton in note_form

See merge request gitlab-org/gitlab!42221
parents 694c1d4f 2defec23
<script> <script>
/* eslint-disable vue/no-v-html */ /* eslint-disable vue/no-v-html */
import { mapGetters, mapActions, mapState } from 'vuex'; import { mapGetters, mapActions, mapState } from 'vuex';
import { GlButton } from '@gitlab/ui';
import { mergeUrlParams } from '~/lib/utils/url_utility'; import { mergeUrlParams } from '~/lib/utils/url_utility';
import eventHub from '../event_hub'; import eventHub from '../event_hub';
import markdownField from '~/vue_shared/components/markdown/field.vue'; import markdownField from '~/vue_shared/components/markdown/field.vue';
...@@ -16,6 +17,7 @@ export default { ...@@ -16,6 +17,7 @@ export default {
components: { components: {
markdownField, markdownField,
CommentFieldLayout, CommentFieldLayout,
GlButton,
}, },
mixins: [glFeatureFlagsMixin(), issuableStateMixin, resolvable], mixins: [glFeatureFlagsMixin(), issuableStateMixin, resolvable],
props: { props: {
...@@ -378,61 +380,70 @@ export default { ...@@ -378,61 +380,70 @@ export default {
</template> </template>
</label> </label>
</p> </p>
<div> <div class="gl-display-sm-flex gl-flex-wrap">
<button <gl-button
:disabled="isDisabled" :disabled="isDisabled"
type="button" category="primary"
class="btn btn-success" variant="success"
class="gl-mr-3"
data-qa-selector="start_review_button" data-qa-selector="start_review_button"
@click="handleAddToReview" @click="handleAddToReview"
> >
<template v-if="hasDrafts">{{ __('Add to review') }}</template> <template v-if="hasDrafts">{{ __('Add to review') }}</template>
<template v-else>{{ __('Start a review') }}</template> <template v-else>{{ __('Start a review') }}</template>
</button> </gl-button>
<button <gl-button
:disabled="isDisabled" :disabled="isDisabled"
type="button" category="secondary"
class="btn js-comment-button" variant="default"
data-qa-selector="comment_now_button" data-qa-selector="comment_now_button"
class="gl-mr-3 js-comment-button"
@click="handleUpdate()" @click="handleUpdate()"
> >
{{ __('Add comment now') }} {{ __('Add comment now') }}
</button> </gl-button>
<button <gl-button
class="btn note-edit-cancel js-close-discussion-note-form" class="note-edit-cancel js-close-discussion-note-form"
type="button" category="secondary"
variant="default"
data-testid="cancelBatchCommentsEnabled" data-testid="cancelBatchCommentsEnabled"
@click="cancelHandler(true)" @click="cancelHandler(true)"
> >
{{ __('Cancel') }} {{ __('Cancel') }}
</button> </gl-button>
</div> </div>
</template> </template>
<template v-else> <template v-else>
<button <div class="gl-display-sm-flex gl-flex-wrap">
<gl-button
:disabled="isDisabled" :disabled="isDisabled"
type="button" category="primary"
class="js-vue-issue-save btn btn-success js-comment-button" variant="success"
data-qa-selector="reply_comment_button" data-qa-selector="reply_comment_button"
class="gl-mr-3 js-vue-issue-save js-comment-button"
@click="handleUpdate()" @click="handleUpdate()"
> >
{{ saveButtonTitle }} {{ saveButtonTitle }}
</button> </gl-button>
<button <gl-button
v-if="discussion.resolvable" v-if="discussion.resolvable"
class="btn btn-default gl-mr-3 js-comment-resolve-button" category="secondary"
variant="default"
class="gl-mr-3 js-comment-resolve-button"
@click.prevent="handleUpdate(true)" @click.prevent="handleUpdate(true)"
> >
{{ resolveButtonTitle }} {{ resolveButtonTitle }}
</button> </gl-button>
<button <gl-button
class="btn btn-cancel note-edit-cancel js-close-discussion-note-form" class="note-edit-cancel js-close-discussion-note-form"
type="button" category="secondary"
variant="default"
data-testid="cancel" data-testid="cancel"
@click="cancelHandler(true)" @click="cancelHandler(true)"
> >
{{ __('Cancel') }} {{ __('Cancel') }}
</button> </gl-button>
</div>
</template> </template>
</div> </div>
</form> </form>
......
---
title: Migrate button to gitlab ui in note form
merge_request: 42221
author:
type: changed
...@@ -161,7 +161,7 @@ RSpec.describe 'Merge request > User posts notes', :js do ...@@ -161,7 +161,7 @@ RSpec.describe 'Merge request > User posts notes', :js do
fill_in 'note[note]', with: 'Some new content' fill_in 'note[note]', with: 'Some new content'
accept_confirm do accept_confirm do
find('.btn-cancel').click find('[data-testid="cancel"]').click
end end
end end
expect(find('.js-note-text').text).to eq '' expect(find('.js-note-text').text).to eq ''
......
...@@ -4,9 +4,8 @@ import createStore from '~/notes/stores'; ...@@ -4,9 +4,8 @@ import createStore from '~/notes/stores';
import NoteForm from '~/notes/components/note_form.vue'; import NoteForm from '~/notes/components/note_form.vue';
import batchComments from '~/batch_comments/stores/modules/batch_comments'; import batchComments from '~/batch_comments/stores/modules/batch_comments';
import MarkdownField from '~/vue_shared/components/markdown/field.vue'; import MarkdownField from '~/vue_shared/components/markdown/field.vue';
import { noteableDataMock, notesDataMock, discussionMock } from '../mock_data';
import { getDraft, updateDraft } from '~/lib/utils/autosave'; import { getDraft, updateDraft } from '~/lib/utils/autosave';
import { noteableDataMock, notesDataMock, discussionMock } from '../mock_data';
jest.mock('~/lib/utils/autosave'); jest.mock('~/lib/utils/autosave');
...@@ -25,6 +24,8 @@ describe('issue_note_form component', () => { ...@@ -25,6 +24,8 @@ describe('issue_note_form component', () => {
}); });
}; };
const findCancelButton = () => wrapper.find('[data-testid="cancel"]');
beforeEach(() => { beforeEach(() => {
getDraft.mockImplementation((key) => { getDraft.mockImplementation((key) => {
if (key === dummyAutosaveKey) { if (key === dummyAutosaveKey) {
...@@ -160,8 +161,8 @@ describe('issue_note_form component', () => { ...@@ -160,8 +161,8 @@ describe('issue_note_form component', () => {
}); });
await nextTick(); await nextTick();
const cancelButton = wrapper.find('[data-testid="cancel"]'); const cancelButton = findCancelButton();
cancelButton.trigger('click'); cancelButton.vm.$emit('click');
await nextTick(); await nextTick();
expect(wrapper.emitted().cancelForm).toHaveLength(1); expect(wrapper.emitted().cancelForm).toHaveLength(1);
...@@ -177,7 +178,7 @@ describe('issue_note_form component', () => { ...@@ -177,7 +178,7 @@ describe('issue_note_form component', () => {
const textarea = wrapper.find('textarea'); const textarea = wrapper.find('textarea');
textarea.setValue('Foo'); textarea.setValue('Foo');
const saveButton = wrapper.find('.js-vue-issue-save'); const saveButton = wrapper.find('.js-vue-issue-save');
saveButton.trigger('click'); saveButton.vm.$emit('click');
expect(wrapper.vm.isSubmitting).toBe(true); expect(wrapper.vm.isSubmitting).toBe(true);
}); });
...@@ -272,7 +273,7 @@ describe('issue_note_form component', () => { ...@@ -272,7 +273,7 @@ describe('issue_note_form component', () => {
await nextTick(); await nextTick();
const cancelButton = wrapper.find('[data-testid="cancelBatchCommentsEnabled"]'); const cancelButton = wrapper.find('[data-testid="cancelBatchCommentsEnabled"]');
cancelButton.trigger('click'); cancelButton.vm.$emit('click');
expect(wrapper.vm.cancelHandler).toHaveBeenCalledWith(true); expect(wrapper.vm.cancelHandler).toHaveBeenCalledWith(true);
}); });
...@@ -302,16 +303,16 @@ describe('issue_note_form component', () => { ...@@ -302,16 +303,16 @@ describe('issue_note_form component', () => {
expect(wrapper.find('.js-resolve-checkbox').exists()).toBe(false); expect(wrapper.find('.js-resolve-checkbox').exists()).toBe(false);
}); });
it('hides actions for commits', () => { it('hides actions for commits', async () => {
wrapper.setProps({ discussion: { for_commit: true } }); wrapper.setProps({ discussion: { for_commit: true } });
return nextTick(() => { await nextTick();
expect(wrapper.find('.note-form-actions').text()).not.toContain('Start a review'); expect(wrapper.find('.note-form-actions').text()).not.toContain('Start a review');
}); });
});
describe('on enter', () => { describe('on enter', () => {
it('should start review or add to review when cmd+enter is pressed', () => { it('should start review or add to review when cmd+enter is pressed', async () => {
const textarea = wrapper.find('textarea'); const textarea = wrapper.find('textarea');
jest.spyOn(wrapper.vm, 'handleAddToReview'); jest.spyOn(wrapper.vm, 'handleAddToReview');
...@@ -319,10 +320,9 @@ describe('issue_note_form component', () => { ...@@ -319,10 +320,9 @@ describe('issue_note_form component', () => {
textarea.setValue('Foo'); textarea.setValue('Foo');
textarea.trigger('keydown.enter', { metaKey: true }); textarea.trigger('keydown.enter', { metaKey: true });
return nextTick(() => { await nextTick();
expect(wrapper.vm.handleAddToReview).toHaveBeenCalled(); expect(wrapper.vm.handleAddToReview).toHaveBeenCalled();
}); });
}); });
}); });
});
}); });
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