flutter_glove_box icon indicating copy to clipboard operation
flutter_glove_box copied to clipboard

Support asynchronous Scenarios

Open matthew-carroll opened this issue 5 years ago • 3 comments

I'm trying to assemble a golden sheet of button states: normal, pressed, and disabled.

For a pressed button state, I need to orchestrate a tap, but there doesn't appear to be any place within a standard Scenario to do this. A Widget is expected. There should probably be an option for a function that returns Future<Widget> or something like that.

It looks like a DeviceScenario supports onCreate, which might allow for this, but onCreate is not offered for regular scenarios.

matthew-carroll avatar Nov 14 '20 03:11 matthew-carroll

@matthew-carroll I think this can be accomplished with the GoldenBuilder or the DeviceScenario option.

Here is an pseudo-code example with just the golden builder:

testGoldens('GRID: Different weather types without frame', (tester) async {
      final gb = GoldenBuilder.grid(
        columns: 2,
        bgColor: Colors.white,
        widthToHeightRatio: 1,
      )
        ..addScenario(
            'Normal', const WeatherCard(temp: 37, weather: Weather.rain))
       ..addScenario(
            'Pressed', const WeatherCard(key: Key('click_me'), temp: 37, weather: Weather.rain))
       ..addScenario(
            'Disabled',
          const WeatherCard(temp: 25, weather: Weather.cold, enabled: false),
        );

      await tester.pumpWidgetBuilder(
        gb.build(),
        surfaceSize: const Size(500, 500),
      );
      await tester.press(find.byKey(const Key('click_me')));
      await tester.pump(const Duration(milliseconds: 300));

      await screenMatchesGolden(tester, 'weather_types_grid');
});

fatherOfLegends avatar Nov 14 '20 03:11 fatherOfLegends

@coreysprague I think this is a use case we need to document in our examples.

fatherOfLegends avatar Nov 14 '20 03:11 fatherOfLegends

That approach seems to work.

matthew-carroll avatar Nov 14 '20 03:11 matthew-carroll