@@ -817,3 +817,67 @@ describe("JsonSchemaExampleComponent - visibleIf - condition-types (chained cond
817817 } ) ;
818818 } ) ) ;
819819} ) ;
820+
821+
822+ describe ( "JsonSchemaExampleComponent - visibleIf - array items have visibleIf fields" , ( ) => {
823+ let component : JsonSchemaExampleComponent ;
824+ let fixture : ComponentFixture < JsonSchemaExampleComponent > ;
825+
826+ beforeEach ( async ( ( ) => {
827+ TestBed . configureTestingModule ( {
828+ imports : [ SchemaFormModule . forRoot ( ) , HttpClientModule , FormsModule , ReactiveFormsModule ] ,
829+ declarations : [ JsonSchemaExampleComponent ] ,
830+ providers : [
831+ { provide : WidgetRegistry , useClass : DefaultWidgetRegistry } ,
832+ {
833+ provide : SchemaValidatorFactory ,
834+ useClass : ZSchemaValidatorFactory
835+ }
836+ ]
837+ } ) . compileComponents ( ) ;
838+ } ) ) ;
839+
840+ beforeEach ( ( ) => {
841+ fixture = TestBed . createComponent ( JsonSchemaExampleComponent ) ;
842+ component = fixture . componentInstance ;
843+ fixture . detectChanges ( ) ;
844+ } ) ;
845+
846+ beforeEach ( ( ) => {
847+ // select demo sample
848+ const select : HTMLSelectElement = fixture . debugElement . query ( By . css ( "#samples" ) ) . nativeElement ;
849+ select . value = select . options [ 6 ] . value ; // <-- select a new value
850+ select . dispatchEvent ( new Event ( "change" ) ) ;
851+ fixture . detectChanges ( ) ;
852+ } ) ;
853+
854+ it ( `# 1. Test 'VisibleIf' within an element of an array` , async ( ( ) => {
855+ // Visible component shows up if status value is 'Warn' or 'Fail'
856+
857+ fixture . whenStable ( ) . then ( ( ) => {
858+ fixture . detectChanges ( ) ;
859+
860+ // expect page containing a sf-form element
861+ const sf_form = fixture . debugElement . query ( By . css ( "sf-form" ) ) ;
862+ expect ( sf_form ) . toBeTruthy ( ) ;
863+
864+ // Add an element
865+ const _add_button = fixture . debugElement . query ( By . css ( ".array-add-button" ) ) . nativeElement ;
866+ _add_button . click ( ) ;
867+ fixture . detectChanges ( ) ;
868+ // initial state
869+ const _select : HTMLSelectElement = fixture . debugElement . query ( By . css ( "#arrayObject\\.0\\.showHiddenField" ) ) . nativeElement ;
870+ let _input = fixture . debugElement . query ( By . css ( "#arrayObject\\.0\\.visibleTest" ) ) ;
871+ expect ( _select ) . toBeDefined ( ) ;
872+ expect ( _input ) . toBeNull ( ) ;
873+
874+ // change state to make field visible
875+ _select . value = _select . options [ 1 ] . value ;
876+ _select . dispatchEvent ( new Event ( "change" ) ) ;
877+ fixture . detectChanges ( ) ;
878+ _input = fixture . debugElement . query ( By . css ( "#arrayObject\\.0\\.visibleTest" ) ) . nativeElement ;
879+ expect ( _input ) . toBeDefined ( ) ;
880+ } ) ;
881+ } ) ) ;
882+
883+ } ) ;
0 commit comments