Skip to content

Commit

Permalink
Fix test and pressed position + size bug
Browse files Browse the repository at this point in the history
  • Loading branch information
spydon committed Jan 22, 2025
1 parent 483c62b commit e623e56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
10 changes: 5 additions & 5 deletions packages/flame/lib/src/widgets/sprite_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,26 @@ class SpriteButton extends StatelessWidget {
? [
Sprite(
(images ?? Flame.images).fromCache(path),
srcSize: srcSize,
srcPosition: srcPosition,
srcSize: srcSize,
),
Sprite(
(images ?? Flame.images).fromCache(pressedPath),
srcSize: srcSize,
srcPosition: srcPosition,
srcPosition: pressedSrcPosition,
srcSize: pressedSrcSize,
),
]
: Future.wait([
Sprite.load(
path,
srcSize: srcSize,
srcPosition: srcPosition,
srcSize: srcSize,
images: images,
),
Sprite.load(
pressedPath,
srcSize: pressedSrcSize,
srcPosition: pressedSrcPosition,
srcSize: pressedSrcSize,
images: images,
),
]);
Expand Down
26 changes: 12 additions & 14 deletions packages/flame/test/widgets/sprite_button_test.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import 'dart:io';

import 'package:flame/cache.dart';
import 'package:flame/flame.dart';
import 'package:flame/widgets.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

import 'loading_widget.dart';

class _MockAssetBundle extends Mock implements AssetBundle {}
class _MockImages extends Mock implements Images {}

Future<void> main() async {
TestWidgetsFlutterBinding.ensureInitialized();
Expand Down Expand Up @@ -47,14 +44,14 @@ Future<void> main() async {
const imagePath1 = 'test_path_1';
const imagePath2 = 'test_path_2';

final bundle = _MockAssetBundle();
when(() => bundle.load(any())).thenAnswer(
(_) async {
print('CALLED!');
return generatePNGByteData();
},
final mockImageCache = _MockImages();

when(() => mockImageCache.load(any())).thenAnswer(
(_) => generateImage(),
);

when(() => mockImageCache.containsKey(any())).thenAnswer((_) => false);

await tester.pumpWidget(
SpriteButton.asset(
path: imagePath1,
Expand All @@ -64,7 +61,7 @@ Future<void> main() async {
height: 100,
label: const SizedBox(),
loadingBuilder: (_) => const LoadingWidget(),
images: Images(bundle: bundle),
images: mockImageCache,
),
);

Expand All @@ -77,7 +74,7 @@ Future<void> main() async {
expect(internalButtonFinder, findsNothing);

/// loading to be removed
await tester.pumpAndSettle();
await tester.pump();

expect(futureBuilderFinder, findsOneWidget);
expect(loadingWidgetFinder, findsNothing);
Expand All @@ -86,7 +83,8 @@ Future<void> main() async {
);

testWidgets(
'has no FutureBuilder or LoadingWidget when passed already loaded asset paths',
'has no FutureBuilder or LoadingWidget when passed already '
'loaded asset paths',
(tester) async {
const imagePath1 = 'test_path_1';
const imagePath2 = 'test_path_2';
Expand Down

0 comments on commit e623e56

Please sign in to comment.