Skip to content
This repository was archived by the owner on Aug 14, 2023. It is now read-only.

fix: reenable test optimizations #415

Merged
merged 6 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ jobs:
flutter_channel: "beta"
flutter_version: 3.6.0-0.1.pre
coverage_excludes: "**/*.g.dart"
test_optimization: false
21 changes: 17 additions & 4 deletions lib/share/widgets/portal_animation.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:async';
import 'dart:math' as math;
import 'dart:typed_data';
import 'dart:ui';

import 'package:flame/cache.dart';
import 'package:flame/components.dart';
import 'package:flame/effects.dart';
import 'package:flame/game.dart';
Expand Down Expand Up @@ -101,23 +103,34 @@ class PortalGame extends FlameGame {
required this.mode,
required this.imageBytes,
required this.onComplete,
});
Future<Image> Function(Uint8List)? decodeImage,
Future<SpriteAnimation> Function(String, SpriteAnimationData)?
loadAnimation,
}) {
_decodeImageFromList = decodeImage ?? decodeImageFromList;
_loadAnimation = loadAnimation ?? loadSpriteAnimation;
}

final PortalMode mode;

final Uint8List imageBytes;

final VoidCallback onComplete;

late final Future<Image> Function(Uint8List) _decodeImageFromList;

late final Future<SpriteAnimation> Function(String, SpriteAnimationData)
_loadAnimation;

@override
Future<void> onLoad() async {
images = Images(prefix: '');
final data = mode.data;
images.prefix = '';
final image = await decodeImageFromList(imageBytes);
final image = await _decodeImageFromList(imageBytes);

final thumb = Sprite(image);

final animation = await loadSpriteAnimation(
final animation = await _loadAnimation(
data.texturePath,
SpriteAnimationData.sequenced(
amount: data.frameAmout,
Expand Down
41 changes: 40 additions & 1 deletion test/share/widgets/portal_animation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,40 @@ import 'dart:ui';
import 'package:flame/components.dart';
import 'package:flame/game.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' hide Image;
import 'package:flutter_test/flutter_test.dart';
import 'package:holobooth/share/share.dart';
import 'package:mocktail/mocktail.dart';

class _MockImage extends Mock implements Image {
@override
String toString({DiagnosticLevel minLevel = DiagnosticLevel.debug}) {
return '';
}
}

class _MockSpriteAnimation extends Mock implements SpriteAnimation {
@override
VoidCallback? onComplete;

@override
void update(_) {
onComplete?.call();
}
}

Image _createMockImage() {
final image = _MockImage();
when(() => image.width).thenReturn(100);
when(() => image.height).thenReturn(100);
return image;
}

SpriteAnimation _createMockSpriteAnimation() {
final animation = _MockSpriteAnimation();

return animation;
}

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
Expand All @@ -26,6 +57,8 @@ void main() {
mode: PortalMode.portrait,
imageBytes: imageBytes,
onComplete: () {},
decodeImage: (_) async => _createMockImage(),
loadAnimation: (_, __) async => _createMockSpriteAnimation(),
),
(game) async {
await game.ready();
Expand All @@ -42,6 +75,8 @@ void main() {
mode: PortalMode.landscape,
imageBytes: imageBytes,
onComplete: () {},
decodeImage: (_) async => _createMockImage(),
loadAnimation: (_, __) async => _createMockSpriteAnimation(),
),
(game) async {
await game.ready();
Expand All @@ -58,6 +93,8 @@ void main() {
mode: PortalMode.landscape,
imageBytes: imageBytes,
onComplete: () {},
decodeImage: (_) async => _createMockImage(),
loadAnimation: (_, __) async => _createMockSpriteAnimation(),
),
(game) async {
await game.ready();
Expand All @@ -76,6 +113,8 @@ void main() {
mode: PortalMode.landscape,
imageBytes: imageBytes,
onComplete: () {},
decodeImage: (_) async => _createMockImage(),
loadAnimation: (_, __) async => _createMockSpriteAnimation(),
),
(game) async {
await game.ready();
Expand Down