This repository has been archived by the owner on Feb 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: default boolean false is not accepted (#241)
- Loading branch information
1 parent
5f368b3
commit 2d52bd4
Showing
2 changed files
with
93 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,6 +159,98 @@ describe('SchemaForm', () => { | |
}) | ||
}) | ||
|
||
describe('default schema values', () => { | ||
it('populates the formModel with the schema when created if a default prop exists', () => { | ||
const schema = { | ||
firstName: { | ||
component: FormText, | ||
label: 'First Name', | ||
default: 'Darth' | ||
}, | ||
lastName: { | ||
component: FormText, | ||
label: 'Last Name', | ||
default: 'Vader' | ||
}, | ||
contact: { | ||
component: SchemaForm, | ||
schema: { | ||
email: { | ||
component: FormText, | ||
label: 'Email', | ||
default: '[email protected]' | ||
}, | ||
address: { | ||
FormText, | ||
label: 'Address' | ||
}, | ||
deepNest: { | ||
component: SchemaForm, | ||
schema: { | ||
lightSaber: { | ||
component: FormText, | ||
label: 'Lightsaber', | ||
default: 'Red' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const formModel = ref({}) | ||
|
||
mount(SchemaWrapperFactory(schema, {}, formModel)) | ||
expect(formModel.value).toEqual({ | ||
firstName: 'Darth', | ||
lastName: 'Vader', | ||
contact: { | ||
email: '[email protected]', | ||
deepNest: { | ||
lightSaber: 'Red' | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
it('can set default schema values to boolean false', () => { | ||
const schema = { | ||
firstName: { | ||
component: FormText, | ||
label: 'First Name', | ||
default: false | ||
}, | ||
contact: { | ||
component: SchemaForm, | ||
schema: { | ||
deepNest: { | ||
component: SchemaForm, | ||
schema: { | ||
lightSaber: { | ||
component: FormText, | ||
label: 'Lightsaber', | ||
default: false | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const formModel = ref({}) | ||
|
||
mount(SchemaWrapperFactory(schema, {}, formModel)) | ||
expect(formModel.value).toEqual({ | ||
firstName: false, | ||
contact: { | ||
deepNest: { | ||
lightSaber: false | ||
} | ||
} | ||
}) | ||
}) | ||
}) | ||
|
||
it('renders a form with multiple nested schemas at the same nesting level', () => { | ||
const nestedSchema = { | ||
work: { | ||
|
@@ -206,59 +298,6 @@ describe('SchemaForm', () => { | |
expect(wrapper.findAllComponents(FormSelect)).toHaveLength(2) | ||
}) | ||
|
||
it('populates the formModel with the schema when created if a default prop exists', () => { | ||
const schema = { | ||
firstName: { | ||
component: FormText, | ||
label: 'First Name', | ||
default: 'Darth' | ||
}, | ||
lastName: { | ||
component: FormText, | ||
label: 'Last Name', | ||
default: 'Vader' | ||
}, | ||
contact: { | ||
component: SchemaForm, | ||
schema: { | ||
email: { | ||
component: FormText, | ||
label: 'Email', | ||
default: '[email protected]' | ||
}, | ||
address: { | ||
FormText, | ||
label: 'Address' | ||
}, | ||
deepNest: { | ||
component: SchemaForm, | ||
schema: { | ||
lightSaber: { | ||
component: FormText, | ||
label: 'Lightsaber', | ||
default: 'Red' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
const formModel = ref({}) | ||
|
||
mount(SchemaWrapperFactory(schema, {}, formModel)) | ||
expect(formModel.value).toEqual({ | ||
firstName: 'Darth', | ||
lastName: 'Vader', | ||
contact: { | ||
email: '[email protected]', | ||
deepNest: { | ||
lightSaber: 'Red' | ||
} | ||
} | ||
}) | ||
}) | ||
|
||
describe('a11y', () => { | ||
it('injects a unique id to each component', () => { | ||
const schema = { | ||
|