From 89cbea8be9bbfec92332bbc3fa1bbd72453e269c Mon Sep 17 00:00:00 2001 From: RuiAlonso Date: Wed, 29 Nov 2023 10:42:29 +0100 Subject: [PATCH] test: coverage --- lib/home/bloc/home_bloc.dart | 8 -- lib/home/bloc/home_event.dart | 4 - lib/home/widgets/see_source_answers.dart | 64 ------------ lib/home/widgets/widgets.dart | 1 - test/home/bloc/home_bloc_test.dart | 22 +++++ .../home/widgets/see_source_answers_test.dart | 99 ------------------- 6 files changed, 22 insertions(+), 176 deletions(-) delete mode 100644 lib/home/widgets/see_source_answers.dart delete mode 100644 test/home/widgets/see_source_answers_test.dart diff --git a/lib/home/bloc/home_bloc.dart b/lib/home/bloc/home_bloc.dart index 0c37be9..0792903 100644 --- a/lib/home/bloc/home_bloc.dart +++ b/lib/home/bloc/home_bloc.dart @@ -17,7 +17,6 @@ class HomeBloc extends Bloc { on(_onResults); on(_onSeeSourceAnswersRequested); on(_onSeeSourceAnswers); - on(_onBackToAnswerRequested); } final QuestionsRepository _questionsRepository; @@ -74,11 +73,4 @@ class HomeBloc extends Bloc { ) { emit(state.copyWith(status: Status.seeSourceAnswers)); } - - void _onBackToAnswerRequested( - BackToAnswerRequested event, - Emitter emit, - ) { - emit(state.copyWith(status: Status.sourceAnswersBackToResults)); - } } diff --git a/lib/home/bloc/home_event.dart b/lib/home/bloc/home_event.dart index 7cb2e3a..ed579d2 100644 --- a/lib/home/bloc/home_event.dart +++ b/lib/home/bloc/home_event.dart @@ -38,7 +38,3 @@ class SeeSourceAnswersRequested extends HomeEvent { class SeeResultsSourceAnswers extends HomeEvent { const SeeResultsSourceAnswers(); } - -class BackToAnswerRequested extends HomeEvent { - const BackToAnswerRequested(); -} diff --git a/lib/home/widgets/see_source_answers.dart b/lib/home/widgets/see_source_answers.dart deleted file mode 100644 index f51fccd..0000000 --- a/lib/home/widgets/see_source_answers.dart +++ /dev/null @@ -1,64 +0,0 @@ -import 'package:app_ui/app_ui.dart'; -import 'package:dash_ai_search/home/home.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; - -class SeeSourceAnswers extends StatelessWidget { - const SeeSourceAnswers({super.key}); - - @override - Widget build(BuildContext context) { - final response = - context.select((HomeBloc bloc) => bloc.state.vertexResponse); - return SizedBox.expand( - child: ColoredBox( - color: VertexColors.googleBlue, - child: SingleChildScrollView( - child: Column( - children: [ - const SizedBox(height: 64), - const SearchBox(), - const SizedBox(height: 32), - Row( - children: [ - Expanded(child: _AiResponse(response.summary)), - const SizedBox(width: 150), - Expanded( - child: SourcesCarouselView(documents: response.documents), - ), - ], - ), - ], - ), - ), - ), - ); - } -} - -class _AiResponse extends StatelessWidget { - const _AiResponse(this.text); - - final String text; - - @override - Widget build(BuildContext context) { - final textTheme = Theme.of(context).textTheme; - - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 50), - child: Column( - children: [ - Text( - text, - style: textTheme.headlineLarge?.copyWith( - color: VertexColors.white, - ), - ), - const SizedBox(height: 20), - const FeedbackButtons(), - ], - ), - ); - } -} diff --git a/lib/home/widgets/widgets.dart b/lib/home/widgets/widgets.dart index b3cfd0a..f574598 100644 --- a/lib/home/widgets/widgets.dart +++ b/lib/home/widgets/widgets.dart @@ -5,7 +5,6 @@ export 'logo.dart'; export 'question_view.dart'; export 'results_view.dart'; export 'search_box.dart'; -export 'see_source_answers.dart'; export 'sources_carousel_view.dart'; export 'thinking_view.dart'; export 'transition_screen_mixin.dart'; diff --git a/test/home/bloc/home_bloc_test.dart b/test/home/bloc/home_bloc_test.dart index 3f03002..a5b057f 100644 --- a/test/home/bloc/home_bloc_test.dart +++ b/test/home/bloc/home_bloc_test.dart @@ -80,6 +80,17 @@ void main() { ); }); + group('Results', () { + blocTest( + 'emits Status.results', + build: buildBloc, + act: (bloc) => bloc.add(Results()), + expect: () => [ + HomeState(status: Status.results), + ], + ); + }); + group('SeeSourceAnswersRequested', () { blocTest( 'emits Status.seeSourceAnswers', @@ -90,5 +101,16 @@ void main() { ], ); }); + + group('SeeResultsSourceAnswers', () { + blocTest( + 'emits Status.seeSourceAnswers', + build: buildBloc, + act: (bloc) => bloc.add(SeeResultsSourceAnswers()), + expect: () => [ + HomeState(status: Status.seeSourceAnswers), + ], + ); + }); }); } diff --git a/test/home/widgets/see_source_answers_test.dart b/test/home/widgets/see_source_answers_test.dart deleted file mode 100644 index 4b14394..0000000 --- a/test/home/widgets/see_source_answers_test.dart +++ /dev/null @@ -1,99 +0,0 @@ -import 'package:api_client/api_client.dart'; -import 'package:bloc_test/bloc_test.dart'; -import 'package:dash_ai_search/home/home.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('SeeSourceAnswers', () { - late HomeBloc homeBloc; - const response = VertexResponse( - summary: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, ' - 'sed do eiusmod tempor incididunt ut labore et dolore magna ' - 'aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' - 'ullamco laboris nisi ut aliquip ex ea commodo consequat. ' - 'Duis aute irure dolor in reprehenderit in voluptate velit ' - 'esse cillum dolore eu fugiat nulla pariatur. Excepteur sint ' - 'occaecat cupidatat non proident, sunt in culpa qui officia' - ' deserunt mollit anim id est laborum.', - documents: [ - VertexDocument( - id: '1', - metadata: VertexMetadata( - url: 'url', - title: 'title', - description: 'description', - ), - ), - VertexDocument( - id: '2', - metadata: VertexMetadata( - url: 'url', - title: 'title', - description: 'description', - ), - ), - VertexDocument( - id: '3', - metadata: VertexMetadata( - url: 'url', - title: 'title', - description: 'description', - ), - ), - VertexDocument( - id: '4', - metadata: VertexMetadata( - url: 'url', - title: 'title', - description: 'description', - ), - ), - ], - ); - - setUp(() { - homeBloc = _MockHomeBloc(); - when(() => homeBloc.state).thenReturn( - HomeState(vertexResponse: response), - ); - }); - - testWidgets('renders the response summary', (tester) async { - await tester.pumpApp( - BlocProvider.value( - value: homeBloc, - child: Material(child: SeeResultsSourceAnswers()), - ), - ); - expect(find.text(response.summary), findsOneWidget); - }); - - testWidgets('renders SearchBox', (tester) async { - await tester.pumpApp( - BlocProvider.value( - value: homeBloc, - child: Material(child: SeeResultsSourceAnswers()), - ), - ); - expect(find.byType(SearchBox), findsOneWidget); - }); - - testWidgets('renders SourcesCarouselView', (tester) async { - await tester.pumpApp( - BlocProvider.value( - value: homeBloc, - child: Material(child: SeeResultsSourceAnswers()), - ), - ); - expect(find.byType(SourcesCarouselView), findsOneWidget); - }); - }); -}