Skip to content

Commit

Permalink
Merge pull request #64 from agonza40/master
Browse files Browse the repository at this point in the history
Fix for a required property check
  • Loading branch information
agonza40 committed Dec 8, 2016
2 parents 09982ae + 3795a73 commit 0812249
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function subModel (model, modelPath) {
if (isArrayItem(pathSeg)) {
return subModel(model, modelPath.items)
}
return subModel(model.properties[pathSeg], pathSeg)
return subModel(model.properties[pathSeg], modelPath)
}

function isRequired (model, id) {
Expand Down
46 changes: 42 additions & 4 deletions tests/reducer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,22 +275,43 @@ describe('reducer', function () {
validationResult: {warnings: [], errors: []},
value: {
foo: {
fooProp: ''
fooProp: 'test'
},
bar: {
baz: {
bazProp: 'test'
}
}
},
baseModel: {
type: 'object',
properties: {
foo: {
type: 'object'
},
bar: {
type: 'object',
properties: {
baz: {
type: 'object',
properties: {
bazProp: {
type: 'string'
}
}
}
},
required: ['baz']
}
},
required: ['foo']
}
}

var changedState = reducer(initialState, {type: actions.CHANGE_VALUE, value: {}, bunsenId: 'foo'})
expect(changedState.value).to.eql({foo: {}})
expect(changedState.value).to.eql({foo: {}, bar: {baz: {bazProp: 'test'}}})
changedState = reducer(initialState, {type: actions.CHANGE_VALUE, value: {}, bunsenId: 'bar.baz'})
expect(changedState.value).to.eql({foo: {fooProp: 'test'}, bar: {baz: {}}})
})

it('preserves empty arrays that are required', function () {
Expand All @@ -299,6 +320,18 @@ describe('reducer', function () {
properties: {
foo: {
type: 'array'
},
bar: {
type: 'object',
properties: {
baz: {
type: 'array',
item: {
type: 'string'
}
}
},
required: ['baz']
}
},
required: ['foo']
Expand All @@ -308,14 +341,19 @@ describe('reducer', function () {
errors: {},
validationResult: {warnings: [], errors: []},
value: {
foo: ['foo item']
foo: ['foo item'],
bar: {
baz: ['baz item']
}
},
baseModel: model,
model
}

var changedState = reducer(initialState, {type: actions.CHANGE_VALUE, value: [], bunsenId: 'foo'})
expect(changedState.value).to.eql({foo: []})
expect(changedState.value).to.eql({foo: [], bar: {baz: ['baz item']}})
changedState = reducer(initialState, {type: actions.CHANGE_VALUE, value: [], bunsenId: 'bar.baz'})
expect(changedState.value).to.eql({foo: ['foo item'], bar: {baz: []}})
})
})

Expand Down

0 comments on commit 0812249

Please sign in to comment.