import { Parser } from '@/parsers/Parser' ; import { NativeElements } from '@/lib/NativeElements' ; import { InputElement } from '@/components/InputElement' ; import { TestParser , Scope } from '../../lib/TestParser' ; describe ( 'descriptors/ScalarUIDescriptor' , ( ) => { TestParser . Case ( { case : '1.0' , description : 'generic scalar field' , given : { parser : Parser . get ( { schema : { type : 'string' } , model : 'Jon Snow' , name : 'name' , required : true , descriptor : { label : 'Name' , helper : 'Your Name' , props : { } , attrs : { id : 'name' } } } ) } , expected : { parser : { field : { kind : ( { value } ) => expect ( value ) . toBe ( 'string' ) , value : ( { value , parser : { options } } ) => expect ( value ) . toEqual ( options . model ) , attrs : { id : ( { value , options } ) => expect ( value . startsWith ( `${ options . name }-` ) ) . toBeTruthy ( ) , type : ( { value } ) => expect ( value ) . toBe ( 'text' ) , name : ( { value , options } ) => expect ( value ) . toBe ( options . name ) , required : ( { value , options } ) => expect ( value ) . toBe ( options . required ) } , descriptor : { kind : ( { value , parser } ) => expect ( value ) . toBe ( parser . field . kind ) , label : ( { value , options } ) => expect ( value ) . toBe ( options . descriptor . label ) , helper : ( { value , options } ) => expect ( value ) . toBe ( options . descriptor . helper ) , components : ( { value } ) => expect ( value ) . toBe ( NativeElements ) , component : ( { value } ) => expect ( value ) . toBe ( InputElement ) , props : ( { value , options } ) => expect ( value ) . toEqual ( options . descriptor . props ) , attrs ( { value , field , options , descriptor } ) { expect ( value ) . not . toEqual ( field . attrs ) ; expect ( value . id ) . toBe ( options . descriptor . attrs . id ) ; expect ( value [ 'aria-labelledby' ] ) . toBe ( descriptor . labelAttrs . id ) ; expect ( value [ 'aria-describedby' ] ) . toBe ( descriptor . helperAttrs . id ) ; } , labelAttrs : { id : ( { value } ) => expect ( value ) . toBeDefined ( ) , for : ( { value } ) => expect ( value ) . toBeDefined ( ) } , helperAttrs : { id : ( { value } ) => expect ( value ) . toBeDefined ( ) } } } } } } ) ; TestParser . Case ( { case : '2.0' , description : 'hidden field' , given : { parser : Parser . get ( { schema : { type : 'string' } , model : 'Jon Snow' , name : 'name' , required : true , descriptor : { kind : 'hidden' , label : 'Name' , helper : 'Your Name' , props : { } , attrs : { id : 'name' } } } ) } , expected : { parser : { field : { attrs : { id : ( { value , options } ) => expect ( value . startsWith ( `${ options . name }-` ) ) . toBeTruthy ( ) , type : ( { value } ) => expect ( value ) . toBe ( 'hidden' ) , name : ( { value , options } ) => expect ( value ) . toBe ( options . name ) , required : ( { value , options } ) => expect ( value ) . toBe ( options . required ) } , descriptor : { attrs : { id : ( { value , options } ) => expect ( value ) . toBe ( options . descriptor . attrs . id ) , 'aria-labelledby' : ( { value , descriptor } ) => expect ( value ) . toBe ( descriptor . labelAttrs . id ) , 'aria-describedby' : ( { value , descriptor } ) => expect ( value ) . toBe ( descriptor . helperAttrs . id ) } , kind : ( { value , parser } ) => expect ( value ) . toBe ( parser . field . kind ) , label : ( { value , options } ) => expect ( value ) . toBe ( options . descriptor . label ) , helper : ( { value , options } ) => expect ( value ) . toBe ( options . descriptor . helper ) , component : ( { value } ) => expect ( value ) . toBe ( 'input' ) } } } } } ) ; } ) ;