You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pinball/test/helpers/pump_app.dart

101 lines
3.2 KiB

import 'package:bloc_test/bloc_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leaderboard_repository/leaderboard_repository.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pinball/assets_manager/assets_manager.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/select_character/select_character.dart';
import 'package:pinball/start_game/start_game.dart';
import 'package:pinball_audio/pinball_audio.dart';
import 'package:pinball_ui/pinball_ui.dart';
class _MockAssetsManagerCubit extends Mock implements AssetsManagerCubit {}
class _MockLeaderboardRepository extends Mock implements LeaderboardRepository {
}
class _MockCharacterThemeCubit extends Mock implements CharacterThemeCubit {}
class _MockGameBloc extends Mock implements GameBloc {}
class _MockStartGameBloc extends Mock implements StartGameBloc {}
class _MockPinballAudio extends Mock implements PinballAudio {}
PinballAudio _buildDefaultPinballAudio() {
final audio = _MockPinballAudio();
when(audio.load).thenAnswer((_) => Future.value());
return audio;
}
AssetsManagerCubit _buildDefaultAssetsManagerCubit() {
final cubit = _MockAssetsManagerCubit();
final state = AssetsManagerState(
loadables: [Future<void>.value()],
loaded: [Future<void>.value()],
);
whenListen(
cubit,
Stream.value(state),
initialState: state,
);
return cubit;
}
extension PumpApp on WidgetTester {
Future<void> pumpApp(
Widget widget, {
GameBloc? gameBloc,
StartGameBloc? startGameBloc,
AssetsManagerCubit? assetsManagerCubit,
CharacterThemeCubit? characterThemeCubit,
LeaderboardRepository? leaderboardRepository,
PinballAudio? pinballAudio,
}) {
return runAsync(() {
return pumpWidget(
MultiRepositoryProvider(
providers: [
RepositoryProvider.value(
value: leaderboardRepository ?? _MockLeaderboardRepository(),
),
RepositoryProvider.value(
value: pinballAudio ?? _buildDefaultPinballAudio(),
),
],
child: MultiBlocProvider(
providers: [
BlocProvider.value(
value: characterThemeCubit ?? _MockCharacterThemeCubit(),
),
BlocProvider.value(
value: gameBloc ?? _MockGameBloc(),
),
BlocProvider.value(
value: startGameBloc ?? _MockStartGameBloc(),
),
BlocProvider.value(
value: assetsManagerCubit ?? _buildDefaultAssetsManagerCubit(),
),
],
child: MaterialApp(
theme: PinballTheme.standard,
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
],
supportedLocales: AppLocalizations.supportedLocales,
home: widget,
),
),
),
);
});
}
}