Commit c605c798 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch...

Merge branch '217168-close-open-reply-input-fields-in-the-design-view-sidebar-when-leaving-a-new-comment' into 'master'

Close open reply input fields on design when leaving a new comment

See merge request gitlab-org/gitlab!33587
parents 7080bd2e 3691477c
...@@ -117,6 +117,12 @@ export default { ...@@ -117,6 +117,12 @@ export default {
showForm() { showForm() {
this.isFormRendered = true; this.isFormRendered = true;
}, },
handleReplyFormBlur() {
if (this.discussionComment) {
return;
}
this.isFormRendered = false;
},
}, },
createNoteMutation, createNoteMutation,
}; };
...@@ -142,7 +148,7 @@ export default { ...@@ -142,7 +148,7 @@ export default {
v-if="!isFormRendered" v-if="!isFormRendered"
class="qa-discussion-reply" class="qa-discussion-reply"
:button-text="__('Reply...')" :button-text="__('Reply...')"
@onClick="showForm" @onMouseDown="showForm"
/> />
<apollo-mutation <apollo-mutation
v-else v-else
...@@ -161,6 +167,7 @@ export default { ...@@ -161,6 +167,7 @@ export default {
:markdown-preview-path="markdownPreviewPath" :markdown-preview-path="markdownPreviewPath"
@submitForm="mutate" @submitForm="mutate"
@cancelForm="hideForm" @cancelForm="hideForm"
@onBlur="handleReplyFormBlur"
/> />
</apollo-mutation> </apollo-mutation>
</div> </div>
......
...@@ -103,6 +103,7 @@ export default { ...@@ -103,6 +103,7 @@ export default {
@keydown.meta.enter="submitForm" @keydown.meta.enter="submitForm"
@keydown.ctrl.enter="submitForm" @keydown.ctrl.enter="submitForm"
@keyup.esc.stop="cancelComment" @keyup.esc.stop="cancelComment"
@blur="$emit('onBlur')"
> >
</textarea> </textarea>
</template> </template>
......
...@@ -17,6 +17,7 @@ export default { ...@@ -17,6 +17,7 @@ export default {
class="js-vue-discussion-reply btn btn-text-field" class="js-vue-discussion-reply btn btn-text-field"
:title="s__('MergeRequests|Add a reply')" :title="s__('MergeRequests|Add a reply')"
@click="$emit('onClick')" @click="$emit('onClick')"
@mousedown.prevent="$emit('onMouseDown')"
> >
{{ buttonText }} {{ buttonText }}
</button> </button>
......
---
title: Close open reply input fields in the design view sidebar when leaving a new
comment
merge_request: 33587
author:
type: added
...@@ -76,7 +76,7 @@ describe('Design discussions component', () => { ...@@ -76,7 +76,7 @@ describe('Design discussions component', () => {
it('hides reply placeholder and opens form on placeholder click', () => { it('hides reply placeholder and opens form on placeholder click', () => {
createComponent(); createComponent();
findReplyPlaceholder().trigger('click'); findReplyPlaceholder().vm.$emit('onMouseDown');
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(findReplyPlaceholder().exists()).toBe(false); expect(findReplyPlaceholder().exists()).toBe(false);
...@@ -130,4 +130,22 @@ describe('Design discussions component', () => { ...@@ -130,4 +130,22 @@ describe('Design discussions component', () => {
true, true,
); );
}); });
it('closes the form on blur if the form was empty', () => {
createComponent({}, { discussionComment: '', isFormRendered: true });
findReplyForm().vm.$emit('onBlur');
return wrapper.vm.$nextTick().then(() => {
expect(findReplyForm().exists()).toBe(false);
});
});
it('keeps the form open on blur if the form had text', () => {
createComponent({}, { discussionComment: 'test', isFormRendered: true });
findReplyForm().vm.$emit('onBlur');
return wrapper.vm.$nextTick().then(() => {
expect(findReplyForm().exists()).toBe(true);
});
});
}); });
...@@ -39,6 +39,13 @@ describe('Design reply form component', () => { ...@@ -39,6 +39,13 @@ describe('Design reply form component', () => {
expect(findTextarea().element).toEqual(document.activeElement); expect(findTextarea().element).toEqual(document.activeElement);
}); });
it('textarea emits onBlur event on blur', () => {
createComponent();
findTextarea().trigger('blur');
expect(wrapper.emitted('onBlur')).toBeTruthy();
});
it('renders button text as "Comment" when creating a comment', () => { it('renders button text as "Comment" when creating a comment', () => {
createComponent(); createComponent();
......
...@@ -20,7 +20,7 @@ describe('ReplyPlaceholder', () => { ...@@ -20,7 +20,7 @@ describe('ReplyPlaceholder', () => {
wrapper.destroy(); wrapper.destroy();
}); });
it('emits onClick even on button click', () => { it('emits onClick event on button click', () => {
findButton().trigger('click'); findButton().trigger('click');
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
...@@ -30,6 +30,16 @@ describe('ReplyPlaceholder', () => { ...@@ -30,6 +30,16 @@ describe('ReplyPlaceholder', () => {
}); });
}); });
it('emits onMouseDown event on button mousedown', () => {
findButton().trigger('mousedown');
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.emitted()).toEqual({
onMouseDown: [[]],
});
});
});
it('should render reply button', () => { it('should render reply button', () => {
expect(findButton().text()).toEqual(buttonText); expect(findButton().text()).toEqual(buttonText);
}); });
......
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