Skip to content

Commit

Permalink
add tests for rect_crop_area_clipper
Browse files Browse the repository at this point in the history
  • Loading branch information
chooyan-eng committed Feb 15, 2024
1 parent 23615b5 commit c3d6b1c
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 3 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
6 changes: 3 additions & 3 deletions test/widget/circle_crop_area_clipper_test.dart
@@ -1,5 +1,5 @@
import 'package:crop_your_image/src/widget/circle_crop_area_clipper.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
Expand All @@ -24,7 +24,7 @@ void main() {
child: ClipPath(
clipper: CircleCropAreaClipper(Rect.fromLTWH(50, 50, 100, 100)),
child: ColoredBox(
color: Color(0xFF0000FF),
color: Colors.grey,
),
),
),
Expand All @@ -34,7 +34,7 @@ void main() {
await expectLater(
find.byType(RepaintBoundary),
matchesGoldenFile(
'circle_crop_area_clipper.viewportSizex200.crop_center.png'),
'circle_crop_area_clipper.viewportSize200x200.crop_center.png'),
);
},
);
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
90 changes: 90 additions & 0 deletions test/widget/rect_crop_area_clipper_test.dart
@@ -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,
),
);
}
}

0 comments on commit c3d6b1c

Please sign in to comment.