testStateMatrix function

Future<void> testStateMatrix(
  1. WidgetTester tester,
  2. String name, {
  3. required Map<String, Widget Function()> states,
  4. required void verify(
    1. String stateName
    ),
  5. bool wrapWithMaterialApp = true,
})

Tests a widget across a matrix of states using a custom verification callback.

Implementation

Future<void> testStateMatrix(
  WidgetTester tester,
  String name, {
  required Map<String, Widget Function()> states,
  required void Function(String stateName) verify,
  bool wrapWithMaterialApp = true,
}) async {
  for (final entry in states.entries) {
    final stateName = entry.key;
    final widgetBuilder = entry.value;

    final widget = widgetBuilder();

    // Pump widget, potentially wrapped for context (like Theme)
    await tester.pumpWidget(
      GoldenWrapper(
        wrapWithMaterialApp: wrapWithMaterialApp,
        // Default small size if not specified, implies component testing
        surfaceSize: const Size(800, 600),
        child: widget,
      ),
    );

    await tester.pumpAndSettle();

    // Run verification
    verify(stateName);

    // Cleanup
    await tester.pumpWidget(const SizedBox.shrink());
  }
}