Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test allowCompleteWithEmptyEditing #17

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## Version 2.5.2
- **Fix:** fix: The `allowCompleteWithEmptyEditing` logic was dropped by the committing.

## Version 2.5.1
- **Feat:** Set theme for alert dialog. Details in [GitHub pull #16](https://github.com/hm21/pro_image_editor/pull/16)

Expand Down
16 changes: 11 additions & 5 deletions lib/pro_image_editor_main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1635,7 +1635,11 @@ class ProImageEditorState extends State<ProImageEditor> {
/// is in progress.
void doneEditing() async {
if (_editPosition <= 0 && _layers.isEmpty) {
return closeEditor();
final allowCompleteWithEmptyEditing =
widget.allowCompleteWithEmptyEditing ?? false;
if (!allowCompleteWithEmptyEditing) {
return closeEditor();
}
}
_doneEditing = true;
LoadingDialog loading = LoadingDialog()
Expand All @@ -1648,11 +1652,12 @@ class ProImageEditorState extends State<ProImageEditor> {
imageEditorTheme: widget.configs.imageEditorTheme,
);

var bytes = await _screenshotCtrl.capture(pixelRatio: _pixelRatio);
Uint8List bytes = Uint8List.fromList([]);
try {
bytes = await _screenshotCtrl.capture(pixelRatio: _pixelRatio) ?? bytes;
} catch (_) {}

if (bytes != null) {
await widget.onImageEditingComplete(bytes);
}
await widget.onImageEditingComplete(bytes);

if (mounted) loading.hide(context);

Expand Down Expand Up @@ -1960,6 +1965,7 @@ class ProImageEditorState extends State<ProImageEditor> {
onPressed: redoAction,
),
IconButton(
key: const ValueKey('TextEditorMainDoneButton'),
tooltip: widget.configs.i18n.done,
padding: const EdgeInsets.symmetric(horizontal: 8),
icon: Icon(widget.configs.icons.doneIcon),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pro_image_editor
description: "A Flutter image editor: Seamlessly enhance your images with user-friendly editing features."
version: 2.5.1
version: 2.5.2
homepage: https://github.com/hm21/pro_image_editor/
repository: https://github.com/hm21/pro_image_editor/
issue_tracker: https://github.com/hm21/pro_image_editor/issues/
Expand Down
36 changes: 36 additions & 0 deletions test/pro_image_editor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,40 @@ void main() {
final layers3 = find.byType(LayerWidget);
expect(layers3, findsOneWidget);
});

testWidgets(
'ProImageEditor performs done action with allowCompleteWithEmptyEditing',
(WidgetTester tester) async {
Future test({
required bool givingAllowCompleteWithEmptyEditing,
required bool expectedHasCompleteEdit,
}) async {
var hasCompleteEdit = false;
await tester.pumpWidget(MaterialApp(
home: ProImageEditor.memory(
fakeMemoryImage,
allowCompleteWithEmptyEditing: givingAllowCompleteWithEmptyEditing,
onImageEditingComplete: (Uint8List bytes) async {
hasCompleteEdit = true;
},
)));

// Press done button without any editing;
final doneBtn = find.byKey(const ValueKey('TextEditorMainDoneButton'));
expect(doneBtn, findsOneWidget);
await tester.tap(doneBtn);
try {
await tester.pumpAndSettle();
} catch (_) {}

expect(hasCompleteEdit, expectedHasCompleteEdit);
}

await test(
givingAllowCompleteWithEmptyEditing: true,
expectedHasCompleteEdit: true);
await test(
givingAllowCompleteWithEmptyEditing: false,
expectedHasCompleteEdit: false);
});
}
Loading