import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:image/image.dart' as img; import 'package:tane/ui/photo_crop.dart'; void main() { // A small but real PNG the cropper can decode. final bytes = Uint8List.fromList( img.encodePng(img.Image(width: 32, height: 32)), ); testWidgets('cropToSquare shows a cancel/confirm UI and cancel returns null', ( tester, ) async { Uint8List? result; var returned = false; await tester.pumpWidget(MaterialApp( home: Builder( builder: (context) => Scaffold( body: Center( child: ElevatedButton( onPressed: () async { result = await cropToSquare(context, bytes); returned = true; }, child: const Text('open'), ), ), ), ), )); await tester.tap(find.text('open')); await tester.pump(); // push the crop route await tester.pump(const Duration(milliseconds: 100)); expect(find.byKey(const Key('crop.confirm')), findsOneWidget); expect(find.byKey(const Key('crop.cancel')), findsOneWidget); await tester.tap(find.byKey(const Key('crop.cancel'))); await tester.pump(); // pop the crop route expect(returned, isTrue); expect(result, isNull); // cancelling yields no image }); }