// Author: fruit.com.cn import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:fruitshorts/pages/player/widgets/player_double_tap_hearts.dart'; void main() { testWidgets('heart pixels start at origin and move upward', (tester) async { tester.view.physicalSize = const Size(400, 800); tester.view.devicePixelRatio = 1; addTearDown(tester.view.resetPhysicalSize); addTearDown(tester.view.resetDevicePixelRatio); var completedCalls = 0; const origin = Offset(300, 546); await tester.pumpWidget( MaterialApp( home: Scaffold( body: Stack( fit: StackFit.expand, clipBehavior: Clip.none, children: [ Positioned.fill( child: PlayerDoubleTapHeartBurst( burstId: 91, origin: origin, onCompleted: () => completedCalls++, ), ), ], ), ), ), ); final firstHeart = find.byKey(const Key('double-tap-heart-0')); expect(firstHeart, findsOneWidget); final firstSize = tester.getSize(firstHeart); final initialCenter = tester.getCenter(firstHeart); debugPrint( '[heart-pixels] initial size=${firstSize.width}x${firstSize.height} ' 'center=${initialCenter.dx},${initialCenter.dy}', ); expect(firstSize.width, closeTo(48, 1)); expect(firstSize.height, closeTo(48, 1)); expect(firstSize.width, greaterThan(20)); expect((initialCenter - origin).distance, lessThanOrEqualTo(1)); expect( (tester.getTopLeft(find.byKey(const Key('heart-burst-elapsed-debug'))) - const Offset(308, 556)) .distance, lessThanOrEqualTo(1), ); await tester.pump(const Duration(milliseconds: 400)); final midpoint = tester.getCenter(firstHeart); debugPrint( '[heart-pixels] after400ms center=${midpoint.dx},${midpoint.dy}', ); expect(midpoint.dy, lessThan(origin.dy - 40)); expect((midpoint.dx - origin.dx).abs(), lessThanOrEqualTo(30)); await tester.pump(const Duration(milliseconds: 1200)); expect(completedCalls, 1); }); }