2018-10-15 09:36:19 -04:00
|
|
|
import DirtySubmitCollection from '~/dirty_submit/dirty_submit_collection';
|
2018-11-14 14:51:39 -05:00
|
|
|
import { setInputValue, createForm } from './helper';
|
2018-10-15 09:36:19 -04:00
|
|
|
|
|
|
|
describe('DirtySubmitCollection', () => {
|
|
|
|
it('disables submits until there are changes', done => {
|
|
|
|
const testElementsCollection = [createForm(), createForm()];
|
|
|
|
const forms = testElementsCollection.map(testElements => testElements.form);
|
|
|
|
|
|
|
|
new DirtySubmitCollection(forms); // eslint-disable-line no-new
|
|
|
|
|
|
|
|
testElementsCollection.forEach(testElements => {
|
|
|
|
const { input, submit } = testElements;
|
|
|
|
const originalValue = input.value;
|
|
|
|
|
|
|
|
expect(submit.disabled).toBe(true);
|
|
|
|
|
2018-11-14 14:51:39 -05:00
|
|
|
return setInputValue(input, `${originalValue} changes`)
|
2018-10-09 14:03:09 -04:00
|
|
|
.then(() => {
|
|
|
|
expect(submit.disabled).toBe(false);
|
|
|
|
})
|
2018-11-14 14:51:39 -05:00
|
|
|
.then(() => setInputValue(input, originalValue))
|
2018-10-09 14:03:09 -04:00
|
|
|
.then(() => {
|
|
|
|
expect(submit.disabled).toBe(true);
|
|
|
|
})
|
2018-10-15 09:36:19 -04:00
|
|
|
.then(done)
|
|
|
|
.catch(done.fail);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|