Skip to content

Commit

Permalink
feat(interface): add coverage badge and min coverage to 90
Browse files Browse the repository at this point in the history
  • Loading branch information
criistian14 committed Jan 18, 2025
1 parent 00dac1c commit 2b6041a
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ jobs:
flutter_channel: stable
flutter_version: 3.24.0
working_directory: flutter_document_scanner_platform_interface
min_coverage: 80
min_coverage: 90

upload-coverage:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: flutter_document_scanner_platform_interface/coverage/lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
flags: flutter_document_scanner_platform_interface
fail_ci_if_error: true
8 changes: 8 additions & 0 deletions flutter_document_scanner_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
## 2.0.0

* Replaced Equatable with manual property comparisons using Dart.
* Added error handling to improve process control.
* Implemented unit tests to ensure the correctness of changes.

## 1.0.0

* Stable version with basic functionality and new structure

# 0.5.0

* Initial release.
9 changes: 7 additions & 2 deletions flutter_document_scanner_platform_interface/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# flutter_document_scanner_platform_interface

[![style: very good analysis][very_good_analysis_badge]][very_good_analysis_link]
[![Coverage](https://codecov.io/gh/criistian14/flutter_document_scanner/branch/master/graph/badge.svg?flag=flutter_document_scanner_platform_interface)](https://codecov.io/gh/criistian14/flutter_document_scanner)

A common platform interface for the [`flutter_document_scanner`][pub_link] plugin.

This interface allows platform-specific implementations of the `flutter_document_scanner` plugin, as well as the plugin itself, to ensure they are supporting the same interface.
This interface allows platform-specific implementations of the `flutter_document_scanner` plugin, as well as the plugin
itself, to ensure they are supporting the same interface.

# Usage

To implement a new platform-specific implementation of `flutter_document_scanner`, extend `FlutterDocumentScannerPlatform` with an implementation that performs the platform-specific behavior.
To implement a new platform-specific implementation of `flutter_document_scanner`, extend
`FlutterDocumentScannerPlatform` with an implementation that performs the platform-specific behavior.

[pub_link]: https://pub.dev/packages/flutter_document_scanner

[very_good_analysis_badge]: https://img.shields.io/badge/style-very_good_analysis-B22C89.svg

[very_good_analysis_link]: https://pub.dev/packages/very_good_analysis
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,27 @@ class FlutterDocumentScannerMock extends FlutterDocumentScannerPlatform {
],
);
}

@override
Future<Uint8List> applyFilter({
required Uint8List byteData,
required FilterType filter,
}) async {
return byteData;
}

@override
Future<Uint8List> adjustingPerspective({
required Uint8List byteData,
required Contour contour,
}) async {
return byteData;
}
}

class FlutterDocumentScannerNotImplemented
extends FlutterDocumentScannerPlatform {}

void main() {
TestWidgetsFlutterBinding.ensureInitialized();

Expand All @@ -39,8 +58,9 @@ void main() {
FlutterDocumentScannerPlatform.instance = flutterDocumentScannerPlatform;
});

group('getPlatformName', () {
test('returns correct name', () async {
test(
'Should return expected contour when findContourPhoto is called',
() async {
final tByteData = Uint8List(1);
const tMinContourArea = 120.0;

Expand All @@ -56,7 +76,125 @@ void main() {
),
),
);
});
});
},
);

test(
'Should return the same byte data when applyFilter is called',
() async {
final tByteData = Uint8List.fromList([1, 2, 3]);
const tFilterType = FilterType.natural;

expect(
await FlutterDocumentScannerPlatform.instance.applyFilter(
byteData: tByteData,
filter: tFilterType,
),
equals(
await flutterDocumentScannerPlatform.applyFilter(
byteData: tByteData,
filter: tFilterType,
),
),
);
},
);

test(
'Should return the same byte data when adjustingPerspective is called',
() async {
final tByteData = Uint8List.fromList([1, 2, 3]);
const tContour = Contour(
points: [
Point(10.5, 50.8),
Point(0.2, 8),
Point(10.5, 50.8),
Point(0.2, 8),
],
);

expect(
await FlutterDocumentScannerPlatform.instance.adjustingPerspective(
byteData: tByteData,
contour: tContour,
),
equals(
await flutterDocumentScannerPlatform.adjustingPerspective(
byteData: tByteData,
contour: tContour,
),
),
);
},
);
});

group('FlutterDocumentScannerNotImplemented', () {
test(
'Should throw UnimplementedError when findContourPhoto '
'is called without implementation',
() async {
final flutterDocumentScannerPlatform =
FlutterDocumentScannerNotImplemented();

final tByteData = Uint8List.fromList([1, 2, 3]);
const tMinContourArea = 100.0;

expect(
() async => await flutterDocumentScannerPlatform.findContourPhoto(
byteData: tByteData,
minContourArea: tMinContourArea,
),
throwsA(isA<UnimplementedError>()),
);
},
);

test(
'Should throw UnimplementedError when adjustingPerspective '
'is called without implementation',
() async {
final flutterDocumentScannerPlatform =
FlutterDocumentScannerNotImplemented();

final tByteData = Uint8List.fromList([1, 2, 3]);
const tContour = Contour(
points: [
Point(10.5, 50.8),
Point(0.2, 8),
Point(10.5, 50.8),
Point(0.2, 8),
],
);

expect(
() async => await flutterDocumentScannerPlatform.adjustingPerspective(
byteData: tByteData,
contour: tContour,
),
throwsA(isA<UnimplementedError>()),
);
},
);

test(
'Should throw UnimplementedError when applyFilter '
'is called without implementation',
() async {
final flutterDocumentScannerPlatform =
FlutterDocumentScannerNotImplemented();

final tByteData = Uint8List.fromList([1, 2, 3]);
const tFilterType = FilterType.natural;

expect(
() async => await flutterDocumentScannerPlatform.applyFilter(
byteData: tByteData,
filter: tFilterType,
),
throwsA(isA<UnimplementedError>()),
);
},
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ void main() {
() async {
// arrange
const tContour = Contour(
width: 50,
height: 20,
points: [
Point(10.5, 50.8),
Point(0.2, 8),
Expand All @@ -62,6 +64,7 @@ void main() {

// assert
expect(newContour, expectedContour);
expect(newContour.hashCode, expectedContour.hashCode);
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ void main() {
);
}

void setUpFailure() {
void setUpFailure({
Exception? findContourPhoto,
Exception? adjustingPerspective,
Exception? applyFilter,
}) {
methodChannelFlutterDocumentScanner = MethodChannelFlutterDocumentScanner();

TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
Expand All @@ -98,13 +102,13 @@ void main() {

switch (message.method) {
case 'findContourPhoto':
throw Exception('Custom error');
throw findContourPhoto ?? Exception('Custom error');

case 'adjustingPerspective':
throw Exception('Custom error');
throw adjustingPerspective ?? Exception('Custom error');

case 'applyFilter':
throw Exception('Custom error');
throw applyFilter ?? Exception('Custom error');

default:
return null;
Expand Down Expand Up @@ -176,16 +180,24 @@ void main() {
'Should throw InvalidMinContourAreaError when minContourArea '
'is less than or equal to 0',
() async {
// arrange
const minContourAreaExpected = -10.0;

try {
// act
await methodChannelFlutterDocumentScanner.findContourPhoto(
byteData: tByteData,
minContourArea: -10,
minContourArea: minContourAreaExpected,
);
} catch (e) {
// assert
expect(e, isA<ContourError>());
expect((e as InvalidMinContourAreaError).minContourArea, -10);
expect(e.toString(),
'ContourError: Invalid minContourArea value: $minContourAreaExpected. It must be greater than 0.');
expect(
(e as InvalidMinContourAreaError).minContourArea,
minContourAreaExpected,
);
}
},
);
Expand Down Expand Up @@ -445,6 +457,7 @@ void main() {
} catch (e) {
// assert
expect(e, isA<Exception>());
expect((e as InvalidByteDataError).byteData, Uint8List.fromList([]));
}
},
);
Expand All @@ -464,6 +477,10 @@ void main() {
} catch (e) {
// assert
expect(e, isA<Exception>());
expect(
(e as FilterResultNullError).toString(),
'FilterError: The result of applying the filter is null.',
);
}
},
);
Expand All @@ -482,7 +499,60 @@ void main() {
);
} catch (e) {
// assert
expect(e, isA<Exception>());
expect(e, isA<PlatformException>());
}
},
);

test(
'Should throw UnsupportedFilterTypeError when an unsupported '
'filter type is provided',
() async {
// arrange
setUpFailure(
applyFilter: PlatformException(
code: 'UNSUPPORTED_FILTER_TYPE',
message: 'Unsupported filter type.',
),
);

try {
// act
await methodChannelFlutterDocumentScanner.applyFilter(
byteData: tByteData,
filter: tFilter,
);
} catch (e) {
// assert
expect(e, isA<FilterError>());
expect(
(e as UnsupportedFilterTypeError).filterType,
tFilter.toString(),
);
}
},
);

test(
'Should throw FilterError for a generic filter-related failure',
skip: true,
() async {
// arrange
setUpFailure();

try {
// act
await methodChannelFlutterDocumentScanner.applyFilter(
byteData: tByteData,
filter: tFilter,
);
} catch (e) {
// assert
expect(e, isA<FilterError>());
expect(
(e as FilterError).toString(),
'FilterError: Exception: Custom error',
);
}
},
);
Expand Down

0 comments on commit 2b6041a

Please sign in to comment.