Commit 64b0a799 authored by Luke "Jared" Bennett's avatar Luke "Jared" Bennett Committed by Clement Ho

Resolve "Submitting reply to existing diff discussion using Cmd/Ctrl+Enter...

Resolve "Submitting reply to existing diff discussion using Cmd/Ctrl+Enter submits twice and refreshes page"
parent 6ab58866
...@@ -40,7 +40,7 @@ $(document).on('keydown.quick_submit', '.js-quick-submit', (e) => { ...@@ -40,7 +40,7 @@ $(document).on('keydown.quick_submit', '.js-quick-submit', (e) => {
e.preventDefault(); e.preventDefault();
const $form = $(e.target).closest('form'); 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')) { if (!$submitButton.attr('disabled')) {
$submitButton.trigger('click', [e]); $submitButton.trigger('click', [e]);
......
...@@ -40,16 +40,29 @@ import '~/behaviors/quick_submit'; ...@@ -40,16 +40,29 @@ import '~/behaviors/quick_submit';
it('disables input of type submit', function() { it('disables input of type submit', function() {
const submitButton = $('.js-quick-submit input[type=submit]'); const submitButton = $('.js-quick-submit input[type=submit]');
this.textarea.trigger(keydownEvent()); this.textarea.trigger(keydownEvent());
expect(submitButton).toBeDisabled(); expect(submitButton).toBeDisabled();
}); });
it('disables button of type submit', function() { it('disables button of type submit', function() {
// button doesn't exist in fixture, add it manually const submitButton = $('.js-quick-submit input[type=submit]');
const submitButton = $('<button type="submit">Submit it</button>');
submitButton.insertAfter(this.textarea);
this.textarea.trigger(keydownEvent()); this.textarea.trigger(keydownEvent());
expect(submitButton).toBeDisabled(); 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 // We cannot stub `navigator.userAgent` for CI's `rake karma` task, so we'll
// only run the tests that apply to the current platform // only run the tests that apply to the current platform
if (navigator.userAgent.match(/Macintosh/)) { 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