Resolve "Submitting reply to existing diff discussion using Cmd/Ctrl+Enter submits twice and refreshes page"
This commit is contained in:
parent
6ab588665c
commit
64b0a799f3
|
@ -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,15 +40,28 @@ 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>');
|
this.textarea.trigger(keydownEvent());
|
||||||
submitButton.insertAfter(this.textarea);
|
|
||||||
|
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());
|
this.textarea.trigger(keydownEvent());
|
||||||
expect(submitButton).toBeDisabled();
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue