Skip to content

Commit

Permalink
Add tap share on release event detail screen
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed Mar 20, 2024
1 parent b384f55 commit 1a72abf
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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/share_launcher.dart';
import 'package:vocadb_app/src/utils/url_launcher.dart';

class ReleaseEventDetailButtonBar extends StatelessWidget {
Expand All @@ -24,32 +25,36 @@ class ReleaseEventDetailButtonBar extends StatelessWidget {
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: const Column(
children: [
children: [
Icon(Icons.favorite),
gapH4,
Text('Like'),
],
),
),
TextButton(
key: shareBtnKey,
onPressed: () => {},
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: const Column(
children: [
Icon(Icons.share),
gapH4,
Text('Share'),
],
),
),
Consumer(builder: (context, ref, _) {
return TextButton(
key: shareBtnKey,
onPressed: () => ref.read(shareLauncherProvider).shareReleaseEvent(releaseEvent.id),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: const Column(
children: [
Icon(Icons.share),
gapH4,
Text('Share'),
],
),
);
}),
Consumer(builder: (context, ref, _) {
return TextButton(
key: infoBtnKey,
onPressed: () {
ref.read(urlLauncherProvider).launchReleaseEventMoreInfo(releaseEvent.id);
ref
.read(urlLauncherProvider)
.launchReleaseEventMoreInfo(releaseEvent.id);
},
style: ButtonStyle(
foregroundColor: MaterialStateProperty.all<Color>(Colors.white),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,36 @@ void main() {

verify(() => urlLauncher.launchReleaseEventMoreInfo(kFakeReleaseEventDetail.id)).called(1);
});

testWidgets('tap share on release event detail screen', (tester) async {
final r = ReleaseEventRobot(tester);
final releaseEventRepository = MockReleaseEventRepository();
final shareLauncher = MockShareLauncher();

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,
shareLauncher: shareLauncher
);

await tester.pump();

await r.expectErrorMessageWidgetNotVisible();

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

await r.tapShare();

verify(() => shareLauncher.shareReleaseEvent(kFakeReleaseEventDetail.id)).called(1);
});
}
16 changes: 14 additions & 2 deletions 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/share_launcher.dart';
import 'package:vocadb_app/src/utils/url_launcher.dart';

class ReleaseEventRobot {
Expand All @@ -19,7 +20,8 @@ class ReleaseEventRobot {

Future<void> pumpReleaseEventDetailScreen({
ReleaseEventRepository? releaseEventRepository,
UrlLauncher? urlLauncher
UrlLauncher? urlLauncher,
ShareLauncher? shareLauncher
}) async {
await tester.pumpWidget(
ProviderScope(
Expand All @@ -29,7 +31,10 @@ class ReleaseEventRobot {
.overrideWithValue(releaseEventRepository),
if (urlLauncher != null)
urlLauncherProvider
.overrideWithValue(urlLauncher)
.overrideWithValue(urlLauncher),
if (shareLauncher != null)
shareLauncherProvider
.overrideWithValue(shareLauncher)
],
child: const MaterialApp(
home: ReleaseEventDetailScreen(
Expand Down Expand Up @@ -103,6 +108,13 @@ class ReleaseEventRobot {
await tester.pump();
}

Future<void> tapShare() async {
final finder = find.byKey(ReleaseEventDetailButtonBar.shareBtnKey);
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 1a72abf

Please sign in to comment.