// Author: fruit.com.cn import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:fruitshorts/core/data/models/interaction.dart'; import 'package:fruitshorts/l10n/app_localizations.dart'; import 'package:fruitshorts/pages/interaction/widgets/report_dialog.dart'; void main() { testWidgets('should_return_selected_reason_and_description_when_submitted', ( tester, ) async { ReportDialogResult? result; await tester.pumpWidget( MaterialApp( locale: const Locale('en'), localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, home: Builder( builder: (context) => Scaffold( body: TextButton( key: const Key('open-report-dialog'), onPressed: () async { result = await showReportDialog( context, title: 'Report comment', ); }, child: const Text('Open'), ), ), ), ), ); await tester.tap(find.byKey(const Key('open-report-dialog'))); await tester.pumpAndSettle(); expect(find.text('Spam'), findsOneWidget); expect(find.text('Harassment'), findsOneWidget); expect(find.text('Sexual content'), findsOneWidget); expect(find.text('Advertising'), findsOneWidget); expect(find.text('Other'), findsOneWidget); await tester.tap(find.byKey(const Key('report-reason-AD'))); await tester.enterText( find.byKey(const Key('report-description')), 'Repeat promotion', ); await tester.tap(find.byKey(const Key('report-submit'))); await tester.pumpAndSettle(); expect(result?.reason, ReportReason.ad); expect(result?.description, 'Repeat promotion'); }); }