1+ import { expect , it , describe , beforeAll } from 'vitest'
2+ import { config , mount } from '@vue/test-utils'
3+
4+ import FormGenerator from '@/FormGenerator.vue'
5+ import FieldText from '@/fields/core/FieldText.vue'
6+ import FieldTextarea from '@/fields/core/FieldTextarea.vue'
7+ import FieldSubmit from '@/fields/core/FieldSubmit.vue'
8+ import { generateSchemaSingleField } from '@test/_resources/utils.js'
9+
10+ beforeAll ( ( ) => {
11+ config . global . components = { FieldText, FieldTextarea, FieldSubmit }
12+ } )
13+
14+ const textSchema = generateSchemaSingleField (
15+ 'text' ,
16+ 'textModel' ,
17+ 'input' ,
18+ 'text' ,
19+ 'Text input label' ,
20+ '' ,
21+ {
22+ required : true
23+ }
24+ )
25+
26+ const textAreaSchema = generateSchemaSingleField (
27+ 'textArea' ,
28+ 'textAreaModel' ,
29+ 'textarea' ,
30+ null ,
31+ 'Text area label' ,
32+ '' ,
33+ { }
34+ )
35+
36+ const schema = {
37+ schema : { fields : [ ...textSchema . schema . fields , ...textAreaSchema . schema . fields ] } ,
38+ model : { ...textSchema . model , ...textAreaSchema . model }
39+ }
40+
41+ describe ( 'FormGenerator' , ( ) => {
42+
43+ it ( 'Shouldn\'t render without a schema' , async ( ) => {
44+ const wrapper = mount ( FormGenerator )
45+ expect ( wrapper . find ( 'form' ) . exists ( ) ) . toBeFalsy ( )
46+ } )
47+
48+ it ( 'Should render with a schema' , async ( ) => {
49+ const wrapper = mount ( FormGenerator , { props : { model : schema . model , schema : schema . schema } } )
50+ expect ( wrapper . find ( 'form' ) . exists ( ) ) . toBeTruthy ( )
51+ expect ( wrapper . findComponent ( FieldText ) . exists ( ) ) . toBeTruthy ( )
52+ expect ( wrapper . findComponent ( FieldTextarea ) . exists ( ) ) . toBeTruthy ( )
53+ } )
54+
55+ } )
0 commit comments