From c33e78b4fdb125af674aa2b83c26eaf6424d426b Mon Sep 17 00:00:00 2001 From: lukorito Date: Thu, 9 Nov 2023 01:50:39 +0300 Subject: [PATCH] fix failing test --- Makefile | 2 +- lib/home/sections/get_test_tokens.dart | 511 +++++++++--------- lib/requests/providers/requests_provider.dart | 11 +- .../requests/desktop_request_failed_test.dart | 8 +- test/requests/mobile_request_failed_test.dart | 11 +- test/requests/required_request_tests.dart | 13 + test/requests/tablet_request_failed_test.dart | 58 ++ 7 files changed, 343 insertions(+), 271 deletions(-) diff --git a/Makefile b/Makefile index ec8c297..d4d30f2 100644 --- a/Makefile +++ b/Makefile @@ -108,4 +108,4 @@ web_build_and_host: file_test: @reset - @flutter test test/requests/requests_test.dart \ No newline at end of file + @flutter test test/requests/mobile_request_failed_test.dart \ No newline at end of file diff --git a/lib/home/sections/get_test_tokens.dart b/lib/home/sections/get_test_tokens.dart index 0d10513..5d71e9e 100644 --- a/lib/home/sections/get_test_tokens.dart +++ b/lib/home/sections/get_test_tokens.dart @@ -46,222 +46,223 @@ class GetTestTokens extends HookConsumerWidget { return Container( decoration: BoxDecoration(color: getSelectedColor(colorTheme, 0xFFFFFFFF, 0xFF282A2C)), child: Padding( - padding: EdgeInsets.all(isMobile ? 16.0 : 40.0), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - Strings.getTestNetwork, - style: headlineLarge(context), - ), - const SizedBox( - height: 48, - ), - Container( - height: 64, - width: 560, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8), - color: const Color.fromRGBO(112, 64, 236, 0.04), - ), - child: Row( - children: [ - const SizedBox(width: 16), - Icon( - Icons.warning_amber, - color: getSelectedColor(colorTheme, 0xFF7040EC, 0xFF7040EC), - size: 24, + padding: EdgeInsets.all(isMobile ? 16.0 : 40.0), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + Strings.getTestNetwork, + style: headlineLarge(context), + ), + const SizedBox( + height: 48, + ), + Container( + height: 64, + width: 560, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8), + color: const Color.fromRGBO(112, 64, 236, 0.04), ), - const SizedBox(width: 16), - Expanded( - child: SizedBox( - width: 450, - child: Text( - 'Confirm details before submitting', - style: TextStyle( - fontSize: 14, - fontFamily: 'Rational Display', - fontWeight: FontWeight.w300, - color: getSelectedColor(colorTheme, 0xFF7040EC, 0xFF7040EC), + child: Row( + children: [ + const SizedBox(width: 16), + Icon( + Icons.warning_amber, + color: getSelectedColor(colorTheme, 0xFF7040EC, 0xFF7040EC), + size: 24, + ), + const SizedBox(width: 16), + Expanded( + child: SizedBox( + width: 450, + child: Text( + 'Confirm details before submitting', + style: TextStyle( + fontSize: 14, + fontFamily: 'Rational Display', + fontWeight: FontWeight.w300, + color: getSelectedColor(colorTheme, 0xFF7040EC, 0xFF7040EC), + ), + ), ), ), - ), - ), - ], - ), - ), - const SizedBox( - height: 48, - ), - TextField( - key: lvlInputKey, - controller: TextEditingController(text: 'LVL'), - enabled: false, - style: bodyMedium(context), - decoration: InputDecoration( - labelText: 'Tokens', - labelStyle: bodyMedium(context), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - borderSide: BorderSide( - color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), + ], ), ), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - borderSide: BorderSide( - color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), - ), + const SizedBox( + height: 48, ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - borderSide: BorderSide( - color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), + TextField( + key: lvlInputKey, + controller: TextEditingController(text: 'LVL'), + enabled: false, + style: bodyMedium(context), + decoration: InputDecoration( + labelText: 'Tokens', + labelStyle: bodyMedium(context), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide( + color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), + ), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide( + color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), + ), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide( + color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), + ), + ), ), ), - ), - ), - const SizedBox( - height: 24, - ), - DropdownButton2( - key: selectNetworkKey, - hint: const Text( - 'Select a Network', - style: TextStyle( - fontSize: 16, - fontFamily: 'Rational Display', - color: Color(0xFF858E8E), + const SizedBox( + height: 24, ), - ), - style: bodyMedium(context), - underline: Container( - height: 0, - ), - buttonStyleData: ButtonStyleData( - height: 56, - width: 560, - padding: const EdgeInsets.only(left: 14, right: 14), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8.0), - border: Border.all( - color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF4B4B4B), + DropdownButton2( + key: selectNetworkKey, + hint: const Text( + 'Select a Network', + style: TextStyle( + fontSize: 16, + fontFamily: 'Rational Display', + color: Color(0xFF858E8E), + ), ), - color: getSelectedColor(colorTheme, 0xFFFEFEFE, 0xFF282A2C), - ), - ), - dropdownStyleData: DropdownStyleData( - maxHeight: 200, - decoration: BoxDecoration( - color: getSelectedColor(colorTheme, 0xFFFEFEFE, 0xFF282A2C), - borderRadius: const BorderRadius.only( - bottomLeft: Radius.circular(8.0), - bottomRight: Radius.circular(8.0), + style: bodyMedium(context), + underline: Container( + height: 0, ), - ), - ), - menuItemStyleData: const MenuItemStyleData( - height: 40, - ), - iconStyleData: IconStyleData( - icon: isCDropDownOpen - ? const Icon( - Icons.keyboard_arrow_up, - color: Color(0xFF858E8E), - ) - : const Icon( - Icons.keyboard_arrow_down, - color: Color(0xFF858E8E), + buttonStyleData: ButtonStyleData( + height: 56, + width: 560, + padding: const EdgeInsets.only(left: 14, right: 14), + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8.0), + border: Border.all( + color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF4B4B4B), ), - iconSize: 20, - ), - value: selectedNetwork, - // Array list of items - items: networks.map((String items) { - return DropdownMenuItem( - value: items, - child: Text(items), - ); - }).toList(), - onChanged: (value) { - selectedNetwork = value as String; - }, - onMenuStateChange: (isOpen) { - isCDropDownOpen = !isCDropDownOpen; - }, - ), - const SizedBox( - height: 24, - ), - TextField( - // TODO: Add to accept the address format only - key: addressInputKey, - controller: textWalletEditingController, - style: bodyMedium(context), - decoration: InputDecoration( - labelText: 'Wallet Address', - labelStyle: bodyMedium(context), - hintText: '0xxxxxxxxxxxxxxxxxxxxxxxxx', - suffix: TextButton( - style: TextButton.styleFrom( - foregroundColor: const Color(0xFFC0C4C4), - padding: const EdgeInsets.all(16.0), - textStyle: const TextStyle(fontSize: 16), + color: getSelectedColor(colorTheme, 0xFFFEFEFE, 0xFF282A2C), + ), ), - onPressed: () async { - final copiedData = await Clipboard.getData('text/plain'); - textWalletEditingController.value = TextEditingValue( - text: copiedData?.text ?? '', - selection: TextSelection.fromPosition( - TextPosition(offset: copiedData?.text?.length ?? 0), + dropdownStyleData: DropdownStyleData( + maxHeight: 200, + decoration: BoxDecoration( + color: getSelectedColor(colorTheme, 0xFFFEFEFE, 0xFF282A2C), + borderRadius: const BorderRadius.only( + bottomLeft: Radius.circular(8.0), + bottomRight: Radius.circular(8.0), ), + ), + ), + menuItemStyleData: const MenuItemStyleData( + height: 40, + ), + iconStyleData: IconStyleData( + icon: isCDropDownOpen + ? const Icon( + Icons.keyboard_arrow_up, + color: Color(0xFF858E8E), + ) + : const Icon( + Icons.keyboard_arrow_down, + color: Color(0xFF858E8E), + ), + iconSize: 20, + ), + value: selectedNetwork, + // Array list of items + items: networks.map((String items) { + return DropdownMenuItem( + value: items, + child: Text(items), ); + }).toList(), + onChanged: (value) { + selectedNetwork = value as String; + }, + onMenuStateChange: (isOpen) { + isCDropDownOpen = !isCDropDownOpen; }, - child: const Text('Paste'), ), - border: OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - borderSide: BorderSide( - color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), - ), + const SizedBox( + height: 24, ), - enabledBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - borderSide: BorderSide( - color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), + TextField( + // TODO: Add to accept the address format only + key: addressInputKey, + controller: textWalletEditingController, + style: bodyMedium(context), + decoration: InputDecoration( + labelText: 'Wallet Address', + labelStyle: bodyMedium(context), + hintText: '0xxxxxxxxxxxxxxxxxxxxxxxxx', + suffix: TextButton( + style: TextButton.styleFrom( + foregroundColor: const Color(0xFFC0C4C4), + padding: const EdgeInsets.all(16.0), + textStyle: const TextStyle(fontSize: 16), + ), + onPressed: () async { + final copiedData = await Clipboard.getData('text/plain'); + textWalletEditingController.value = TextEditingValue( + text: copiedData?.text ?? '', + selection: TextSelection.fromPosition( + TextPosition(offset: copiedData?.text?.length ?? 0), + ), + ); + }, + child: const Text('Paste'), + ), + border: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide( + color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), + ), + ), + enabledBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide( + color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), + ), + ), + focusedBorder: OutlineInputBorder( + borderRadius: BorderRadius.circular(8), + borderSide: BorderSide( + color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), + ), + ), ), ), - focusedBorder: OutlineInputBorder( - borderRadius: BorderRadius.circular(8), - borderSide: BorderSide( - color: getSelectedColor(colorTheme, 0xFFC0C4C4, 0xFF858E8E), - ), + const SizedBox( + height: 8, ), - ), - ), - const SizedBox( - height: 8, - ), - Stack(children: [ - SizedBox( - child: Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Text( - validate ? "This field is required" : '', - style: titleSmall(context), + Stack(children: [ + SizedBox( + child: Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Text( + validate ? "This field is required" : '', + style: titleSmall(context), + ), + ], ), - ], - ), - ), - SizedBox( - height: !isMobile ? 30 : null, - ), - const Positioned( - key: recaptchaWidgetKey, - left: 0, - top: 0, - child: SizedBox( + ), + SizedBox( + height: !isMobile ? 30 : null, + ), + const Positioned( + key: recaptchaWidgetKey, + left: 0, + top: 0, + child: SizedBox( height: 200, child: EasyWebView( src: @@ -271,72 +272,74 @@ class GetTestTokens extends HookConsumerWidget { isMarkdown: false, // Use markdown syntax convertToWidgets: false, // Try to convert to flutter widgets height: 150, - ))) - ]), - Padding( - padding: const EdgeInsets.only(top: 64.0), - child: Row( - mainAxisSize: MainAxisSize.max, - mainAxisAlignment: MainAxisAlignment.end, - children: [ - Expanded( - child: SizedBox( - width: isMobile ? 100 : 272, - height: 56, - child: TextButton( - onPressed: () { - Navigator.pop(context); - }, - child: Text( - 'Cancel', - style: titleSmall(context), - )), + ), ), - ), - const SizedBox( - width: 16, - ), - Expanded( - child: SizedBox( - width: isMobile ? 100 : 272, - height: 56, - child: ElevatedButton( - key: requestTokenButtonKey, - onPressed: () { - notifier.makeRequest( - context, - Request( - network: NetworkName.testnet, - walletAddress: textWalletEditingController.text, - status: Status.confirmed, - dateTime: DateTime.now(), - tokensDisbursed: 100, - transactionId: '28EhwUBiHJ3evyGidV1WH8QMfrLF6N8UDze9Yw7jqi6w'), - ); - }, - style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( - const Color(0xFF0DC8D4), - ), - shape: MaterialStateProperty.all( - RoundedRectangleBorder( - borderRadius: BorderRadius.circular(16), + ) + ]), + Padding( + padding: const EdgeInsets.only(top: 64.0), + child: Row( + mainAxisSize: MainAxisSize.max, + mainAxisAlignment: MainAxisAlignment.end, + children: [ + Expanded( + child: SizedBox( + width: isMobile ? 100 : 272, + height: 56, + child: TextButton( + onPressed: () { + Navigator.pop(context); + }, + child: Text( + 'Cancel', + style: titleSmall(context), + )), + ), + ), + const SizedBox( + width: 16, + ), + Expanded( + child: SizedBox( + width: isMobile ? 100 : 272, + height: 56, + child: ElevatedButton( + key: requestTokenButtonKey, + onPressed: () { + notifier.makeRequest( + context, + Request( + network: NetworkName.testnet, + walletAddress: textWalletEditingController.text, + status: Status.confirmed, + dateTime: DateTime.now(), + tokensDisbursed: 100, + transactionId: '28EhwUBiHJ3evyGidV1WH8QMfrLF6N8UDze9Yw7jqi6w'), + ); + }, + style: ButtonStyle( + backgroundColor: MaterialStateProperty.all( + const Color(0xFF0DC8D4), + ), + shape: MaterialStateProperty.all( + RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + ), + ), + ), + child: Text( + Strings.getLVL, + style: titleSmall(context)!.copyWith(color: Colors.white), ), ), ), - child: Text( - Strings.getLVL, - style: titleSmall(context)!.copyWith(color: Colors.white), - ), ), - ), + ], ), - ], - ), - ) - ], - ), - ), + ) + ], + ), + )), ); } } diff --git a/lib/requests/providers/requests_provider.dart b/lib/requests/providers/requests_provider.dart index 07b6685..9d92cad 100644 --- a/lib/requests/providers/requests_provider.dart +++ b/lib/requests/providers/requests_provider.dart @@ -221,6 +221,7 @@ class SuccessDialog extends StatelessWidget { ), ResponsiveRowColumnItem( child: IconButton( + key: closeSuccessDialogKey, icon: const Icon(Icons.close), onPressed: () { Navigator.of(context).pop(); @@ -257,11 +258,11 @@ class SuccessDialog extends StatelessWidget { layout: isTablet ? ResponsiveRowColumnType.COLUMN : ResponsiveRowColumnType.ROW, children: [ ResponsiveRowColumnItem( - child: Expanded( - child: SelectableText( - transactionHash, - style: bodyMedium(context), - ), + rowFlex: 5, + columnOrder: 1, + child: SelectableText( + transactionHash, + style: bodyMedium(context), ), ), const ResponsiveRowColumnItem( diff --git a/test/requests/desktop_request_failed_test.dart b/test/requests/desktop_request_failed_test.dart index 82e59cc..a4f299e 100644 --- a/test/requests/desktop_request_failed_test.dart +++ b/test/requests/desktop_request_failed_test.dart @@ -19,7 +19,7 @@ void main() async { } Future invalidTestTokenRequest(TestScreenSizes testScreenSize) async => testWidgets( - 'Should fail on invalid test token request', + 'Desktop - Should fail on invalid test token request', (WidgetTester tester) async { await tester.pumpWidget( await essentialTestProviderWidget(tester: tester, testScreenSize: testScreenSize, overrides: [ @@ -47,13 +47,11 @@ Future invalidTestTokenRequest(TestScreenSizes testScreenSize) async => te // first time success message expect(find.byKey(SuccessDialog.requestSuccessDialogKey), findsOneWidget); // find close button - await tester.tap(find.bySemanticsLabel('Close'), warnIfMissed: false); + await tester.tap(find.byKey(SuccessDialog.closeSuccessDialogKey)); await tester.pumpAndSettle(); - await tester.ensureVisible(requestTokenButton); await tester.pumpAndSettle(); await tester.tap(requestTokenButton); - await tester.pumpAndSettle(); - // second tap error message + await tester.pumpAndSettle(const Duration(seconds: 1)); expect(find.byKey(ErrorDialog.requestErrorDialogKey), findsOneWidget); }, ); diff --git a/test/requests/mobile_request_failed_test.dart b/test/requests/mobile_request_failed_test.dart index 44f44f2..c487bc2 100644 --- a/test/requests/mobile_request_failed_test.dart +++ b/test/requests/mobile_request_failed_test.dart @@ -2,6 +2,7 @@ import 'package:faucet/home/sections/get_test_tokens.dart'; import 'package:faucet/requests/providers/requests_provider.dart'; import 'package:faucet/shared/services/hive/hive_service.dart'; import 'package:faucet/transactions/sections/transaction_table.dart'; +import 'package:flutter/cupertino.dart'; import 'package:flutter_test/flutter_test.dart'; import '../essential_test_provider_widget.dart'; @@ -12,14 +13,14 @@ import 'utils/mock_request_hive_utils.dart'; void main() async { final requestTests = RequiredInvalidRequestsTests( invalidTestTokenRequest: (testScreenSize) => invalidTestTokenRequest(testScreenSize), - testScreenSize: TestScreenSizes.tablet, + testScreenSize: TestScreenSizes.mobile, ); await requestTests.runTests(); } Future invalidTestTokenRequest(TestScreenSizes testScreenSize) async => testWidgets( - 'Should fail on invalid test token request', + 'Mobile - Should fail on invalid test token request', (WidgetTester tester) async { await tester.pumpWidget( await essentialTestProviderWidget(tester: tester, testScreenSize: testScreenSize, overrides: [ @@ -47,13 +48,11 @@ Future invalidTestTokenRequest(TestScreenSizes testScreenSize) async => te // first time success message expect(find.byKey(SuccessDialog.requestSuccessDialogKey), findsOneWidget); // find close button - await tester.tap(find.bySemanticsLabel('Close'), warnIfMissed: false); + await tester.tap(find.byKey(SuccessDialog.closeSuccessDialogKey)); await tester.pumpAndSettle(); - await tester.ensureVisible(requestTokenButton); await tester.pumpAndSettle(); await tester.tap(requestTokenButton); - await tester.pumpAndSettle(); - // second tap error message + await tester.pumpAndSettle(const Duration(seconds: 1)); expect(find.byKey(ErrorDialog.requestErrorDialogKey), findsOneWidget); }, ); diff --git a/test/requests/required_request_tests.dart b/test/requests/required_request_tests.dart index 3b8e229..7609097 100644 --- a/test/requests/required_request_tests.dart +++ b/test/requests/required_request_tests.dart @@ -12,3 +12,16 @@ class RequiredRequestsTests extends RequiredTest { await menuOpened(testScreenSize); } } + +class RequiredInvalidRequestsTests extends RequiredTest { + Future Function(TestScreenSizes testScreenSize) invalidTestTokenRequest; + + RequiredInvalidRequestsTests({ + required this.invalidTestTokenRequest, + required super.testScreenSize, + }); + + Future runTests() async { + await invalidTestTokenRequest(testScreenSize); + } +} diff --git a/test/requests/tablet_request_failed_test.dart b/test/requests/tablet_request_failed_test.dart index e69de29..0a3de4b 100644 --- a/test/requests/tablet_request_failed_test.dart +++ b/test/requests/tablet_request_failed_test.dart @@ -0,0 +1,58 @@ +import 'package:faucet/home/sections/get_test_tokens.dart'; +import 'package:faucet/requests/providers/requests_provider.dart'; +import 'package:faucet/shared/services/hive/hive_service.dart'; +import 'package:faucet/transactions/sections/transaction_table.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import '../essential_test_provider_widget.dart'; +import '../required_test_class.dart'; +import 'required_request_tests.dart'; +import 'utils/mock_request_hive_utils.dart'; + +void main() async { + final requestTests = RequiredInvalidRequestsTests( + invalidTestTokenRequest: (testScreenSize) => invalidTestTokenRequest(testScreenSize), + testScreenSize: TestScreenSizes.tablet, + ); + + await requestTests.runTests(); +} + +Future invalidTestTokenRequest(TestScreenSizes testScreenSize) async => testWidgets( + 'Tablet - Should fail on invalid test token request', + (WidgetTester tester) async { + await tester.pumpWidget( + await essentialTestProviderWidget(tester: tester, testScreenSize: testScreenSize, overrides: [ + hivePackageProvider.overrideWithValue( + getMockRequestHive().mockHive, + ), + ]), + ); + await tester.pumpAndSettle(); + // click request token button + await tester.ensureVisible(find.byKey(TransactionTableScreen.requestTokensKey)); + await tester.pumpAndSettle(); + await tester.tap(find.byKey(TransactionTableScreen.requestTokensKey)); + await tester.pumpAndSettle(); + // check that the drawer is displayed + expect(find.byKey(GetTestTokens.getTestTokensKey), findsOneWidget); + // click the request token button + var requestTokenButton = find.byKey(GetTestTokens.requestTokenButtonKey); + + await tester.ensureVisible(requestTokenButton); + await tester.pumpAndSettle(); + await tester.tap(requestTokenButton); + await tester.pumpAndSettle(); + await tester.ensureVisible(find.byKey(SuccessDialog.requestSuccessDialogKey)); + // first time success message + expect(find.byKey(SuccessDialog.requestSuccessDialogKey), findsOneWidget); + // find close button + await tester.tap(find.byKey(SuccessDialog.closeSuccessDialogKey)); + await tester.pumpAndSettle(); + await tester.pumpAndSettle(); + await tester.tap(requestTokenButton); + await tester.pumpAndSettle(const Duration(seconds: 1)); + expect(find.byKey(ErrorDialog.requestErrorDialogKey), findsOneWidget); + }, + );