widget_test.dart 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // This is a basic Flutter widget test.
  2. //
  3. // To perform an interaction with a widget in your test, use the WidgetTester
  4. // utility that Flutter provides. For example, you can send tap and scroll
  5. // gestures. You can also use WidgetTester to find child widgets in the widget
  6. // tree, read text, and verify that the values of widget properties are correct.
  7. import 'package:pb_authenticator/l10n/app_localizations.dart';
  8. import 'package:pb_authenticator/pages/acknowledgements.dart';
  9. import 'package:pb_authenticator/state/app_state.dart';
  10. import 'package:pb_authenticator/state/file_storage.dart';
  11. import 'package:pb_authenticator/main.dart';
  12. import 'package:pb_authenticator_state/state.dart';
  13. import 'package:flutter/foundation.dart';
  14. import 'package:flutter/material.dart';
  15. import 'package:flutter_test/flutter_test.dart';
  16. import 'package:provider/provider.dart';
  17. import 'package:flutter_localizations/flutter_localizations.dart'
  18. show GlobalMaterialLocalizations, GlobalWidgetsLocalizations;
  19. void main() {
  20. testWidgets('App launches', (WidgetTester tester) async {
  21. var repository = Repository(FileStorage());
  22. // Build our app and trigger a frame.
  23. await tester.pumpWidget(
  24. MultiProvider(
  25. providers: [
  26. ChangeNotifierProvider(create: (_) => AppState(repository))
  27. ],
  28. child: MainApp(),
  29. ),
  30. );
  31. });
  32. testWidgets('Acknowledgements page', (WidgetTester tester) async {
  33. for (var i = 0; i < 100; i++) {
  34. LicenseRegistry.addLicense(
  35. () => Stream<LicenseEntry>.value(
  36. LicenseEntryWithLineBreaks(<String>['test$i'], '''
  37. TestLicense $i
  38. fff
  39. ''')),
  40. );
  41. }
  42. await tester.pumpWidget(
  43. MaterialApp(
  44. home: Localizations(
  45. delegates: const [
  46. AppLocalizations.delegate,
  47. GlobalMaterialLocalizations.delegate,
  48. GlobalWidgetsLocalizations.delegate,
  49. ],
  50. locale: const Locale('en'),
  51. child: const AcknowledgementsPage(),
  52. )),
  53. );
  54. await tester.pumpAndSettle();
  55. final titleFinder = find.text("Acknowledgements");
  56. expect(titleFinder, findsOneWidget);
  57. final scrollFinder = find.byType(Scrollable);
  58. expect(scrollFinder, findsOneWidget);
  59. // Scroll to end (hopefully)
  60. final listTilesFinder = find.byType(ListTile);
  61. expect(listTilesFinder, findsAny);
  62. await tester.drag(find.byType(ListTile).first, const Offset(0, -10000));
  63. await tester.pumpAndSettle();
  64. final finalItem = find.text("test99");
  65. expect(finalItem, findsOne);
  66. await tester.tap(finalItem);
  67. await tester.pumpAndSettle();
  68. // Page for individual license
  69. final subpageTitleFinder = find.text("test99");
  70. expect(subpageTitleFinder, findsOne);
  71. final subpageTextFinder = find.text("TestLicense 99");
  72. expect(subpageTextFinder, findsOne);
  73. });
  74. }