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.
feat: lookup plugin replace SchemaForm with plugin version in sub sch…
…emas closes #224 (#229) * chore: move e2es to their own folder and extract comps * feat: allow asking SchemaForm to replace nested SchemaForms with plugin enhanced version * chore: remove unused import and console log * chore: attempt to fix CI * docs: lookupSubSchemas Co-authored-by: Abdelrahman Awad <[email protected]>
- Loading branch information
1 parent
f54de3f
commit 90577e7
Showing
10 changed files
with
166 additions
and
33 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
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
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
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
73 changes: 73 additions & 0 deletions
73
packages/formvuelate/tests/e2e/specs/SchemaFormFactory.e2e.js
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { mount } from '@cypress/vue' | ||
|
||
import { h, ref, shallowRef } from 'vue' | ||
import { SchemaFormFactory, useSchemaForm } from '../../../src/index' | ||
import LookupPlugin, { lookupSubSchemas } from '../../../../plugin-lookup/src/index' | ||
import { BaseInput } from '../../utils/components' | ||
|
||
describe('SchemaFormFactory', () => { | ||
describe('with lookup plugin', () => { | ||
it('parses subschema SchemaForm elements', () => { | ||
const SCHEMA = [ | ||
{ | ||
model: 'firstName', | ||
component: 'Text', | ||
label: 'First Name' | ||
}, | ||
{ | ||
model: 'nested', | ||
component: 'SchemaForm', | ||
schema: [ | ||
{ | ||
model: 'nestedfirstName', | ||
component: 'Text', | ||
label: 'First Name nested' | ||
}, | ||
{ | ||
model: 'nestedLastName', | ||
component: BaseInput, | ||
label: 'Last name nested' | ||
}, | ||
{ | ||
model: 'doubleNested', | ||
component: 'SchemaForm', | ||
schema: [ | ||
{ | ||
model: 'doubleNestedName', | ||
component: 'Text', | ||
label: 'Double nested text' | ||
} | ||
] | ||
} | ||
] | ||
} | ||
] | ||
|
||
const SchemaFormWithPlugins = SchemaFormFactory([ | ||
LookupPlugin({ | ||
mapComponents: { | ||
Text: BaseInput | ||
} | ||
}) | ||
]) | ||
|
||
mount({ | ||
components: { SchemaFormWithPlugins }, | ||
setup () { | ||
const model = ref({}) | ||
lookupSubSchemas(SchemaFormWithPlugins) | ||
useSchemaForm(model) | ||
|
||
const schemaRef = shallowRef(SCHEMA) | ||
|
||
return () => h(SchemaFormWithPlugins, { | ||
schema: schemaRef | ||
}) | ||
} | ||
}) | ||
|
||
cy.get('input').should('have.length', 4) | ||
cy.get('label').eq(3).should('have.text', 'Double nested text') | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { h } from 'vue' | ||
|
||
export const BaseInput = { | ||
props: ['label', 'modelValue'], | ||
render () { | ||
return [ | ||
h('label', this.label), | ||
h('input', { | ||
...this.$attrs, | ||
value: this.modelValue, | ||
onInput: ($event) => this.$emit('update:modelValue', $event.target.value) | ||
}) | ||
] | ||
} | ||
} |
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