-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for rect_crop_area_clipper
- Loading branch information
1 parent
23615b5
commit c3d6b1c
Showing
6 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
Binary file added
BIN
+2.67 KB
test/widget/circle_crop_area_clipper.viewportSize200x200.crop_center.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-2.18 KB
test/widget/circle_crop_area_clipper.viewportSizex200.crop_center.png
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+646 Bytes
test/widget/rect_crop_area_clipper.viewportSize200x200.crop_center.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1.5 KB
test/widget/rect_crop_area_clipper.viewportSize200x200.crop_center_radius20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import 'package:crop_your_image/src/widget/rect_crop_area_clipper.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
test('shouldReclip is always true', () { | ||
final oldClipper = CropAreaClipper(Rect.fromLTWH(50, 50, 100, 100), 0); | ||
final clipper = CropAreaClipper(Rect.fromLTWH(50, 50, 100, 100), 0); | ||
|
||
expect(clipper.shouldReclip(oldClipper), true); | ||
}); | ||
|
||
group('when viewport is 200 x 200', () { | ||
final viewportSize = 200.0; | ||
testWidgets( | ||
'CropAreaClipper clips center with 100x100 size of rectangular shape' | ||
'if passing Rect.fromLTWH(50, 50, 100, 100)', | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
_ViewportWidget( | ||
size: viewportSize, | ||
targetWidget: RepaintBoundary( | ||
child: ClipPath( | ||
clipper: CropAreaClipper(Rect.fromLTWH(50, 50, 100, 100), 0), | ||
child: ColoredBox( | ||
color: Colors.grey, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
|
||
await expectLater( | ||
find.byType(RepaintBoundary), | ||
matchesGoldenFile( | ||
'rect_crop_area_clipper.viewportSize200x200.crop_center.png', | ||
), | ||
); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
'CropAreaClipper clips center with 100x100 size of rectangular shape with rounded corners' | ||
'if passing Rect.fromLTWH(50, 50, 100, 100) and radius: 20', | ||
(WidgetTester tester) async { | ||
await tester.pumpWidget( | ||
_ViewportWidget( | ||
size: viewportSize, | ||
targetWidget: RepaintBoundary( | ||
child: ClipPath( | ||
clipper: CropAreaClipper(Rect.fromLTWH(50, 50, 100, 100), 20), | ||
child: ColoredBox( | ||
color: Colors.grey, | ||
), | ||
), | ||
), | ||
), | ||
); | ||
|
||
await expectLater( | ||
find.byType(RepaintBoundary), | ||
matchesGoldenFile( | ||
'rect_crop_area_clipper.viewportSize200x200.crop_center_radius20.png', | ||
), | ||
); | ||
}, | ||
); | ||
}); | ||
} | ||
|
||
class _ViewportWidget extends StatelessWidget { | ||
const _ViewportWidget({ | ||
required this.size, | ||
required this.targetWidget, | ||
}); | ||
|
||
final double size; | ||
final RepaintBoundary targetWidget; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Center( | ||
child: SizedBox( | ||
width: size, | ||
height: size, | ||
child: targetWidget, | ||
), | ||
); | ||
} | ||
} |