Skip to content

Commit

Permalink
add golden test to CircleCropAreaClipper (#140)
Browse files Browse the repository at this point in the history
* add golden test to CircleCropAreaClipper

* add test case to shouldReclip
  • Loading branch information
chooyan-eng authored Feb 14, 2024
1 parent a18b1c2 commit e6fab4e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions test/widget/circle_crop_area_clipper_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import 'package:crop_your_image/src/widget/circle_crop_area_clipper.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
test('shouldReclip is always true', () {
final oldClipper = CircleCropAreaClipper(Rect.fromLTWH(50, 50, 100, 100));
final clipper = CircleCropAreaClipper(Rect.fromLTWH(50, 50, 100, 100));

expect(clipper.shouldReclip(oldClipper), true);
});

group('when viewport is 200 x 200', () {
final viewportSize = 200.0;
testWidgets(
'CircleCropAreaClipper clips center with 100x100 size of circle shape'
'if passing Rect.fromLTWH(50, 50, 100, 100)',
(WidgetTester tester) async {
Widget actual = Center(
child: SizedBox(
width: viewportSize,
height: viewportSize,
child: RepaintBoundary(
child: ClipPath(
clipper: CircleCropAreaClipper(Rect.fromLTWH(50, 50, 100, 100)),
child: ColoredBox(
color: Color(0xFF0000FF),
),
),
),
),
);
await tester.pumpWidget(actual);
await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile(
'circle_crop_area_clipper.viewportSizex200.crop_center.png'),
);
},
);
});
}

0 comments on commit e6fab4e

Please sign in to comment.