This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate to checks for expections
- Loading branch information
Showing
17 changed files
with
129 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
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,54 @@ | ||
import 'package:checks/context.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
extension AccessibilityExpect on Subject<WidgetTester> { | ||
Future<void> meetsGuideline(AccessibilityGuideline guideline) async { | ||
await context.expectAsync(() => [guideline.description], (tester) async { | ||
final result = await guideline.evaluate(tester); | ||
if (result.passed) { | ||
return null; | ||
} | ||
return Rejection(which: [result.reason!]); | ||
}); | ||
} | ||
} | ||
|
||
extension WidgetFinderExpect on Subject<Finder> { | ||
void findsOne() { | ||
findsExactly(1); | ||
} | ||
|
||
void findsExactly(int count) { | ||
_findsWidgets(0, count); | ||
} | ||
|
||
void _findsWidgets(int? min, int? max) { | ||
assert(min != null || max != null, 'min or max must be provided'); | ||
assert( | ||
min == null || max == null || min <= max, | ||
'min must be less than or equal to max', | ||
); | ||
|
||
context.expect(() => ['finds between $min and $max widgets'], (finder) { | ||
var count = 0; | ||
final Iterator<dynamic> iterator = finder.evaluate().iterator; | ||
if (min != null) { | ||
while (count < min && iterator.moveNext()) { | ||
count += 1; | ||
} | ||
if (count < min) { | ||
return Rejection(which: ['found less than $min widgets']); | ||
} | ||
} | ||
if (max != null) { | ||
while (count <= max && iterator.moveNext()) { | ||
count += 1; | ||
} | ||
if (count > max) { | ||
return Rejection(which: ['found more than $max widgets']); | ||
} | ||
} | ||
return null; | ||
}); | ||
} | ||
} |
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
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
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
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
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
5 changes: 3 additions & 2 deletions
5
packages/app/test/src/features/sample/domain/sample_item_entity_test.dart
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import 'package:checks/checks.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:our_democracy/src/features/sample/domain/sample_item_entity.dart'; | ||
|
||
void main() { | ||
test('SampleItemEntity should correctly wrap an int', () { | ||
const entity = SampleItemEntity(1); | ||
expect(entity, isA<int>()); | ||
expect(entity, equals(1)); | ||
check(entity).isA<int>(); | ||
check(entity.id).equals(1); | ||
}); | ||
} |
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
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
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
Oops, something went wrong.