Commit 485a0bf7 authored by Phil Hughes's avatar Phil Hughes

Merge branch 'sh-fix-issue-8040-ee' into 'master'

Fix save button not activating when original setting started as null

Closes gitlab-ee#8040

See merge request gitlab-org/gitlab-ce!22820
parents 1109c227 a22fd26e
...@@ -31,7 +31,7 @@ class DirtySubmitForm { ...@@ -31,7 +31,7 @@ class DirtySubmitForm {
updateDirtyInput(event) { updateDirtyInput(event) {
const input = event.target; const input = event.target;
if (!input.dataset.dirtySubmitOriginalValue) return; if (!input.dataset.isDirtySubmitInput) return;
this.updateDirtyInputs(input); this.updateDirtyInputs(input);
this.toggleSubmission(); this.toggleSubmission();
...@@ -65,6 +65,7 @@ class DirtySubmitForm { ...@@ -65,6 +65,7 @@ class DirtySubmitForm {
} }
static initInput(element) { static initInput(element) {
element.dataset.isDirtySubmitInput = true;
element.dataset.dirtySubmitOriginalValue = DirtySubmitForm.inputCurrentValue(element); element.dataset.dirtySubmitOriginalValue = DirtySubmitForm.inputCurrentValue(element);
} }
......
import DirtySubmitForm from '~/dirty_submit/dirty_submit_form'; import DirtySubmitForm from '~/dirty_submit/dirty_submit_form';
import { setInput, createForm } from './helper'; import { setInput, createForm } from './helper';
function expectToToggleDisableOnDirtyUpdate(submit, input) {
const originalValue = input.value;
expect(submit.disabled).toBe(true);
return setInput(input, `${originalValue} changes`)
.then(() => expect(submit.disabled).toBe(false))
.then(() => setInput(input, originalValue))
.then(() => expect(submit.disabled).toBe(true));
}
describe('DirtySubmitForm', () => { describe('DirtySubmitForm', () => {
it('disables submit until there are changes', done => { it('disables submit until there are changes', done => {
const { form, input, submit } = createForm(); const { form, input, submit } = createForm();
const originalValue = input.value;
new DirtySubmitForm(form); // eslint-disable-line no-new new DirtySubmitForm(form); // eslint-disable-line no-new
expect(submit.disabled).toBe(true); return expectToToggleDisableOnDirtyUpdate(submit, input)
.then(done)
.catch(done.fail);
});
return setInput(input, `${originalValue} changes`) it('disables submit until there are changes when initializing with a falsy value', done => {
.then(() => { const { form, input, submit } = createForm();
expect(submit.disabled).toBe(false); input.value = '';
})
.then(() => setInput(input, originalValue)) new DirtySubmitForm(form); // eslint-disable-line no-new
.then(() => {
expect(submit.disabled).toBe(true); return expectToToggleDisableOnDirtyUpdate(submit, input)
})
.then(done) .then(done)
.catch(done.fail); .catch(done.fail);
}); });
......
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