diff --git a/lib/app/features/feed/presentation/compose_tweet/compose_tweet_page.dart b/lib/app/features/feed/presentation/compose_tweet/compose_tweet_page.dart index 6f3f4033e..24f11e051 100644 --- a/lib/app/features/feed/presentation/compose_tweet/compose_tweet_page.dart +++ b/lib/app/features/feed/presentation/compose_tweet/compose_tweet_page.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; -import 'package:flutter_modular/flutter_modular.dart'; import 'package:flutter_svg/svg.dart'; import 'package:mobx/mobx.dart'; @@ -17,17 +16,18 @@ class ComposeTweetPage extends StatefulWidget { Key? key, this.title = 'Publicar', this.showAppBar = false, + required this.composeTweetController, }) : super(key: key); final String title; final bool showAppBar; + final ComposeTweetController composeTweetController; @override _ComposeTweetPageState createState() => _ComposeTweetPageState(); } -class _ComposeTweetPageState - extends ModularState +class _ComposeTweetPageState extends State with SnackBarHandler { final String inputHint = 'Deixe seu comentário'; final String anonymousHint = @@ -35,6 +35,7 @@ class _ComposeTweetPageState List? _disposers; final GlobalKey _scaffoldKey = GlobalKey(); PageProgressState _currentState = PageProgressState.initial; + ComposeTweetController get controller => widget.composeTweetController; TextStyle get _kTextStyleNewTweetAnonymousHint => const TextStyle( fontFamily: 'Lato', diff --git a/lib/app/features/mainboard/presentation/mainboard/mainboard_module.dart b/lib/app/features/mainboard/presentation/mainboard/mainboard_module.dart index 64aa250df..d1092213d 100644 --- a/lib/app/features/mainboard/presentation/mainboard/mainboard_module.dart +++ b/lib/app/features/mainboard/presentation/mainboard/mainboard_module.dart @@ -131,6 +131,7 @@ class MainboardModule extends Module { Modular.initialRoute, child: (_, args) => MainboardPage( controller: Modular.get(), + composeTweetController: Modular.get(), ), ), ...tweetRoutes, @@ -151,7 +152,10 @@ class MainboardModule extends Module { ), ChildRoute( '/compose', - child: (_, args) => const ComposeTweetPage(showAppBar: true), + child: (_, args) => ComposeTweetPage( + showAppBar: true, + composeTweetController: Modular.get(), + ), transition: TransitionType.rightToLeft, ), ChildRoute( diff --git a/lib/app/features/mainboard/presentation/mainboard/mainboard_page.dart b/lib/app/features/mainboard/presentation/mainboard/mainboard_page.dart index 403602b70..74bcc1f99 100644 --- a/lib/app/features/mainboard/presentation/mainboard/mainboard_page.dart +++ b/lib/app/features/mainboard/presentation/mainboard/mainboard_page.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; +import '../../../feed/presentation/compose_tweet/compose_tweet_controller.dart'; import '../../../main_menu/presentation/penhas_drawer_page.dart'; import 'mainboard_controller.dart'; import 'pages/mainboard_app_bar_page.dart'; @@ -11,9 +12,11 @@ class MainboardPage extends StatefulWidget { const MainboardPage({ Key? key, required this.controller, + required this.composeTweetController, }) : super(key: key); final MainboardController controller; + final ComposeTweetController composeTweetController; static final mainBoardKey = GlobalKey( debugLabel: 'main-board-scaffold-key', @@ -29,6 +32,8 @@ class MainboardPage extends StatefulWidget { class MainboardPageState extends State with WidgetsBindingObserver { MainboardController get controller => widget.controller; + ComposeTweetController get composeTweetController => + widget.composeTweetController; @override void initState() { @@ -61,6 +66,7 @@ class MainboardPageState extends State body: MainboardBodyPage( pages: controller.mainboardStore.pages, pageController: controller.mainboardStore.pageController, + composeTweetController: composeTweetController, ), ), bottomNavigationBar: MainboardBottomNavigationPage( diff --git a/lib/app/features/mainboard/presentation/mainboard/pages/mainboard_body_page.dart b/lib/app/features/mainboard/presentation/mainboard/pages/mainboard_body_page.dart index 7e0ce1bc4..e5ccd5824 100644 --- a/lib/app/features/mainboard/presentation/mainboard/pages/mainboard_body_page.dart +++ b/lib/app/features/mainboard/presentation/mainboard/pages/mainboard_body_page.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../../../../chat/presentation/chat_main_module.dart'; import '../../../../escape_manual/escape_manual_module.dart'; +import '../../../../feed/presentation/compose_tweet/compose_tweet_controller.dart'; import '../../../../feed/presentation/compose_tweet/compose_tweet_page.dart'; import '../../../../feed/presentation/feed_module.dart'; import '../../../../help_center/presentation/help_center_module.dart'; @@ -13,10 +14,12 @@ class MainboardBodyPage extends StatelessWidget { Key? key, required this.pages, required this.pageController, + required this.composeTweetController, }) : super(key: key); final List pages; final PageController pageController; + final ComposeTweetController composeTweetController; @override Widget build(BuildContext context) { @@ -32,7 +35,9 @@ class MainboardBodyPage extends StatelessWidget { chat: () => ChatMainModule(), feed: () => FeedModule(), escapeManual: () => EscapeManualModule(), - compose: () => const ComposeTweetPage(), + compose: () => ComposeTweetPage( + composeTweetController: composeTweetController, + ), supportPoint: () => SupportCenterModule(), helpCenter: () => HelpCenterModule(), ); diff --git a/test/app/features/feed/presentation/compose_tweet/compose_tweet_page_test.dart b/test/app/features/feed/presentation/compose_tweet/compose_tweet_page_test.dart index a62999c37..b6f8175de 100644 --- a/test/app/features/feed/presentation/compose_tweet/compose_tweet_page_test.dart +++ b/test/app/features/feed/presentation/compose_tweet/compose_tweet_page_test.dart @@ -1,15 +1,13 @@ import 'package:dartz/dartz.dart' show left, right; import 'package:flutter/material.dart'; -import 'package:flutter_modular/flutter_modular.dart'; import 'package:flutter_modular_test/flutter_modular_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; -import 'package:penhas/app/app_module.dart'; import 'package:penhas/app/core/error/failures.dart'; import 'package:penhas/app/features/feed/domain/usecases/feed_use_cases.dart'; +import 'package:penhas/app/features/feed/presentation/compose_tweet/compose_tweet_controller.dart'; import 'package:penhas/app/features/feed/presentation/compose_tweet/compose_tweet_navigator.dart'; import 'package:penhas/app/features/feed/presentation/compose_tweet/compose_tweet_page.dart'; -import 'package:penhas/app/features/mainboard/presentation/mainboard/mainboard_module.dart'; import '../../../../../utils/golden_tests.dart'; import '../../../../../utils/widget_tester_ext.dart'; @@ -17,7 +15,7 @@ import '../../../../../utils/widget_tester_ext.dart'; void main() { late FeedUseCases mockFeedUseCases; late ComposeTweetNavigator mockNavigator; - + late ComposeTweetController composeTweetController; group(ComposeTweetPage, () { setUpAll(() { registerFallbackValue(_FakeContext()); @@ -26,40 +24,34 @@ void main() { setUp(() { mockFeedUseCases = _MockFeedUseCases(); mockNavigator = _MockComposeTweetNavigator(); + composeTweetController = ComposeTweetController( + navigator: mockNavigator, useCase: mockFeedUseCases); + }); - initModules( - [ - AppModule(), - MainboardModule(), - ], - replaceBinds: [ - Bind((i) => mockFeedUseCases), - Bind((i) => mockNavigator), - ], + screenshotTest('should render ComposeTweetPage', + fileName: 'compose_tweet_page', pageBuilder: () { + return ComposeTweetPage( + composeTweetController: composeTweetController, ); }); - tearDown(() { - Modular.removeModule(AppModule()); - Modular.removeModule(MainboardModule()); + screenshotTest('should render ComposeTweetPage with app bar', + fileName: 'compose_tweet_page_with_app_bar', pageBuilder: () { + return ComposeTweetPage( + showAppBar: true, + composeTweetController: composeTweetController, + ); }); - screenshotTest( - 'should render ComposeTweetPage', - fileName: 'compose_tweet_page', - pageBuilder: () => ComposeTweetPage(), - ); - - screenshotTest( - 'should render ComposeTweetPage with app bar', - fileName: 'compose_tweet_page_with_app_bar', - pageBuilder: () => ComposeTweetPage(showAppBar: true), - ); - screenshotTest( 'when user types a tweet, should enable create button', fileName: 'compose_tweet_page_with_text', - pageBuilder: () => ComposeTweetPage(showAppBar: true), + pageBuilder: () { + return ComposeTweetPage( + showAppBar: true, + composeTweetController: composeTweetController, + ); + }, pumpBeforeTest: (tester) async { await tester.enterTextAll(find.byType(TextField), 'Hello, world!'); await tester.pumpAndSettle(); @@ -69,7 +61,10 @@ void main() { screenshotTest( 'when create tweet fails should show error message', fileName: 'compose_tweet_page_with_error', - pageBuilder: () => ComposeTweetPage(showAppBar: true), + pageBuilder: () => ComposeTweetPage( + showAppBar: true, + composeTweetController: composeTweetController, + ), setUp: () { when(() => mockFeedUseCases.create(any())).thenAnswer( (_) async => left(ServerFailure()), @@ -90,7 +85,9 @@ void main() { (_) async => right(FeedCache(tweets: [])), ); - await tester.pumpWidget(buildTestableWidget(ComposeTweetPage())); + await tester.pumpWidget(buildTestableWidget(ComposeTweetPage( + composeTweetController: composeTweetController, + ))); await tester.pumpAndSettle(); // act @@ -108,13 +105,16 @@ void main() { 'when tweet created successfully should navigate to mainboard', (tester) async { // arrange + when(() => mockFeedUseCases.create(any())).thenAnswer( (_) async => right(FeedCache(tweets: [])), ); when(() => mockNavigator.navigateToFeed(any())) .thenAnswer((_) => Future.value()); - await tester.pumpWidget(buildTestableWidget(ComposeTweetPage())); + await tester.pumpWidget(buildTestableWidget(ComposeTweetPage( + composeTweetController: composeTweetController, + ))); await tester.pumpAndSettle(); // act diff --git a/test/app/features/mainboard/presentation/mainboard/mainboard_page_test.dart b/test/app/features/mainboard/presentation/mainboard/mainboard_page_test.dart index a8f7b5b85..485c3b4af 100644 --- a/test/app/features/mainboard/presentation/mainboard/mainboard_page_test.dart +++ b/test/app/features/mainboard/presentation/mainboard/mainboard_page_test.dart @@ -5,6 +5,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mobx/mobx.dart' as mobx; import 'package:mocktail/mocktail.dart'; import 'package:penhas/app/features/appstate/domain/usecases/app_preferences_use_case.dart'; +import 'package:penhas/app/features/feed/presentation/compose_tweet/compose_tweet_controller.dart'; import 'package:penhas/app/features/mainboard/domain/states/mainboard_state.dart'; import 'package:penhas/app/features/mainboard/domain/states/mainboard_store.dart'; import 'package:penhas/app/features/mainboard/presentation/mainboard/mainboard_controller.dart'; @@ -25,8 +26,12 @@ class MockNotificationRepository extends Mock class FakeTimer extends Fake implements Timer {} +class MockComposeTweetController extends Mock + implements ComposeTweetController {} + void main() { late MainboardController controller; + late ComposeTweetController composeTweetController; late MainboardStore mainboardStore; late InactivityLogoutUseCase inactivityLogoutUseCase; late INotificationRepository notification; @@ -56,13 +61,17 @@ void main() { notification: notification, notificationTimer: notificationTimer, ); + composeTweetController = MockComposeTweetController(); }); group(MainboardPage, () { screenshotTest( 'mainboard page', fileName: 'mainboard_page', - pageBuilder: () => MainboardPage(controller: controller), + pageBuilder: () => MainboardPage( + controller: controller, + composeTweetController: composeTweetController, + ), skip: true, reason: 'possuiu vários elementos difíceis de testar. Vou revisar esta tela para melhorar a cobertura de testes',