import { generateWidget , assertEqual } from '../test/shared' ; suite ( "Child Builder Tests" , function ( ) { test ( "ListView basic" , function ( ) { const xml = `
    <ListView :childBuilder="item of component.items">
      <Text text="item.title" />
    </ListView>
` ; const expected = `
        ListView(
          children: WidgetHelpers.mapToWidgetList(component.items, (item, index) {
            return Text(
              item.title,
            );
          }),
        )
` ; const generated = generateWidget ( xml ) ; assertEqual ( generated , expected ) ; } ) ; test ( "ListView with stream" , function ( ) { const xml = `
    <ListView :childBuilder="item of component.items | stream">
      <Text text="item.title" />
    </ListView>
` ; const expected = `
        StreamBuilder(
          initialData: null,
          stream: component.items,
          builder: (BuildContext context, componentItemsSnapshot) {
            final componentItemsValue = componentItemsSnapshot.data;
            if (componentItemsValue == null) {
              return Container(width: 0, height: 0);
            }
            return ListView(
              children: WidgetHelpers.mapToWidgetList(componentItemsValue, (item, index) {
                return Text(
                  item.title,
                );
              }),
            );
          },
        )
` ; const generated = generateWidget ( xml ) ; assertEqual ( generated , expected ) ; } ) ; } ) ;