2020-04-27 14:09:41 -04:00
|
|
|
import DirtySubmitCollection from '~/dirty_submit/dirty_submit_collection';
|
|
|
|
import { setInputValue, createForm } from './helper';
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
jest.mock('lodash/throttle', () => jest.fn((fn) => fn));
|
2020-04-27 14:09:41 -04:00
|
|
|
|
|
|
|
describe('DirtySubmitCollection', () => {
|
|
|
|
const testElementsCollection = [createForm(), createForm()];
|
2020-12-23 16:10:24 -05:00
|
|
|
const forms = testElementsCollection.map((testElements) => testElements.form);
|
2020-04-27 14:09:41 -04:00
|
|
|
|
|
|
|
new DirtySubmitCollection(forms); // eslint-disable-line no-new
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
it.each(testElementsCollection)('disables submits until there are changes', (testElements) => {
|
2020-04-27 14:09:41 -04:00
|
|
|
const { input, submit } = testElements;
|
|
|
|
const originalValue = input.value;
|
|
|
|
|
|
|
|
expect(submit.disabled).toBe(true);
|
|
|
|
setInputValue(input, `${originalValue} changes`);
|
|
|
|
expect(submit.disabled).toBe(false);
|
|
|
|
setInputValue(input, originalValue);
|
|
|
|
expect(submit.disabled).toBe(true);
|
|
|
|
});
|
|
|
|
});
|