From 6a5ed0d4532f332814d2fdf08b30fcfaa3577e86 Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Wed, 29 Nov 2023 17:45:23 +0100 Subject: [PATCH] feat: logo icon restart flow --- lib/home/bloc/home_bloc.dart | 8 +++++++ lib/home/bloc/home_event.dart | 4 ++++ lib/home/widgets/logo.dart | 17 +++++++++++++- packages/app_ui/assets/icons/asterisk.png | Bin 300 -> 436 bytes test/home/bloc/home_bloc_test.dart | 11 +++++++++ test/home/bloc/home_event_test.dart | 21 +++++++++++++++++ test/home/widgets/logo_test.dart | 27 ++++++++++++++++++++++ 7 files changed, 87 insertions(+), 1 deletion(-) diff --git a/lib/home/bloc/home_bloc.dart b/lib/home/bloc/home_bloc.dart index 0792903..f576dfd 100644 --- a/lib/home/bloc/home_bloc.dart +++ b/lib/home/bloc/home_bloc.dart @@ -17,6 +17,7 @@ class HomeBloc extends Bloc { on(_onResults); on(_onSeeSourceAnswersRequested); on(_onSeeSourceAnswers); + on(_onRestarted); } final QuestionsRepository _questionsRepository; @@ -73,4 +74,11 @@ class HomeBloc extends Bloc { ) { emit(state.copyWith(status: Status.seeSourceAnswers)); } + + void _onRestarted( + Restarted event, + Emitter emit, + ) { + emit(state.copyWith(status: Status.welcome)); + } } diff --git a/lib/home/bloc/home_event.dart b/lib/home/bloc/home_event.dart index ed579d2..923b513 100644 --- a/lib/home/bloc/home_event.dart +++ b/lib/home/bloc/home_event.dart @@ -38,3 +38,7 @@ class SeeSourceAnswersRequested extends HomeEvent { class SeeResultsSourceAnswers extends HomeEvent { const SeeResultsSourceAnswers(); } + +class Restarted extends HomeEvent { + const Restarted(); +} diff --git a/lib/home/widgets/logo.dart b/lib/home/widgets/logo.dart index 06ee636..8963da4 100644 --- a/lib/home/widgets/logo.dart +++ b/lib/home/widgets/logo.dart @@ -1,6 +1,8 @@ import 'package:app_ui/app_ui.dart'; +import 'package:dash_ai_search/home/bloc/home_bloc.dart'; import 'package:dash_ai_search/l10n/l10n.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; class Logo extends StatelessWidget { const Logo({super.key, this.hasDarkBackground = true}); @@ -23,7 +25,7 @@ class Logo extends StatelessWidget { ), ), const SizedBox(width: 4), - vertexIcons.asterisk.image(), + const LogoIcon(), const SizedBox(width: 4), Text( l10n.flutter, @@ -35,3 +37,16 @@ class Logo extends StatelessWidget { ); } } + +class LogoIcon extends StatelessWidget { + @visibleForTesting + const LogoIcon({super.key}); + + @override + Widget build(BuildContext context) { + return IconButton( + onPressed: () => context.read().add(const Restarted()), + icon: vertexIcons.asterisk.image(), + ); + } +} diff --git a/packages/app_ui/assets/icons/asterisk.png b/packages/app_ui/assets/icons/asterisk.png index 3f6150b46e5917b3c29707312eda213b09a546d2..47ec2e59df5a95b7dede21cfd517a2602a8f0dc4 100644 GIT binary patch delta 360 zcmV-u0hj))0<;5=Reu3VNkl22s#Ef}8UlvPq#i0#dx6;nlFC#9bt-iAvbWjyP70*{&1F@ty!km!2jUDpjyeY*1O1w+npV9%6jQ@>U|Q49-y!lIq|kIej3JUeT#Km``+E8zM9ZXNyum|!5?#{gr00NSx({{Whv zH|oLFQb+`-1aPT=QyW9bd^E0Bix?nsDR{%KbmwMpW>tde16ZJi>Ey3;M>=d`vy$$P zjWAc?7_&z>SL0c7STSYxGt-w_Y!*N( + 'emits Status.welcome', + build: buildBloc, + act: (bloc) => bloc.add(Restarted()), + expect: () => [ + HomeState(), + ], + ); + }); }); } diff --git a/test/home/bloc/home_event_test.dart b/test/home/bloc/home_event_test.dart index cb7a921..ba56be7 100644 --- a/test/home/bloc/home_event_test.dart +++ b/test/home/bloc/home_event_test.dart @@ -31,11 +31,32 @@ void main() { ); }); + test('Results supports value equality', () { + expect( + Results(), + equals(Results()), + ); + }); + test('SeeSourceAnswersRequested supports value equality', () { expect( SeeSourceAnswersRequested(), equals(SeeSourceAnswersRequested()), ); }); + + test('SeeResultsSourceAnswers supports value equality', () { + expect( + SeeResultsSourceAnswers(), + equals(SeeResultsSourceAnswers()), + ); + }); + + test('Restarted supports value equality', () { + expect( + Restarted(), + equals(Restarted()), + ); + }); }); } diff --git a/test/home/widgets/logo_test.dart b/test/home/widgets/logo_test.dart index 19b3df9..e64abd2 100644 --- a/test/home/widgets/logo_test.dart +++ b/test/home/widgets/logo_test.dart @@ -1,12 +1,25 @@ +import 'package:bloc_test/bloc_test.dart'; import 'package:dash_ai_search/home/home.dart'; import 'package:dash_ai_search/l10n/l10n.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; import '../../helpers/helpers.dart'; +class _MockHomeBloc extends MockBloc + implements HomeBloc {} + void main() { group('Logo', () { + late HomeBloc homeBloc; + + setUp(() { + homeBloc = _MockHomeBloc(); + when(() => homeBloc.state).thenReturn(HomeState()); + }); + testWidgets('renders correctly', (tester) async { await tester.pumpApp( Logo(), @@ -18,5 +31,19 @@ void main() { expect(find.byType(Image), findsOneWidget); expect(find.text(l10n.flutter), findsOneWidget); }); + + testWidgets( + 'calls Restarted clicking on the logo ', + (WidgetTester tester) async { + await tester.pumpApp( + BlocProvider.value( + value: homeBloc, + child: Logo(), + ), + ); + await tester.tap(find.byType(LogoIcon)); + verify(() => homeBloc.add(Restarted())).called(1); + }, + ); }); }