Skip to content

Commit

Permalink
Fix some golden tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Abestanis committed Oct 27, 2024
1 parent a46d382 commit 7c78ec1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 28 deletions.
62 changes: 36 additions & 26 deletions test/golden/routes_golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,33 @@ import '../test.dart';
void main() {
group('home_route', () {
late PermissionsChannelObserver permissionsObserver;
testAppGoldens('permissions_screen', initialization: (tester) {
permissionsObserver = PermissionsChannelObserver(tester.binding);
testAppGoldens('permissions_screen', initialization: () {
permissionsObserver = PermissionsChannelObserver(TestWidgetsFlutterBinding.ensureInitialized());
permissionsObserver.setPermission(Permission.storage, PermissionStatus.denied);
permissionsObserver.setPermission(Permission.audio, PermissionStatus.denied);
}, (WidgetTester tester) async {
await tester.tap(find.text(l10n.grant));
await tester.pumpAndSettle();
});

testAppGoldens('searching_screen', initialization: (_) {
ContentControl.instance.dispose();
final fake = FakeContentControl();
fake.init();
// Fake ContentControl.init in a way to trigger the home screen rebuild
fake.initializing = true;
fake.stateNullable = ContentState();
fake.disposed.value = false;
}, (WidgetTester tester) async {
expect(find.byType(Spinner), findsOneWidget);
}, customGoldenPump: (WidgetTester tester) async {
await tester.pump(const Duration(milliseconds: 400));
});

testAppGoldens('no_songs_screen', initialization: (_) {
testAppGoldens(
'searching_screen',
postInitialization: () {
ContentControl.instance.dispose();
final fake = FakeContentControl();
fake.init();
// Fake ContentControl.init in a way to trigger the home screen rebuild
fake.initializing = true;
fake.stateNullable = ContentState();
fake.disposed.value = false;
},
(WidgetTester tester) async {
expect(find.byType(Spinner), findsOneWidget);
},
customGoldenPump: (WidgetTester tester) => tester.pump(const Duration(milliseconds: 400)),
);

testAppGoldens('no_songs_screen', initialization: () {
FakeSweyerPluginPlatform.instance.songs = [];
}, (WidgetTester tester) async {
await tester.pumpAndSettle();
Expand Down Expand Up @@ -82,7 +85,7 @@ void main() {
});

final List<Song> songs = List.unmodifiable(List.generate(10, (index) => songWith(id: index)));
testAppGoldens('selection_deletion_dialog_songs_tab', initialization: (_) {
testAppGoldens('selection_deletion_dialog_songs_tab', initialization: () {
final fake = FakeDeviceInfoControl();
DeviceInfoControl.instance = fake;
fake.sdkInt = 29;
Expand All @@ -96,7 +99,7 @@ void main() {
await tester.pumpAndSettle();
});

testAppGoldens('scroll_labels', initialization: (_) {
testAppGoldens('scroll_labels', initialization: () {
FakeSweyerPluginPlatform.instance.songs =
List.generate(26, (index) => songWith(id: index, title: String.fromCharCode('A'.codeUnitAt(0) + index)));
}, (WidgetTester tester) async {
Expand All @@ -115,7 +118,7 @@ void main() {
});

group('persistent_queue_route', () {
testAppGoldens('album_route', initialization: (_) {
testAppGoldens('album_route', initialization: () {
FakeSweyerPluginPlatform.instance.songs = [
songWith(id: 0, track: null, title: 'Null Song 1'),
songWith(id: 5, track: null, title: 'Null Song 2'),
Expand Down Expand Up @@ -171,11 +174,18 @@ void main() {
});

group('player_route', () {
testAppGoldens('player_route', (WidgetTester tester) async {
await tester.tap(find.byType(SongTile));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(playerRouteController.value, 1.0);
}, playerInterfaceColorStylesToTest: PlayerInterfaceColorStyle.values.toSet());
testAppGoldens(
'player_route',
(WidgetTester tester) async {
await tester.tap(find.byType(SongTile));
await tester.pump(); // Flush micro-tasks so to flush handling of the tap.
// Don't use `pumpAndSettle` because we have animations because we are playing a song.
await tester.pump(const Duration(seconds: 1));
expect(playerRouteController.value, 1.0);
},
customGoldenPump: (WidgetTester tester) => tester.pump(Duration.zero),
playerInterfaceColorStylesToTest: PlayerInterfaceColorStyle.values.toSet(),
);

testAppGoldens('queue_route', (WidgetTester tester) async {
await tester.openPlayerQueueScreen();
Expand Down Expand Up @@ -250,7 +260,7 @@ void main() {
final localFavoriteButNotInMediaStoreSong = songWith(id: 2, title: 'Local only favorite');
final mediaStoreFavoriteButNotLocalSong =
songWith(id: 3, isFavoriteInMediaStore: true, title: 'MediaStore only favorite');
testAppGoldens('general_settings_favorite_conflict_dialog', initialization: (_) {
testAppGoldens('general_settings_favorite_conflict_dialog', initialization: () {
FakeSweyerPluginPlatform.instance.songs = [
songWith(),
localFavoriteAndMediaStoreSong,
Expand Down
6 changes: 4 additions & 2 deletions test/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ void testAppGoldens(
bool? skip,
Object? tags = _defaultTagObject,
Set<PlayerInterfaceColorStyle> playerInterfaceColorStylesToTest = const {_defaultPlayerInterfaceColorStyle},
void Function(WidgetTester)? initialization,
VoidCallback? initialization,
VoidCallback? postInitialization,
CustomPump? customGoldenPump,
}) {
assert(playerInterfaceColorStylesToTest.isNotEmpty);
Expand Down Expand Up @@ -373,10 +374,11 @@ void testAppGoldens(
_testersPlayerInterfaceColorStyle[tester] = playerInterfaceColorStyle;
}
return tester.runAppTest(
initialization: () => initialization?.call(tester),
initialization: () => initialization?.call(),
postInitialization: () {
ThemeControl.instance.setThemeLightMode(lightTheme);
Settings.playerInterfaceColorStyle.set(playerInterfaceColorStyle);
postInitialization?.call();
},
() => test(tester),
goldenCaptureCallback: () => tester.screenMatchesGolden(
Expand Down

0 comments on commit 7c78ec1

Please sign in to comment.