mirror of https://github.com/flutter/pinball.git
parent
b72ff3178f
commit
631518395b
@ -0,0 +1 @@
|
|||||||
|
export 'mocks.dart';
|
@ -0,0 +1,34 @@
|
|||||||
|
// ignore_for_file: one_member_abstracts
|
||||||
|
|
||||||
|
import 'package:audioplayers/audioplayers.dart';
|
||||||
|
import 'package:flame_audio/audio_pool.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
|
||||||
|
abstract class _CreateAudioPoolStub {
|
||||||
|
Future<AudioPool> onCall(
|
||||||
|
String sound, {
|
||||||
|
bool? repeating,
|
||||||
|
int? maxPlayers,
|
||||||
|
int? minPlayers,
|
||||||
|
String? prefix,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class CreateAudioPoolStub extends Mock implements _CreateAudioPoolStub {}
|
||||||
|
|
||||||
|
abstract class _ConfigureAudioCacheStub {
|
||||||
|
void onCall(AudioCache cache);
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConfigureAudioCacheStub extends Mock implements _ConfigureAudioCacheStub {
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class _PlaySingleAudioStub {
|
||||||
|
Future<void> onCall(String url);
|
||||||
|
}
|
||||||
|
|
||||||
|
class PlaySingleAudioStub extends Mock implements _PlaySingleAudioStub {}
|
||||||
|
|
||||||
|
class MockAudioPool extends Mock implements AudioPool {}
|
||||||
|
|
||||||
|
class MockAudioCache extends Mock implements AudioCache {}
|
@ -1,11 +1,110 @@
|
|||||||
// ignore_for_file: prefer_const_constructors
|
// ignore_for_file: prefer_const_constructors
|
||||||
|
import 'package:flame_audio/flame_audio.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball_audio/gen/assets.gen.dart';
|
||||||
import 'package:pinball_audio/pinball_audio.dart';
|
import 'package:pinball_audio/pinball_audio.dart';
|
||||||
|
|
||||||
|
import '../helpers/helpers.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('PinballAudio', () {
|
group('PinballAudio', () {
|
||||||
test('can be instantiated', () {
|
test('can be instantiated', () {
|
||||||
expect(PinballAudio(), isNotNull);
|
expect(PinballAudio(), isNotNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
late CreateAudioPoolStub createAudioPool;
|
||||||
|
late ConfigureAudioCacheStub configureAudioCache;
|
||||||
|
late PlaySingleAudioStub playSingleAudio;
|
||||||
|
late PinballAudio audio;
|
||||||
|
|
||||||
|
setUpAll(() {
|
||||||
|
registerFallbackValue(MockAudioCache());
|
||||||
|
});
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
createAudioPool = CreateAudioPoolStub();
|
||||||
|
when(
|
||||||
|
() => createAudioPool.onCall(
|
||||||
|
any(),
|
||||||
|
maxPlayers: any(named: 'maxPlayers'),
|
||||||
|
prefix: any(named: 'prefix'),
|
||||||
|
),
|
||||||
|
).thenAnswer((_) async => MockAudioPool());
|
||||||
|
|
||||||
|
configureAudioCache = ConfigureAudioCacheStub();
|
||||||
|
when(() => configureAudioCache.onCall(any())).thenAnswer((_) {});
|
||||||
|
|
||||||
|
playSingleAudio = PlaySingleAudioStub();
|
||||||
|
when(() => playSingleAudio.onCall(any())).thenAnswer((_) async {});
|
||||||
|
|
||||||
|
audio = PinballAudio(
|
||||||
|
configureAudioCache: configureAudioCache.onCall,
|
||||||
|
createAudioPool: createAudioPool.onCall,
|
||||||
|
playSingleAudio: playSingleAudio.onCall,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('load', () {
|
||||||
|
test('creates the score pool', () async {
|
||||||
|
await audio.load();
|
||||||
|
|
||||||
|
verify(
|
||||||
|
() => createAudioPool.onCall(
|
||||||
|
'packages/pinball_audio/${Assets.sfx.plim}',
|
||||||
|
maxPlayers: 4,
|
||||||
|
prefix: '',
|
||||||
|
),
|
||||||
|
).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('configures the audio cache instance', () async {
|
||||||
|
await audio.load();
|
||||||
|
|
||||||
|
verify(() => configureAudioCache.onCall(FlameAudio.audioCache))
|
||||||
|
.called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('sets the correct prefix', () async {
|
||||||
|
audio = PinballAudio(
|
||||||
|
createAudioPool: createAudioPool.onCall,
|
||||||
|
playSingleAudio: playSingleAudio.onCall,
|
||||||
|
);
|
||||||
|
await audio.load();
|
||||||
|
|
||||||
|
expect(FlameAudio.audioCache.prefix, equals(''));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('score', () {
|
||||||
|
test('plays the score sound pool', () async {
|
||||||
|
final audioPool = MockAudioPool();
|
||||||
|
when(audioPool.start).thenAnswer((_) async => () {});
|
||||||
|
when(
|
||||||
|
() => createAudioPool.onCall(
|
||||||
|
any(),
|
||||||
|
maxPlayers: any(named: 'maxPlayers'),
|
||||||
|
prefix: any(named: 'prefix'),
|
||||||
|
),
|
||||||
|
).thenAnswer((_) async => audioPool);
|
||||||
|
|
||||||
|
await audio.load();
|
||||||
|
audio.score();
|
||||||
|
|
||||||
|
verify(audioPool.start).called(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('googleBonus', () {
|
||||||
|
test('plays the correct file', () async {
|
||||||
|
await audio.load();
|
||||||
|
audio.googleBonus();
|
||||||
|
|
||||||
|
verify(
|
||||||
|
() => playSingleAudio
|
||||||
|
.onCall('packages/pinball_audio/${Assets.sfx.google}'),
|
||||||
|
).called(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue