debian-mirror-gitlab/spec/javascripts/dirty_submit/dirty_submit_collection_spec.js

30 lines
975 B
JavaScript
Raw Normal View History

2018-12-13 13:39:08 +05:30
import DirtySubmitCollection from '~/dirty_submit/dirty_submit_collection';
2019-03-02 22:35:43 +05:30
import { setInputValue, createForm } from './helper';
2018-12-13 13:39:08 +05:30
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);
2019-03-02 22:35:43 +05:30
return setInputValue(input, `${originalValue} changes`)
2018-12-13 13:39:08 +05:30
.then(() => {
expect(submit.disabled).toBe(false);
})
2019-03-02 22:35:43 +05:30
.then(() => setInputValue(input, originalValue))
2018-12-13 13:39:08 +05:30
.then(() => {
expect(submit.disabled).toBe(true);
})
.then(done)
.catch(done.fail);
});
});
});