diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart index ee960076..145e7012 100644 --- a/lib/game/pinball_game.dart +++ b/lib/game/pinball_game.dart @@ -69,7 +69,7 @@ class PinballGame extends Forge2DGame Future preFetchLeaderboard() async { try { - // _entries = await leaderboardRepository.fetchTop10Leaderboard(); + _entries = await leaderboardRepository.fetchTop10Leaderboard(); } catch (_) { // An initial null leaderboard means that we couldn't fetch // the entries for the [Backbox] and it will show the relevant display. diff --git a/lib/game/view/widgets/bonus_animation.dart b/lib/game/view/widgets/bonus_animation.dart index d97fe886..bfb9c439 100644 --- a/lib/game/view/widgets/bonus_animation.dart +++ b/lib/game/view/widgets/bonus_animation.dart @@ -111,7 +111,7 @@ class _BonusAnimationState extends State shouldRunBuildCallback = oldWidget._imagePath == widget._imagePath; Future.delayed( - Duration(seconds: animation.createTicker().totalDuration().ceil()), + Duration(seconds: duration()), () { widget._onCompleted?.call(); }, @@ -140,7 +140,7 @@ class _BonusAnimationState extends State animationTicker = animation.createTicker(); Future.delayed( - Duration(seconds: animationTicker.totalDuration().ceil()), + Duration(seconds: duration()), () { if (shouldRunBuildCallback) { widget._onCompleted?.call(); diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index 2f51f14e..3b8d437a 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -8,9 +8,11 @@ import 'package:flame_test/flame_test.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:leaderboard_repository/leaderboard_repository.dart'; import 'package:leaderboard_repository/src/leaderboard_repository.dart'; import 'package:mocktail/mocktail.dart'; import 'package:pinball/game/behaviors/behaviors.dart'; +import 'package:pinball/game/components/backbox/displays/displays.dart'; import 'package:pinball/game/game.dart'; import 'package:pinball/select_character/select_character.dart'; import 'package:pinball_audio/src/pinball_audio.dart'; @@ -61,6 +63,15 @@ class _MockGameBloc extends Mock implements GameBloc {} class _MockAppLocalizations extends Mock implements AppLocalizations { @override String get leaderboardErrorMessage => ''; + + @override + String get rank => 'rank'; + + @override + String get score => 'score'; + + @override + String get name => 'name'; } class _MockEventPosition extends Mock implements EventPosition {} @@ -234,6 +245,70 @@ void main() { ); }, ); + + flameTester.testGameWidget( + 'creates initial leaderboard if there are entries.', + setUp: (game, _) async { + final top10Scores = [ + 2500, + 2200, + 2200, + 2000, + 1800, + 1400, + 1300, + 1000, + 600, + 300, + 100, + ]; + final top10Leaderboard = top10Scores + .map( + (score) => LeaderboardEntryData( + playerInitials: 'user$score', + score: score, + character: CharacterType.dash, + ), + ) + .toList(); + when(game.leaderboardRepository.fetchTop10Leaderboard) + .thenAnswer((_) async => top10Leaderboard); + await game.preFetchLeaderboard(); + await game.preLoad(); + await game.onLoad(); + await game.ready(); + }, + verify: (game, _) async { + expect( + game + .descendants() + .whereType() + .single + .descendants() + .whereType() + .length, + equals(18), + ); + }, + ); + + flameTester.testGameWidget( + 'creates empty leaderboard if there is an error loading.', + setUp: (game, _) async { + when(game.leaderboardRepository.fetchTop10Leaderboard) + .thenThrow(Exception()); + await game.preFetchLeaderboard(); + await game.preLoad(); + await game.onLoad(); + await game.ready(); + }, + verify: (game, _) async { + expect( + game.descendants().whereType(), + isEmpty, + ); + }, + ); }); group('flipper control', () {