Commit 762a1d60 authored by Clement Ho's avatar Clement Ho

Merge branch...

Merge branch '34014-submitting-reply-to-existing-diff-discussion-using-cmd-ctrl-enter-submits-twice-and-refreshes-page' into 'master'

Resolve "Submitting reply to existing diff discussion using Cmd/Ctrl+Enter submits twice and refreshes page"

Closes #34014

See merge request !12352
parents 6ab58866 64b0a799
......@@ -40,7 +40,7 @@ $(document).on('keydown.quick_submit', '.js-quick-submit', (e) => {
e.preventDefault();
const $form = $(e.target).closest('form');
const $submitButton = $form.find('input[type=submit], button[type=submit]');
const $submitButton = $form.find('input[type=submit], button[type=submit]').first();
if (!$submitButton.attr('disabled')) {
$submitButton.trigger('click', [e]);
......
......@@ -40,16 +40,29 @@ import '~/behaviors/quick_submit';
it('disables input of type submit', function() {
const submitButton = $('.js-quick-submit input[type=submit]');
this.textarea.trigger(keydownEvent());
expect(submitButton).toBeDisabled();
});
it('disables button of type submit', function() {
// button doesn't exist in fixture, add it manually
const submitButton = $('<button type="submit">Submit it</button>');
submitButton.insertAfter(this.textarea);
const submitButton = $('.js-quick-submit input[type=submit]');
this.textarea.trigger(keydownEvent());
expect(submitButton).toBeDisabled();
});
it('only clicks one submit', function() {
const existingSubmit = $('.js-quick-submit input[type=submit]');
// Add an extra submit button
const newSubmit = $('<button type="submit">Submit it</button>');
newSubmit.insertAfter(this.textarea);
const oldClick = spyOnEvent(existingSubmit, 'click');
const newClick = spyOnEvent(newSubmit, 'click');
this.textarea.trigger(keydownEvent());
expect(oldClick).not.toHaveBeenTriggered();
expect(newClick).toHaveBeenTriggered();
});
// We cannot stub `navigator.userAgent` for CI's `rake karma` task, so we'll
// only run the tests that apply to the current platform
if (navigator.userAgent.match(/Macintosh/)) {
......
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