redux-form
Version:
A higher order component decorator for forms using Redux and React
101 lines (97 loc) • 2.39 kB
JavaScript
import { untouch } from '../actions';
var describeUntouch = function describeUntouch(reducer, expect, _ref) {
var fromJS = _ref.fromJS;
return function () {
it('should unmark fields as touched on untouch', function () {
var state = reducer(fromJS({
foo: {
values: {
myField: 'value',
myOtherField: 'otherValue'
},
fields: {
myField: {
touched: true
},
myOtherField: {
touched: true
}
}
}
}), untouch('foo', 'myField', 'myOtherField'));
expect(state).toEqualMap({
foo: {
values: {
myField: 'value',
myOtherField: 'otherValue'
},
fields: {
myField: {},
myOtherField: {}
}
}
});
});
it('should unmark deep fields as touched on untouch', function () {
var state = reducer(fromJS({
foo: {
values: {
deep: {
myField: 'value',
myOtherField: 'otherValue'
}
},
fields: {
deep: {
myField: {
touched: true
},
myOtherField: {
touched: true
}
}
}
}
}), untouch('foo', 'deep.myField', 'deep.myOtherField'));
expect(state).toEqualMap({
foo: {
values: {
deep: {
myField: 'value',
myOtherField: 'otherValue'
}
},
fields: {
deep: {
myField: {},
myOtherField: {}
}
}
}
});
});
it('should unmark array fields as touched on untouch', function () {
var state = reducer(fromJS({
foo: {
values: {
myFields: ['value', 'otherValue']
},
fields: {
myFields: [{ touched: true }, { touched: true }]
}
}
}), untouch('foo', 'myFields[0]', 'myFields[1]'));
expect(state).toEqualMap({
foo: {
values: {
myFields: ['value', 'otherValue']
},
fields: {
myFields: [{}, {}]
}
}
});
});
};
};
export default describeUntouch;