groupMethod method

Expression groupMethod({
  1. required String widgetName,
  2. required String? builder,
  3. required String goldenName,
  4. required String? lightTheme,
  5. required String? darkTheme,
  6. required List<String> dimensions,
})

Generates a group method that runs the Golden tests.

Implementation

Expression groupMethod({
  required String widgetName,
  required String? builder,
  required String goldenName,
  required String? lightTheme,
  required String? darkTheme,
  required List<String> dimensions,
}) {
  return refer('group').newInstance([
    literalString('$widgetName golden tests'),
    Method(
      (m) => m
        ..body = Block.of(
          [
            ...dimensions.map(
              (dimension) {
                return testWidgetMethod(
                  widgetName: widgetName,
                  builder: builder,
                  goldenName: goldenName,
                  theme: lightTheme,
                  darkTheme: false,
                  dimension: dimension,
                ).statement;
              },
            ),
            if (darkTheme != null)
              ...dimensions.map(
                (dimension) {
                  return testWidgetMethod(
                    widgetName: widgetName,
                    builder: builder,
                    goldenName: goldenName,
                    theme: darkTheme,
                    darkTheme: true,
                    dimension: dimension,
                  ).statement;
                },
              ),
          ],
        ),
    ).closure,
  ]);
}