import {change} from '../actions'
const describeChange = (reducer, expect, {fromJS}) => () => {
it('should set value on change with empty state', () => {
const state = reducer(undefined, {
...change('myValue'),
form: 'foo',
field: 'myField'
})
expect(state)
.toEqualMap({
foo: {
values: {
myField: 'myValue'
}
}
})
})
it('should set value on change and touch with empty state', () => {
const state = reducer(undefined, {
...change('myValue'),
form: 'foo',
field: 'myField',
touch: true
})
expect(state)
.toEqualMap({
foo: {
values: {
myField: 'myValue'
},
fields: {
myField: {
touched: true
}
}
}
})
})
it('should set value on change and touch with initial value', () => {
const state = reducer(fromJS({
foo: {
values: {
myField: 'initialValue'
},
initial: {
myField: 'initialValue'
}
}
}), {
...change('myValue'),
form: 'foo',
field: 'myField',
touch: true
})
expect(state)
.toEqualMap({
foo: {
values: {
myField: 'myValue'
},
initial: {
myField: 'initialValue'
},
fields: {
myField: {
touched: true
}
}
}
})
})
it('should set value on change and remove field-level submit and async errors', () => {
const state = reducer(fromJS({
foo: {
values: {
myField: 'initial'
},
fields: {
myField: {
submitError: 'submit error',
asyncError: 'async error'
}
},
error: 'some global error'
}
}), {
...change('different'),
form: 'foo',
field: 'myField'
})
expect(state)
.toEqualMap({
foo: {
values: {
myField: 'different'
},
fields: {
myField: {}
},
error: 'some global error' // unaffected by CHANGE
}
})
})
it('should set nested value on change with empty state', () => {
const state = reducer(undefined, {
...change('myValue'),
form: 'foo',
field: 'myField.mySubField'
})
expect(state)
.toEqualMap({
foo: {
values: {
myField: {
mySubField: 'myValue'
}
}
}
})
})
}
export default describeChange
|