lundi 27 juillet 2020

How to test the content of multiple list items in Flutter / Dart?

Intro

We have a ListView named OrganizationList which contains a ListTile widget for every item. We use a Text widget to display the name of the organization inside the ListTile.

We would like to test if the organization name is displayed correctly and in the correct order.

Our current solution

We have the following assertions:

var organizationA = find
    .descendant(
        of: find.byType(OrganizationList),
        matching: find.byKey(
            Key('0'),
        ),
     )
     .evaluate()
     .first
     .widget as Text;
expect(textOrganization.data, 'organization-a');

var organizationB = find
    .descendant(
        of: find.byType(OrganizationList),
        matching: find.byKey(
            Key('1'),
        ),
     )
     .evaluate()
     .first
     .widget as Text;
expect(textOrganization.data, 'organization-b');

This feels like a very cumbersome way of testing if the right label is shown for the list items. But I fail to find a more elegant way.

Question

What is a more elegant way in Flutter / Dart to assert both the content of a list item and the order of all items?

Aucun commentaire:

Enregistrer un commentaire