From 05f41e16a90bb5e2faf7b5981d7411bf3113f8bc Mon Sep 17 00:00:00 2001 From: poka Date: Thu, 25 Aug 2022 00:26:04 +0200 Subject: [PATCH] improve test speed --- integration_test/gecko_complete.dart | 17 +++++++------- integration_test/tests_utility.dart | 15 ++++++++---- lib/screens/home.dart | 34 ++++++++++++++-------------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/integration_test/gecko_complete.dart b/integration_test/gecko_complete.dart index 0d6723f..07e43c0 100644 --- a/integration_test/gecko_complete.dart +++ b/integration_test/gecko_complete.dart @@ -72,7 +72,6 @@ Future restoreChest(WidgetTester tester) async { // Tap on button to paste mnemonic await goKey(tester, keyPastMnemonic); - await tester.pumpAndSettle(); // Tap on next button 4 times to skip 3 screen await goKey(tester, keyGoNext); @@ -84,16 +83,16 @@ Future restoreChest(WidgetTester tester) async { final isCached = await isIconPresent(tester, Icons.check_box); // If not, tap on to cache password - if (!isCached) await goKey(tester, keyCachePassword); + if (!isCached) await goKey(tester, keyCachePassword, duration: 0); // Enter password - await enterText(tester, keyPinForm, 'AAAAA'); + await enterText(tester, keyPinForm, 'AAAAA', 0); // Check if string "Accéder à mon coffre" is present in screen await waitFor(tester, 'Accéder à mon coffre'); // Go to wallets home - await goKey(tester, keyGoWalletsHome); + await goKey(tester, keyGoWalletsHome, duration: 0); // Check if string "ĞD" is present in screen await waitFor(tester, 'ĞD'); @@ -138,7 +137,7 @@ Future payTest2(WidgetTester tester) async { await spawnBlock(tester, keyCloseTransactionScreen); await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1)); - await goKey(tester, keyCloseTransactionScreen); + await goKey(tester, keyCloseTransactionScreen, duration: 0); await waitFor(tester, '12.14'); await spawnBlock(tester, keyViewActivity); await waitFor(tester, '9.14'); @@ -155,7 +154,7 @@ Future certifyTest5(WidgetTester tester) async { // await sleep(tester); await goKey(tester, keyCertify); await goKey(tester, keyConfirm); - await spawnBlock(tester, keyViewActivity); + await spawnBlock(tester, keyViewActivity, duration: 500); await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1)); await goKey(tester, keyCloseTransactionScreen); await waitFor(tester, 'Identité créée'); @@ -168,7 +167,7 @@ Future certifyTest5(WidgetTester tester) async { await goKey(tester, keyConfirmIdentity); await enterText(tester, keyEnterIdentityUsername, 'test5'); await goKey(tester, keyConfirm); - await spawnBlock(tester, keyCloseTransactionScreen); + await spawnBlock(tester, keyCloseTransactionScreen, duration: 500); await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1)); await goKey(tester, keyCloseTransactionScreen); await waitFor(tester, 'Identité confirmée'); @@ -192,7 +191,7 @@ Future certifyTest5(WidgetTester tester) async { // Certify with test2 account await goKey(tester, keyCertify); await goKey(tester, keyConfirm); - await spawnBlock(tester, keyViewActivity); + await spawnBlock(tester, keyViewActivity, duration: 500); await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1)); await goKey(tester, keyCloseTransactionScreen); await waitFor(tester, '2'); @@ -208,7 +207,7 @@ Future certifyTest5(WidgetTester tester) async { // Certify with test3 account await goKey(tester, keyCertify); await goKey(tester, keyConfirm); - await spawnBlock(tester, keyViewActivity); + await spawnBlock(tester, keyViewActivity, duration: 500); await waitFor(tester, 'validé !', timeout: const Duration(seconds: 1)); await goKey(tester, keyCloseTransactionScreen); await waitFor(tester, 'Vous devez attendre'); diff --git a/integration_test/tests_utility.dart b/integration_test/tests_utility.dart index 50130a6..e3d31a5 100644 --- a/integration_test/tests_utility.dart +++ b/integration_test/tests_utility.dart @@ -12,7 +12,9 @@ Future sleep(WidgetTester tester, [int time = 1000]) async { Future goKey(WidgetTester tester, Key buttonKey, {Finder? customFinder, int duration = 100, bool selectLast = false}) async { - await tester.pumpAndSettle(Duration(milliseconds: duration)); + if (duration != 0) { + await tester.pumpAndSettle(Duration(milliseconds: duration)); + } final Finder finder = customFinder ?? find.byKey(buttonKey); log.d('INTEGRATION TEST: Tap on ${finder.description}}'); await tester.tap(selectLast ? finder.last : finder); @@ -28,7 +30,9 @@ Future goBack(WidgetTester tester) async { Future enterText(WidgetTester tester, Key fieldKey, String textIn, [int duration = 200]) async { - await tester.pumpAndSettle(Duration(milliseconds: duration)); + if (duration != 0) { + await tester.pumpAndSettle(Duration(milliseconds: duration)); + } log.d('INTEGRATION TEST: Enter text: $textIn'); await tester.enterText(find.byKey(fieldKey), textIn); } @@ -73,8 +77,11 @@ Future isIconPresent(WidgetTester tester, IconData icon, return finder.evaluate().isEmpty ? false : true; } -Future spawnBlock(WidgetTester tester, Key customKey, [int number = 1]) async { - await sleep(tester, 1000); +Future spawnBlock(WidgetTester tester, Key customKey, + {int number = 1, int duration = 200}) async { + if (duration != 0) { + await sleep(tester, duration); + } final BuildContext context = tester.element(find.byKey(customKey)); SubstrateSdk sub = Provider.of(context, listen: false); sub.spawnBlock(number); diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 34e47bd..8850781 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -133,23 +133,23 @@ class HomeScreen extends StatelessWidget { // } // TODO: fix random bad network status on startup - // HomeProvider homeProvider = - // Provider.of(ctx, listen: false); - // Connectivity() - // .onConnectivityChanged - // .listen((ConnectivityResult result) async { - // log.d('Network changed: $result'); - // if (result == ConnectivityResult.none) { - // sub.nodeConnected = false; - // await sub.sdk.api.setting.unsubscribeBestNumber(); - // homeProvider.changeMessage( - // "notConnectedToInternet".tr(), 0); - // sub.reload(); - // } else { - // await sub.connectNode(ctx); - // } - // }); - await sub.connectNode(ctx); + HomeProvider homeProvider = + Provider.of(ctx, listen: false); + Connectivity() + .onConnectivityChanged + .listen((ConnectivityResult result) async { + log.d('Network changed: $result'); + if (result == ConnectivityResult.none) { + sub.nodeConnected = false; + await sub.sdk.api.setting.unsubscribeBestNumber(); + homeProvider.changeMessage( + "notConnectedToInternet".tr(), 0); + sub.reload(); + } else { + await sub.connectNode(ctx); + } + }); + // await sub.connectNode(ctx); } // _duniterIndexer.checkIndexerEndpointBackground(); });