Skip to content

Commit

Permalink
refactor: remover dependência do Modular nos testes da ZodiacPage
Browse files Browse the repository at this point in the history
  • Loading branch information
shonorio committed Jan 13, 2025
1 parent e3a70ce commit d4573c1
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions test/app/features/zodiac/presentation/zodiac_page_test.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
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/features/appstate/domain/entities/user_profile_entity.dart';
Expand All @@ -9,7 +7,6 @@ import 'package:penhas/app/features/zodiac/presentation/pages/zodiac_felling_pag
import 'package:penhas/app/features/zodiac/presentation/pages/zodiac_ruling_page.dart';
import 'package:penhas/app/features/zodiac/presentation/pages/zodiac_sign_page.dart';
import 'package:penhas/app/features/zodiac/presentation/zodiac_controller.dart';
import 'package:penhas/app/features/zodiac/presentation/zodiac_module.dart';
import 'package:penhas/app/features/zodiac/presentation/zodiac_page.dart';

import '../../../../utils/golden_tests.dart';
Expand All @@ -18,6 +15,8 @@ import '../../authentication/presentation/mocks/app_modules_mock.dart';
import '../../authentication/presentation/mocks/authentication_modules_mock.dart';

void main() {
late ZodiacController controller;

setUp(() {
AppModulesMock.init();
AuthenticationModulesMock.init();
Expand Down Expand Up @@ -45,25 +44,20 @@ void main() {

when(() => AuthenticationModulesMock.securityAction.dispose())
.thenAnswer((_) => Future.value());
initModule(ZodiacModule(), replaceBinds: [
Bind.factory((i) => ZodiacController(
userProfileStore: AppModulesMock.userProfileStore,
securityAction: AuthenticationModulesMock.securityAction,
)),
]);
});

tearDown(() {
Modular.removeModule(ZodiacModule());
controller = ZodiacController(
userProfileStore: AppModulesMock.userProfileStore,
securityAction: AuthenticationModulesMock.securityAction,
);
});

group(ZodiacPage, () {
testWidgets('should render the page', (tester) async {
// arrange
await theAppIsRunning(tester, const ZodiacPage());
await theAppIsRunning(tester, ZodiacPage(controller: controller));
// assert
iSeeText('Hoje');
iSeeText('Diário astrólogico');
iSeeText('Diário astrológico');
iSeeWidget(ZodiacSignPage);
iSeeWidget(ZodiacRulingPage);
iSeeWidget(ZodiacFellingPage);
Expand All @@ -76,9 +70,9 @@ void main() {
when(() =>
AppModulesMock.modularNavigator.pushReplacementNamed(routeName))
.thenAnswer((_) => Future.value());
await theAppIsRunning(tester, const ZodiacPage());
await theAppIsRunning(tester, ZodiacPage(controller: controller));
// act
await iTapText(tester, text: 'Diário astrólogico');
await iTapText(tester, text: 'Diário astrológico');
// assert
verify(() =>
AppModulesMock.modularNavigator.pushReplacementNamed(routeName))
Expand All @@ -93,7 +87,7 @@ void main() {
.thenAnswer((_) => Future.value());
when(() => AuthenticationModulesMock.securityAction.stop())
.thenAnswer((_) => Future.value());
await theAppIsRunning(tester, const ZodiacPage());
await theAppIsRunning(tester, ZodiacPage(controller: controller));
await tester.pumpAndSettle();
// act
await iSeeWidget(ZodiacActionButton);
Expand All @@ -106,7 +100,7 @@ void main() {
screenshotTest(
'should render the page',
fileName: 'zodiac_page',
pageBuilder: () => const ZodiacPage(),
pageBuilder: () => ZodiacPage(controller: controller),
);
});
}

0 comments on commit d4573c1

Please sign in to comment.