passsy / spot

Chainable powerful Flutter widget selector API, screenshots and assertions for awesome widget tests.
https://pub.dev/packages/spot
Apache License 2.0
62 stars 1 forks source link

spotText #18

Closed passsy closed 1 year ago

passsy commented 1 year ago

Finding text on screen during widget tests is crucial. It's by far the easiest way to navigate through an app. Therefore, a good API for text is extremely important and justifies a breaking change.

Text is different from widgets. With widgets you want to have the exact type and fire assertions against it. Static typing is key.

Text may be presented by different widgets. Text, SelectableText, EditableText or RichText. But regardless of the Widget presenting the text, you want to fire the same assertions against it.

This PR introduces AnyText, an artificial widget combining properties of all known Text presenting widgets.

The new spotText() returns SingleWidgetSelector<AnyText>.

spotText('foo').existsOnce();

Some features about spotText:

If you're interested in the properties of the actual text widget that presents the text use the normal spot method with the generic type T, e.g. Text:

// deprecated
spotSingleText("Hello");
spotSingleText<Text>("Hello");
spotTexts<EditableText>("Hello");

// New
spotText("Hello");
spotText("Hello", exact: true);
spotTextWhere((it) => it.startsWith("He"));

// With exact widget type
spot<Text>().whereText((it) => it.equals("Hello")).first();