From 84ca3e763aa24907d390d2494e25af20bef4b3fc Mon Sep 17 00:00:00 2001 From: erinn Date: Fri, 26 Mar 2021 18:02:01 -0700 Subject: [PATCH] introducing widget and integration tests --- .gitignore | 4 +- integration_test/app_test.dart | 26 ++--- lib/main.dart | 39 +------ lib/opaque.dart | 42 ++++++++ lib/views/profilemgrview.dart | 2 +- pubspec.lock | 100 +++++++----------- pubspec.yaml | 10 +- test/buttontextfield01.png | Bin 0 -> 246 bytes test/buttontextfield_test.dart | 62 +++++++++++ test/cwtchlabel01.png | Bin 0 -> 2182 bytes test/cwtchlabel_test.dart | 56 ++++++++++ test/widget_test.dart | 30 ------ {integration_test => test_driver}/driver.dart | 0 13 files changed, 229 insertions(+), 142 deletions(-) create mode 100644 test/buttontextfield01.png create mode 100644 test/buttontextfield_test.dart create mode 100644 test/cwtchlabel01.png create mode 100644 test/cwtchlabel_test.dart delete mode 100644 test/widget_test.dart rename {integration_test => test_driver}/driver.dart (100%) diff --git a/.gitignore b/.gitignore index 437b181..83f6662 100644 --- a/.gitignore +++ b/.gitignore @@ -41,4 +41,6 @@ app.*.symbols app.*.map.json libCwtch.so -android/cwtch/cwtch.aar \ No newline at end of file +android/cwtch/cwtch.aar +coverage +test/failures diff --git a/integration_test/app_test.dart b/integration_test/app_test.dart index 2ca6a16..9dd90a4 100644 --- a/integration_test/app_test.dart +++ b/integration_test/app_test.dart @@ -6,31 +6,33 @@ // tree, read text, and verify that the values of widget properties are correct. import 'package:flutter/material.dart'; +import 'package:flutter_app/views/addeditprofileview.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; import 'package:flutter_app/main.dart' as app; -void main() => run(_testMain); +void main() { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + _testMain(); +} void _testMain() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. + testWidgets('New profile pane smoke test', (WidgetTester tester) async { app.main(); - // Trigger a frame. - await tester.pumpAndSettle(); + await tester.pump(); + await tester.pump(); + await tester.pump(); + //await tester.pumpAndSettle(Duration(seconds: 3), EnginePhase.sendSemanticsUpdate, Duration(seconds: 30)); - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. await tester.tap(find.byIcon(Icons.add)); await tester.pump(); + await tester.pump(); + await tester.pump(); // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); + // expect(find.text('0'), findsNothing); + expect(find.byKey(Key('addprofile')), findsOneWidget); }); } diff --git a/lib/main.dart b/lib/main.dart index f47fdd3..16516b8 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -81,44 +81,7 @@ class FlwtchState extends State { localizationsDelegates: AppLocalizations.localizationsDelegates, supportedLocales: AppLocalizations.supportedLocales, title: 'Cwtch', - theme: ThemeData( - visualDensity: VisualDensity.adaptivePlatformDensity, - primarySwatch: Colors.red, - primaryColor: opaque.current().backgroundMainColor(), - canvasColor: opaque.current().backgroundPaneColor(), - accentColor: opaque.current().defaultButtonColor(), - buttonColor: opaque.current().defaultButtonColor(), - backgroundColor: opaque.current().backgroundMainColor(), - iconTheme: IconThemeData( - color: opaque.current().mainTextColor(), - ), - cardColor: opaque.current().backgroundMainColor(), - textButtonTheme: TextButtonThemeData( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all(opaque.current().defaultButtonColor()), - foregroundColor: MaterialStateProperty.all(opaque.current().defaultButtonTextColor()), - overlayColor: MaterialStateProperty.all(opaque.current().defaultButtonActiveColor()), - padding: MaterialStateProperty.all(EdgeInsets.all(20))), - ), - dialogTheme: DialogTheme( - backgroundColor: opaque.current().backgroundPaneColor(), - titleTextStyle: TextStyle(color: opaque.current().mainTextColor()), - contentTextStyle: TextStyle(color: opaque.current().mainTextColor())), - textTheme: TextTheme( - headline1: TextStyle(color: opaque.current().mainTextColor()), - headline2: TextStyle(color: opaque.current().mainTextColor()), - headline3: TextStyle(color: opaque.current().mainTextColor()), - headline4: TextStyle(color: opaque.current().mainTextColor()), - headline5: TextStyle(color: opaque.current().mainTextColor()), - headline6: TextStyle(color: opaque.current().mainTextColor()), - bodyText1: TextStyle(color: opaque.current().mainTextColor()), - bodyText2: TextStyle(color: opaque.current().mainTextColor()), - subtitle1: TextStyle(color: opaque.current().mainTextColor()), - subtitle2: TextStyle(color: opaque.current().mainTextColor()), - caption: TextStyle(color: opaque.current().mainTextColor()), - button: TextStyle(color: opaque.current().mainTextColor()), - overline: TextStyle(color: opaque.current().mainTextColor())), - ), + theme: mkThemeData(opaque), // from dan: home: cwtchInit == true ? ProfileMgrView(cwtch) : SplashView(), // from erinn: home: columns.length == 3 ? TripleColumnView() : ProfileMgrView(), home: cwtchInit == true ? (columns.length == 3 ? TripleColumnView() : ProfileMgrView()) : SplashView(), diff --git a/lib/opaque.dart b/lib/opaque.dart index 477c599..4373440 100644 --- a/lib/opaque.dart +++ b/lib/opaque.dart @@ -6,6 +6,7 @@ import 'dart:ui'; import 'dart:core'; import 'package:flutter/material.dart'; +import 'package:flutter_app/settings.dart'; abstract class OpaqueThemeType { static final Color red = Color(0xFFFF0000); @@ -1339,3 +1340,44 @@ class Opaque extends OpaqueThemeType { return textMediumPt(); } } + +ThemeData mkThemeData(Settings opaque) { + return ThemeData( + visualDensity: VisualDensity.adaptivePlatformDensity, + primarySwatch: Colors.red, + primaryColor: opaque.current().backgroundMainColor(), + canvasColor: opaque.current().backgroundPaneColor(), + accentColor: opaque.current().defaultButtonColor(), + buttonColor: opaque.current().defaultButtonColor(), + backgroundColor: opaque.current().backgroundMainColor(), + iconTheme: IconThemeData( + color: opaque.current().mainTextColor(), + ), + cardColor: opaque.current().backgroundMainColor(), + textButtonTheme: TextButtonThemeData( + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all(opaque.current().defaultButtonColor()), + foregroundColor: MaterialStateProperty.all(opaque.current().defaultButtonTextColor()), + overlayColor: MaterialStateProperty.all(opaque.current().defaultButtonActiveColor()), + padding: MaterialStateProperty.all(EdgeInsets.all(20))), + ), + dialogTheme: DialogTheme( + backgroundColor: opaque.current().backgroundPaneColor(), + titleTextStyle: TextStyle(color: opaque.current().mainTextColor()), + contentTextStyle: TextStyle(color: opaque.current().mainTextColor())), + textTheme: TextTheme( + headline1: TextStyle(color: opaque.current().mainTextColor()), + headline2: TextStyle(color: opaque.current().mainTextColor()), + headline3: TextStyle(color: opaque.current().mainTextColor()), + headline4: TextStyle(color: opaque.current().mainTextColor()), + headline5: TextStyle(color: opaque.current().mainTextColor()), + headline6: TextStyle(color: opaque.current().mainTextColor()), + bodyText1: TextStyle(color: opaque.current().mainTextColor()), + bodyText2: TextStyle(color: opaque.current().mainTextColor()), + subtitle1: TextStyle(color: opaque.current().mainTextColor()), + subtitle2: TextStyle(color: opaque.current().mainTextColor()), + caption: TextStyle(color: opaque.current().mainTextColor()), + button: TextStyle(color: opaque.current().mainTextColor()), + overline: TextStyle(color: opaque.current().mainTextColor())), + ); +} \ No newline at end of file diff --git a/lib/views/profilemgrview.dart b/lib/views/profilemgrview.dart index b584fdb..5588a25 100644 --- a/lib/views/profilemgrview.dart +++ b/lib/views/profilemgrview.dart @@ -77,7 +77,7 @@ class _ProfileMgrViewState extends State { create: (_) => ProfileInfoState(onion: onion), ), ], - builder: (context, widget) => AddEditProfileView(), + builder: (context, widget) => AddEditProfileView(key: Key('addprofile')), ); }, )); diff --git a/pubspec.lock b/pubspec.lock index fb63563..6528649 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,14 +7,7 @@ packages: name: archive url: "https://pub.dartlang.org" source: hosted - version: "2.0.13" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.6.0" + version: "3.1.2" async: dependency: transitive description: @@ -57,20 +50,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" - convert: - dependency: transitive - description: - name: convert - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.1" crypto: dependency: transitive description: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "2.1.5" + version: "3.0.0" cupertino_icons: dependency: "direct main" description: @@ -104,20 +90,18 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_driver: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" flutter_localizations: dependency: "direct main" description: flutter source: sdk version: "0.0.0" - flutter_lokalise: - dependency: "direct dev" - description: - name: flutter_lokalise - url: "https://pub.dartlang.org" - source: hosted - version: "0.1.4" flutter_test: - dependency: "direct dev" + dependency: "direct main" description: flutter source: sdk version: "0.0.0" @@ -126,20 +110,18 @@ packages: description: flutter source: sdk version: "0.0.0" - freezed_annotation: + fuchsia_remote_debug_protocol: dependency: transitive - description: - name: freezed_annotation - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.0" + description: flutter + source: sdk + version: "0.0.0" http: dependency: transitive description: name: http url: "https://pub.dartlang.org" source: hosted - version: "0.13.0" + version: "0.13.1" http_parser: dependency: transitive description: @@ -147,6 +129,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.0" + integration_test: + dependency: "direct main" + description: + name: integration_test + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.2+2" intl: dependency: transitive description: @@ -161,20 +150,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.6.3" - json_annotation: - dependency: transitive - description: - name: json_annotation - url: "https://pub.dartlang.org" - source: hosted - version: "3.1.1" - logging: - dependency: transitive - description: - name: logging - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.4" matcher: dependency: transitive description: @@ -315,13 +290,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.3.2+3" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.5" sky_engine: dependency: transitive description: flutter @@ -355,6 +323,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.1.0" + sync_http: + dependency: transitive + description: + name: sync_http + url: "https://pub.dartlang.org" + source: hosted + version: "0.3.0" term_glyph: dependency: transitive description: @@ -383,6 +358,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.0" + vm_service: + dependency: transitive + description: + name: vm_service + url: "https://pub.dartlang.org" + source: hosted + version: "6.0.1-nullsafety.1" + webdriver: + dependency: transitive + description: + name: webdriver + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.0" win32: dependency: transitive description: @@ -397,13 +386,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.2.0" - yaml: - dependency: transitive - description: - name: yaml - url: "https://pub.dartlang.org" - source: hosted - version: "2.2.1" sdks: dart: ">=2.12.0 <3.0.0" flutter: ">=1.20.0" diff --git a/pubspec.yaml b/pubspec.yaml index 0319339..7507c4b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,10 +35,18 @@ dependencies: ffi: ^1.0.0 path_provider: ^2.0.0 +# todo: flutter_driver causes version conflict. eg https://github.com/flutter/flutter/issues/44829 + # testing-related deps + integration_test: ^1.0.0 + flutter_test: + sdk: flutter + flutter_driver: + sdk: flutter + dev_dependencies: flutter_test: sdk: flutter - flutter_lokalise: any +# flutter_lokalise: any # alternatively: flutter pub run intl_translation:generate_from_arb --output-dir=lib/l10n --no-use-deferred-loading lib/intl/app_localizations.dart lib/l10n/intl_*.arb --api-token X --project-id Y #flutter_lokalise: diff --git a/test/buttontextfield01.png b/test/buttontextfield01.png new file mode 100644 index 0000000000000000000000000000000000000000..aa1beda1a67555740ba207c55538360ced7315af GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0y~yU^)O~3vjRjNr}FbFM$+eage(c!@6@aAP!5hlV=DA z5Y%v_bO8AaJY5_^D(1YsW+>PkAmAF9FhP(@=K+(bVZ$7W4z8GlMy478-ZSZ+y376c zTSw;<-cGh(zwAJD+_p(S-~XEF_3Y%c|F5Kug-8EpW7x5}KB2u~f!cp|hC7$8+5rv! j=gGj#AmB;?@svGRo2Sis@6x3};}|?${an^LB{Ts5CG|t+ literal 0 HcmV?d00001 diff --git a/test/buttontextfield_test.dart b/test/buttontextfield_test.dart new file mode 100644 index 0000000..e69d278 --- /dev/null +++ b/test/buttontextfield_test.dart @@ -0,0 +1,62 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility that Flutter provides. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_app/opaque.dart'; +import 'package:flutter_app/settings.dart'; +import 'package:flutter_app/widgets/buttontextfield.dart'; +import 'package:flutter_app/widgets/cwtchlabel.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:provider/provider.dart'; + +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +var settingsEnglishDark = Settings(Locale("en", ''), Opaque.dark); +var settingsEnglishLight = Settings(Locale("en", ''), Opaque.light); +ChangeNotifierProvider getSettingsEnglishDark() => ChangeNotifierProvider.value(value: settingsEnglishDark); + +void main() { + testWidgets('CwtchButtonTextField widget test', (WidgetTester tester) async { + final String testingStr = "A wonderful label"; + final TextEditingController ctrlr1 = TextEditingController(text: testingStr); + + // await tester.pumpWidget(MultiProvider( + // providers:[getSettingsEnglishDark()], + // child: Directionality(textDirection: TextDirection.ltr, child: CwtchLabel(label: testingStr)) + // )); + + await tester.pumpWidget(MultiProvider( + providers:[getSettingsEnglishDark()], + builder: (context, child) { return MaterialApp( + locale: Provider.of(context).locale, + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + title: 'Test', + theme: mkThemeData(Provider.of(context)), + home: Card(child: CwtchButtonTextField( + icon: Icon(Icons.bug_report_outlined), + tooltip: testingStr, + controller: ctrlr1, + )), + );} + )); + + // Verify that our counter starts at 0. + expect(find.text(testingStr), findsOneWidget); + expect(find.text('1'), findsNothing); + + await expectLater(find.text(testingStr), matchesGoldenFile('buttontextfield01.png')); + + // Tap the '+' icon and trigger a frame. + // await tester.tap(find.byIcon(Icons.add)); + // await tester.pump(); + // + // // Verify that our counter has incremented. + // expect(find.text('0'), findsNothing); + // expect(find.text('1'), findsOneWidget); + }); +} diff --git a/test/cwtchlabel01.png b/test/cwtchlabel01.png new file mode 100644 index 0000000000000000000000000000000000000000..75279d5418053764bc6f561565b2524b4a8a46eb GIT binary patch literal 2182 zcmeAS@N?(olHy`uVBq!ia0y~yU{+vYV2a>i1B%QlYbpRzjKx9jP7LeL$-D$|Sc;uI zLpXq-h9jkefq}!o)5S5QV$R#^hF;8pB5fC~6PY-jPB8f>ibeKpjlO7_k@?ze%hpoP zut`Zl-5f~@e)C$READVkE*AUn`9Wd#`j=+6g+izPzIyc4wqrrtU%peCHCrmWK<3Wz z9an$HGf1pHd4V5jt6w_zeBST-DbZS`X2AOC31vjqV7W%W+K;=6l!<=2)-i!B}vd=F2DJ7V1 zy6snl-S@wb79YE||7N9(Qqrc|w>D4T|J?4_Uh%+1d#>DK0{UVUjE2By2#kinXb6mk fz=#Zi2FAaPFPL*?-)!p90|kJmtDnm{r-UW|Z5V}> literal 0 HcmV?d00001 diff --git a/test/cwtchlabel_test.dart b/test/cwtchlabel_test.dart new file mode 100644 index 0000000..c5792a9 --- /dev/null +++ b/test/cwtchlabel_test.dart @@ -0,0 +1,56 @@ +// This is a basic Flutter widget test. +// +// To perform an interaction with a widget in your test, use the WidgetTester +// utility that Flutter provides. For example, you can send tap and scroll +// gestures. You can also use WidgetTester to find child widgets in the widget +// tree, read text, and verify that the values of widget properties are correct. + +import 'package:flutter/material.dart'; +import 'package:flutter_app/opaque.dart'; +import 'package:flutter_app/settings.dart'; +import 'package:flutter_app/widgets/cwtchlabel.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:provider/provider.dart'; + +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +var settingsEnglishDark = Settings(Locale("en", ''), Opaque.dark); +var settingsEnglishLight = Settings(Locale("en", ''), Opaque.light); +ChangeNotifierProvider getSettingsEnglishDark() => ChangeNotifierProvider.value(value: settingsEnglishDark); + +void main() { + testWidgets('CwtchLabel widget test', (WidgetTester tester) async { + final String testingStr = "A wonderful label"; + + // await tester.pumpWidget(MultiProvider( + // providers:[getSettingsEnglishDark()], + // child: Directionality(textDirection: TextDirection.ltr, child: CwtchLabel(label: testingStr)) + // )); + + await tester.pumpWidget(MultiProvider( + providers:[getSettingsEnglishDark()], + builder: (context, child) { return MaterialApp( + locale: Provider.of(context).locale, + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + title: 'Test', + theme: mkThemeData(Provider.of(context)), + home: CwtchLabel(label: testingStr), + );} + )); + + // Verify that our counter starts at 0. + expect(find.text(testingStr), findsOneWidget); + expect(find.text('1'), findsNothing); + + await expectLater(find.text(testingStr), matchesGoldenFile('cwtchlabel01.png')); + + // Tap the '+' icon and trigger a frame. + // await tester.tap(find.byIcon(Icons.add)); + // await tester.pump(); + // + // // Verify that our counter has incremented. + // expect(find.text('0'), findsNothing); + // expect(find.text('1'), findsOneWidget); + }); +} diff --git a/test/widget_test.dart b/test/widget_test.dart deleted file mode 100644 index dae7277..0000000 --- a/test/widget_test.dart +++ /dev/null @@ -1,30 +0,0 @@ -// This is a basic Flutter widget test. -// -// To perform an interaction with a widget in your test, use the WidgetTester -// utility that Flutter provides. For example, you can send tap and scroll -// gestures. You can also use WidgetTester to find child widgets in the widget -// tree, read text, and verify that the values of widget properties are correct. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:flutter_app/main.dart'; - -void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { - // Build our app and trigger a frame. - await tester.pumpWidget(Flwtch()); - - // Verify that our counter starts at 0. - expect(find.text('0'), findsOneWidget); - expect(find.text('1'), findsNothing); - - // Tap the '+' icon and trigger a frame. - await tester.tap(find.byIcon(Icons.add)); - await tester.pump(); - - // Verify that our counter has incremented. - expect(find.text('0'), findsNothing); - expect(find.text('1'), findsOneWidget); - }); -} diff --git a/integration_test/driver.dart b/test_driver/driver.dart similarity index 100% rename from integration_test/driver.dart rename to test_driver/driver.dart