Skip to content

Commit

Permalink
Add tap more info on release event detail screen
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Mar 19, 2024
1 parent 8813458 commit 8910168
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:vocadb_app/src/constants/app_sizes.dart';
import 'package:vocadb_app/src/features/releaseEvents/domain/release_event.dart';
import 'package:vocadb_app/src/utils/url_launcher.dart';

class ReleaseEventDetailButtonBar extends StatelessWidget {
const ReleaseEventDetailButtonBar({super.key});
final ReleaseEvent releaseEvent;
const ReleaseEventDetailButtonBar({super.key, required this.releaseEvent});

static const addBtnKey = Key('add-btn-key');
static const shareBtnKey = Key('share-btn-key');
Expand All @@ -19,8 +23,8 @@ class ReleaseEventDetailButtonBar extends StatelessWidget {
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: Column(
children: const [
child: const Column(
children: [
Icon(Icons.favorite),
gapH4,
Text('Like'),
Expand All @@ -33,28 +37,32 @@ class ReleaseEventDetailButtonBar extends StatelessWidget {
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: Column(
children: const [
child: const Column(
children: [
Icon(Icons.share),
gapH4,
Text('Share'),
],
),
),
TextButton(
key: infoBtnKey,
onPressed: () => {},
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: Column(
children: const [
Icon(Icons.info),
gapH4,
Text('Info'),
],
),
),
Consumer(builder: (context, ref, _) {
return TextButton(
key: infoBtnKey,
onPressed: () {
ref.read(urlLauncherProvider).launchReleaseEventMoreInfo(releaseEvent.id);
},
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: const Column(
children: [
Icon(Icons.info),
gapH4,
Text('Info'),
],
),
);
}),
],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class ReleaseEventDetailScreen extends StatelessWidget {
),
SliverList(
delegate: SliverChildListDelegate([
const ReleaseEventDetailButtonBar(),
ReleaseEventDetailButtonBar(releaseEvent: releaseEvent,),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/utils/url_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class UrlLauncher {

launchTagMoreInfo(int id) =>
launchUrlString('$host/T/$id');

launchReleaseEventMoreInfo(int id) =>
launchUrlString('$host/E/$id');
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,36 @@ void main() {
await r.expectAlbumsListVisible(false);
await r.expectWebLinksVisible(false);
});

testWidgets('tap more info on release event detail screen', (tester) async {
final r = ReleaseEventRobot(tester);
final releaseEventRepository = MockReleaseEventRepository();
final urlLauncher = MockUrlLauncher();

when(() => releaseEventRepository.fetchReleaseEventByID(any()))
.thenAnswer((_) => Future.value(kFakeReleaseEventDetail));

when(() => releaseEventRepository.fetchAlbums(any()))
.thenAnswer((_) => Future.value(kFakeAlbumsList));

when(() => releaseEventRepository.fetchPublishedSongs(any()))
.thenAnswer((_) => Future.value(kFakeSongsList));

await r.pumpReleaseEventDetailScreen(
releaseEventRepository: releaseEventRepository,
urlLauncher: urlLauncher
);

await tester.pump();

await r.expectErrorMessageWidgetNotVisible();

await r.expectAddButtonVisible();
await r.expectShareButtonVisible();
await r.expectInfoButtonVisible();

await r.tapMoreInfo();

verify(() => urlLauncher.launchReleaseEventMoreInfo(kFakeReleaseEventDetail.id)).called(1);
});
}
14 changes: 13 additions & 1 deletion test/src/features/releaseEvents/release_event_robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:vocadb_app/src/features/releaseEvents/presentation/release_event
import 'package:vocadb_app/src/features/songs/presentation/songs_list/songs_list_view.dart';
import 'package:vocadb_app/src/features/tags/presentation/tag_widgets/tag_usage_group_view.dart';
import 'package:vocadb_app/src/features/weblinks/presentation/web_link_group_view.dart';
import 'package:vocadb_app/src/utils/url_launcher.dart';

class ReleaseEventRobot {
final WidgetTester tester;
Expand All @@ -18,13 +19,17 @@ class ReleaseEventRobot {

Future<void> pumpReleaseEventDetailScreen({
ReleaseEventRepository? releaseEventRepository,
UrlLauncher? urlLauncher
}) async {
await tester.pumpWidget(
ProviderScope(
overrides: [
if (releaseEventRepository != null)
releaseEventRepositoryProvider
.overrideWithValue(releaseEventRepository)
.overrideWithValue(releaseEventRepository),
if (urlLauncher != null)
urlLauncherProvider
.overrideWithValue(urlLauncher)
],
child: const MaterialApp(
home: ReleaseEventDetailScreen(
Expand Down Expand Up @@ -91,6 +96,13 @@ class ReleaseEventRobot {
expect(finder, findsOneWidget);
}

Future<void> tapMoreInfo() async {
final finder = find.byKey(ReleaseEventDetailButtonBar.infoBtnKey);
expect(finder, findsOneWidget);
await tester.tap(finder);
await tester.pump();
}

Future<void> expectTagNameIs(String name) async {
final finder = find.widgetWithText(ListTile, name);
expect(finder, findsOneWidget);
Expand Down

0 comments on commit 8910168

Please sign in to comment.