Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
feat: logo icon restart flow
Browse files Browse the repository at this point in the history
  • Loading branch information
RuiMiguel committed Nov 29, 2023
1 parent 9304123 commit 6a5ed0d
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/home/bloc/home_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
on<Results>(_onResults);
on<SeeSourceAnswersRequested>(_onSeeSourceAnswersRequested);
on<SeeResultsSourceAnswers>(_onSeeSourceAnswers);
on<Restarted>(_onRestarted);
}

final QuestionsRepository _questionsRepository;
Expand Down Expand Up @@ -73,4 +74,11 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
) {
emit(state.copyWith(status: Status.seeSourceAnswers));
}

void _onRestarted(
Restarted event,
Emitter<HomeState> emit,
) {
emit(state.copyWith(status: Status.welcome));
}
}
4 changes: 4 additions & 0 deletions lib/home/bloc/home_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ class SeeSourceAnswersRequested extends HomeEvent {
class SeeResultsSourceAnswers extends HomeEvent {
const SeeResultsSourceAnswers();
}

class Restarted extends HomeEvent {
const Restarted();
}
17 changes: 16 additions & 1 deletion lib/home/widgets/logo.dart
Original file line number Diff line number Diff line change
@@ -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});
Expand All @@ -23,7 +25,7 @@ class Logo extends StatelessWidget {
),
),
const SizedBox(width: 4),
vertexIcons.asterisk.image(),
const LogoIcon(),
const SizedBox(width: 4),
Text(
l10n.flutter,
Expand All @@ -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<HomeBloc>().add(const Restarted()),
icon: vertexIcons.asterisk.image(),
);
}
}
Binary file modified packages/app_ui/assets/icons/asterisk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions test/home/bloc/home_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,16 @@ void main() {
],
);
});

group('Restarted', () {
blocTest<HomeBloc, HomeState>(
'emits Status.welcome',
build: buildBloc,
act: (bloc) => bloc.add(Restarted()),
expect: () => [
HomeState(),
],
);
});
});
}
21 changes: 21 additions & 0 deletions test/home/bloc/home_event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
);
});
});
}
27 changes: 27 additions & 0 deletions test/home/widgets/logo_test.dart
Original file line number Diff line number Diff line change
@@ -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<HomeEvent, HomeState>
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(),
Expand All @@ -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);
},
);
});
}

0 comments on commit 6a5ed0d

Please sign in to comment.