Commit bbdc62ce authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '25429-fix-disabled-quick-actions-in-notes' into 'master'

Make note posting aware of disabled quick actions

Closes #25429

See merge request gitlab-org/gitlab!36563
parents 313d1118 f261928d
......@@ -106,4 +106,8 @@ export default class GLForm {
.removeClass('is-focused');
});
}
get supportsQuickActions() {
return Boolean(this.textarea.data('supports-quick-actions'));
}
}
......@@ -1617,7 +1617,7 @@ export default class Notes {
}
tempFormContent = formContent;
if (this.hasQuickActions(formContent)) {
if (this.glForm.supportsQuickActions && this.hasQuickActions(formContent)) {
tempFormContent = this.stripQuickActions(formContent);
hasQuickActions = true;
}
......
---
title: Snippet comments where any line begins with a slash following an alphabetic character can't be published
merge_request: 36563
type: fixed
......@@ -111,5 +111,21 @@ describe('GLForm', () => {
expect(autosize.destroy).not.toHaveBeenCalled();
});
});
describe('supportsQuickActions', () => {
it('should return false if textarea does not support quick actions', () => {
const glForm = new GLForm(testContext.form, false);
expect(glForm.supportsQuickActions).toEqual(false);
});
it('should return true if textarea supports quick actions', () => {
testContext.textarea.attr('data-supports-quick-actions', true);
const glForm = new GLForm(testContext.form, false);
expect(glForm.supportsQuickActions).toEqual(true);
});
});
});
});
......@@ -624,7 +624,7 @@ describe.skip('Old Notes (~/notes.js)', () => {
});
});
describe('postComment with Slash commands', () => {
describe('postComment with quick actions', () => {
const sampleComment = '/assign @root\n/award :100:';
const note = {
commands_changes: {
......@@ -640,6 +640,7 @@ describe.skip('Old Notes (~/notes.js)', () => {
let $notesContainer;
beforeEach(() => {
loadFixtures('commit/show.html');
mockAxios.onPost(NOTES_POST_PATH).reply(200, note);
new Notes('', []);
......@@ -659,14 +660,49 @@ describe.skip('Old Notes (~/notes.js)', () => {
$form.find('textarea.js-note-text').val(sampleComment);
});
it('should remove slash command placeholder when comment with slash commands is done posting', done => {
it('should remove quick action placeholder when comment with quick actions is done posting', done => {
jest.spyOn(gl.awardsHandler, 'addAwardToEmojiBar');
$('.js-comment-button').click();
expect($notesContainer.find('.system-note.being-posted').length).toEqual(1); // Placeholder shown
expect($notesContainer.find('.note.being-posted').length).toEqual(1); // Placeholder shown
setImmediate(() => {
expect($notesContainer.find('.system-note.being-posted').length).toEqual(0); // Placeholder removed
expect($notesContainer.find('.note.being-posted').length).toEqual(0); // Placeholder removed
done();
});
});
});
describe('postComment with slash when quick actions are not supported', () => {
const sampleComment = '/assign @root';
let $form;
let $notesContainer;
beforeEach(() => {
const note = {
id: 1234,
html: `<li class="note note-row-1234 timeline-entry" id="note_1234">
<div class="note-text">${sampleComment}</div>
</li>`,
note: sampleComment,
valid: true,
};
mockAxios.onPost(NOTES_POST_PATH).reply(200, note);
new Notes('', []);
$form = $('form.js-main-target-form');
$notesContainer = $('ul.main-notes-list');
$form.find('textarea.js-note-text').val(sampleComment);
});
it('should show message placeholder including lines starting with slash', done => {
$('.js-comment-button').click();
expect($notesContainer.find('.note.being-posted').length).toEqual(1); // Placeholder shown
expect($notesContainer.find('.note-body p').text()).toEqual(sampleComment); // No quick action processing
setImmediate(() => {
expect($notesContainer.find('.note.being-posted').length).toEqual(0); // Placeholder removed
done();
});
});
......
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