toReceivePaper<U extends UnitWidget<Paper>, S extends UnitWidgetState<Paper, U>> static method

  1. @isTest
void toReceivePaper<U extends UnitWidget<Paper>, S extends UnitWidgetState<Paper, U>>(
  1. String description, {
  2. required U create(
    1. UnitWidgetState<Paper, UnitWidget<Paper>> s
    ),
  3. void setup(
    1. S state,
    2. AgentValidator agentValidator
    )?,
  4. required Paper paper,
  5. required Agent<Paper> from(
    1. S state
    ),
  6. required dynamic expected,
  7. bool? skip,
  8. Timeout? timeout,
  9. bool semanticsEnabled = true,
  10. TestVariant<Object?> variant = const flutter_test.DefaultTestVariant(),
  11. dynamic tags,
  12. int? retry,
  13. LeakTesting? experimentalLeakTesting,
})

Create a test to verify the operations when U unit widget handles paper with the given description. U is type the of target unit. S is the type of corresponding state of U.

create is the method to create the target unit widget. The input s is convenient for inject parent state to the widget.

setup is for initializing and preparing required dependencies for target widget. setup is called at very first. setup is optional.

paper is the paper will be reported by the child from.

from is function to return the agents that will send paper to the widget.

expected is the matcher of the expected paper.

skip is equivalent to skip of testWidgets in flutter_test.

timeout is equivalent to timeout of testWidgets in flutter_test.

semanticsEnabled is equivalent to semanticsEnabled of testWidgets in flutter_test.

variant is equivalent to variant of testWidgets in flutter_test.

tags is equivalent to tags of testWidgets in flutter_test.

retry is equivalent to retry of testWidgets in flutter_test.

experimentalLeakTesting is equivalent to experimentalLeakTesting of testWidgets in flutter_test.

Refer to TestUnitWidget for an example.

Implementation

@isTest
static void toReceivePaper<U extends UnitWidget<Paper>,
    S extends UnitWidgetState<Paper, U>>(
  String description, {
  required U Function(UnitWidgetState s) create,
  void Function(S state, AgentValidator agentValidator)? setup,
  required Paper paper,
  required Agent Function(S state) from,
  required dynamic expected,
  bool? skip,
  flutter_test.Timeout? timeout,
  bool semanticsEnabled = true,
  flutter_test.TestVariant<Object?> variant =
      const flutter_test.DefaultTestVariant(),
  dynamic tags,
  int? retry,
  LeakTesting? experimentalLeakTesting,
}) {
  final tester = UnitTestingEnvironment();
  flutter_test.testWidgets(
    description,
    (flutter_test.WidgetTester widgetTester) async {
      await widgetTester.runAsync(() async {
        await tester.setupTestingUnitWidget(create, widgetTester);
        final state = tester.context?.state;
        final agentValidator = tester.network.agentValidator;

        final child = from(state);
        setup?.call(state, agentValidator);

        if (child is UnitAgent) {
          await child.init();
        }

        final listener = AgentTestingSupporter().getReporter(child);

        final output = await listener?.getPaper(paper);

        flutter_test.expect(output, expected);
      });
    },
    skip: skip,
    timeout: timeout,
    semanticsEnabled: semanticsEnabled,
    variant: variant,
    tags: tags,
    retry: retry,
    experimentalLeakTesting: experimentalLeakTesting,
  );
}