Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
describe('QuickForm', () => {
/* eslint-disable react/display-name */
class TestQuickForm extends QuickForm {
getAutoField = () => () => <i>;
getErrorsField = () => () => <i>;
getSubmitField = () => () => <i>;
}
/* eslint-enable react/display-name */
const schema = new SimpleSchemaBridge({
getDefinition: () => {},
messageForError: () => {},
objectKeys: () => ['a', 'b', 'c'],
validator: () => {},
});
describe('when rendered with custom fields', () => {
it('renders `AutoField` for each field', () => {
const wrapper = mount();
expect(wrapper.find('.auto').length).toBeGreaterThan(0);
});
it('renders `ErrorsField`', () => {
const wrapper = mount();
</i></i></i>
it('uses the new validator settings if `validator` changes', () => {
const validator = jest.fn();
wrapper.setProps({
schema: new SimpleSchemaBridge({
getDefinition() {},
messageForError() {},
objectKeys() {},
validator,
}),
});
const validatorA = Symbol();
const validatorB = Symbol();
wrapper.setProps({ validator: validatorA });
wrapper.setProps({ validator: validatorB });
wrapper.setProps({ validator: validatorA });
expect(validator).toHaveBeenCalledTimes(4);
// First call is bridge implementation specific.
describe('QuickForm', () => {
/* eslint-disable react/display-name */
class TestQuickForm extends QuickForm {
getAutoField = () => () => <i>;
getErrorsField = () => () => <i>;
getSubmitField = () => () => <i>;
}
/* eslint-enable react/display-name */
const schema = new SimpleSchemaBridge({
getDefinition: () => {},
messageForError: () => {},
objectKeys: () => ['a', 'b', 'c'],
validator: () => {}
});
describe('when rendered with custom fields', () => {
it('renders `AutoField` for each field', () => {
const wrapper = mount();
expect(wrapper.find('.auto').length).toBeGreaterThan(0);
});
it('renders `ErrorsField`', () => {
const wrapper = mount();
</i></i></i>
it('does not revalidate when `schema` changes', () => {
wrapper.setProps({ schema: new SimpleSchemaBridge(schemaDefinition) });
expect(validator).not.toBeCalled();
});
});
it(`works correctly without '${method}'`, () => {
expect(
SimpleSchemaBridge.check({ ...schema, [method]: null }),
).not.toBeTruthy();
});
});
it('works correctly with schema', () => {
expect(SimpleSchemaBridge.check(schema)).toBeTruthy();
});
describe('ValidatedForm', () => {
const onChange = jest.fn();
const onSubmit = jest.fn(async () => {});
const onValidate = jest.fn((model, error, next) => next());
const validator = jest.fn();
const error = new Error();
const model = { a: 1 };
const schemaDefinition = {
getDefinition() {},
messageForError() {},
objectKeys() {},
validator: () => validator,
};
const schema = new SimpleSchemaBridge(schemaDefinition);
beforeEach(() => {
onValidate.mockClear();
onChange.mockReset();
onSubmit.mockReset();
validator.mockReset();
});
describe('on validation', () => {
let wrapper;
let form;
beforeEach(() => {
wrapper = mount(
,
describe('AutoForm', () => {
const onChangeModel = jest.fn();
const validator = jest.fn();
const onChange = jest.fn();
const onSubmit = jest.fn();
const model = { a: '1' };
const schema = new SimpleSchemaBridge({
getDefinition: () => ({ type: String, defaultValue: '' }),
messageForError: () => {},
objectKeys: () => ['a', 'b', 'c'],
validator: () => validator
});
beforeEach(() => {
onChange.mockReset();
onChangeModel.mockReset();
onSubmit.mockReset();
validator.mockReset();
});
describe('when changed', () => {
const wrapper = mount(
describe('injectName', () => {
const error = new Error();
const onChange = () => {};
const randomId = randomIds();
const state = {
changed: false,
changedMap: {},
submitting: false,
label: true,
disabled: false,
placeholder: false,
showInlineError: true,
};
const schema = new SimpleSchemaBridge({
getDefinition(name) {
return {
fieldA: { type: Object, label: 'FieldA' },
'fieldA.fieldB': { type: Object, label: 'FieldB' },
'fieldA.fieldB.fieldC': { type: String, label: 'FieldC' },
}[name];
},
messageForError() {},
objectKeys(name) {
return {
fieldA: ['FieldB'],
'fieldA.FieldB': ['FieldC'],
'fieldA.FieldB.FieldC': [],
}[name];
describe('connectField', () => {
const error = new Error();
const onChange = jest.fn();
const randomId = randomIds();
const state = {
changed: false,
changedMap: {},
submitting: false,
label: true,
disabled: false,
placeholder: false,
showInlineError: true,
};
const schema = new SimpleSchemaBridge({
getDefinition(name) {
return {
field: { type: Object, label: 'Field' },
'field.subfield': { type: Number, label: 'Subfield' },
another: { type: String, optional: true },
}[name];
},
messageForError() {},
objectKeys(name) {
return {
field: ['subfield'],
'field.subfield': [],
}[name];
},