Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Commit

Permalink
fix: model cleanup not working with nested schemas (fix #227) (#228)
Browse files Browse the repository at this point in the history
* fix: model cleanup not working with nested schemas (fix #227)

* test: add model cleanup with nested schemas unit test
  • Loading branch information
victorlambert authored Sep 8, 2021
1 parent c6dca75 commit 24be6e0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/formvuelate/src/utils/Helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const deleteFormModelProperty = (formModel, prop, path) => {
return
}

delete findNestedFormModelProp(path)[prop]
delete findNestedFormModelProp(formModel, path)[prop]
}

/**
Expand Down
47 changes: 47 additions & 0 deletions packages/formvuelate/tests/unit/SchemaForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,53 @@ describe('SchemaForm', () => {
})

describe('handling nested schemas', () => {
it('cleans up the model', async () => {
const schema = {
firstName: {
component: FormText,
label: 'First Name'
},
lastName: {
component: FormText,
label: 'Last Name'
},
properties: {
component: SchemaForm,
schema: {
favoriteThingAboutVue: {
component: FormSelect,
label: 'Favorite thing about Vue',
required: true,
condition: model => !!model.firstName,
options: ['Ease of use', 'Documentation', 'Community']
}
}
}
}

const formModel = ref({
firstName: 'Victor',
lastName: 'Lambert',
properties: {
favoriteThingAboutVue: 'Community'
}
})

const wrapper = mount(SchemaWrapperFactory(schema, null, formModel))

const copySchema = { ...schema }
delete copySchema.firstName
wrapper.setProps({
schema: copySchema
})
await wrapper.vm.$nextTick()

expect(formModel.value).toEqual({
lastName: 'Lambert',
properties: {}
})
})

it('injects the nestedSchemaModel prop as part of the path', () => {
const schema = {
firstName: {
Expand Down

0 comments on commit 24be6e0

Please sign in to comment.