diff options
author | Stan Hu <stanhu@gmail.com> | 2018-11-06 11:48:03 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2018-11-06 11:48:03 +0300 |
commit | a22fd26e4f903e79c55ae1f50513541c61dd71a3 (patch) | |
tree | e35ca97b3e28164a1bd4c4d3497cc87ace8734fc /spec/javascripts/dirty_submit | |
parent | 1109c227e57fac8c53b331b2cda21a87b61970aa (diff) |
Fix save button not activating when original setting started as null
Diffstat (limited to 'spec/javascripts/dirty_submit')
-rw-r--r-- | spec/javascripts/dirty_submit/dirty_submit_form_spec.js | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/spec/javascripts/dirty_submit/dirty_submit_form_spec.js b/spec/javascripts/dirty_submit/dirty_submit_form_spec.js index b7b29190c31..093fec97951 100644 --- a/spec/javascripts/dirty_submit/dirty_submit_form_spec.js +++ b/spec/javascripts/dirty_submit/dirty_submit_form_spec.js @@ -1,23 +1,35 @@ import DirtySubmitForm from '~/dirty_submit/dirty_submit_form'; 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', () => { it('disables submit until there are changes', done => { const { form, input, submit } = createForm(); - const originalValue = input.value; new DirtySubmitForm(form); // eslint-disable-line no-new - expect(submit.disabled).toBe(true); + return expectToToggleDisableOnDirtyUpdate(submit, input) + .then(done) + .catch(done.fail); + }); + + it('disables submit until there are changes when initializing with a falsy value', done => { + const { form, input, submit } = createForm(); + input.value = ''; + + new DirtySubmitForm(form); // eslint-disable-line no-new - return setInput(input, `${originalValue} changes`) - .then(() => { - expect(submit.disabled).toBe(false); - }) - .then(() => setInput(input, originalValue)) - .then(() => { - expect(submit.disabled).toBe(true); - }) + return expectToToggleDisableOnDirtyUpdate(submit, input) .then(done) .catch(done.fail); }); |