-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add tests and workflow for exampl
- Loading branch information
1 parent
5f6e806
commit 4e4404e
Showing
4 changed files
with
191 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
name: example | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
semantic-pull-request: | ||
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/semantic_pull_request.yml@v1 | ||
|
||
build: | ||
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/flutter_package.yml@v1 | ||
with: | ||
flutter_channel: stable | ||
|
||
spell-check: | ||
uses: VeryGoodOpenSource/very_good_workflows/.github/workflows/spell_check.yml@v1 | ||
with: | ||
includes: | | ||
**/*.md | ||
modified_files_only: false |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ dependencies: | |
sdk: flutter | ||
formz: | ||
path: ../ | ||
mocktail: ^1.0.0 | ||
|
||
dev_dependencies: | ||
flutter_test: | ||
|
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,152 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:example/main.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mocktail/mocktail.dart'; | ||
|
||
class MockRandom extends Mock implements Random {} | ||
|
||
|
||
final _seed = MockRandom(); | ||
|
||
void main() { | ||
|
||
group('$MyApp', () { | ||
testWidgets('render example', (tester) async { | ||
await tester.pumpWidget(const MyApp()); | ||
expect(find.text('Formz Example'), findsOneWidget); | ||
}); | ||
}); | ||
|
||
group('$MyForm', () { | ||
|
||
setUp(() { | ||
when(()=> _seed.nextInt(any())).thenReturn(1); | ||
}); | ||
|
||
testWidgets('submits valid values', (tester) async { | ||
await tester.pumpMyForm(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_emailInput')), | ||
'[email protected]', | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_passwordInput')), | ||
'123password', | ||
); | ||
await tester.pumpAndSettle(); | ||
await tester.tap(find.byKey(const Key('myForm_submit'))); | ||
await tester.pumpAndSettle(); | ||
await tester.pumpAndSettle(); | ||
expect(find.text('Submitted successfully! 🎉'), findsOneWidget); | ||
}); | ||
|
||
group('invalid values', () { | ||
testWidgets('invalid email', (tester) async { | ||
await tester.pumpMyForm(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_emailInput')), | ||
'emailexample.com', | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_passwordInput')), | ||
'123password', | ||
); | ||
await tester.pumpAndSettle(); | ||
await tester.tap(find.byKey(const Key('myForm_submit'))); | ||
await tester.pumpAndSettle(); | ||
await tester.pumpAndSettle(); | ||
|
||
expect( | ||
find.text('Please ensure the email entered is valid'), | ||
findsOneWidget, | ||
); | ||
}); | ||
|
||
testWidgets('empty email', (tester) async { | ||
await tester.pumpMyForm(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_emailInput')), | ||
'', | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_passwordInput')), | ||
'123password', | ||
); | ||
await tester.pumpAndSettle(); | ||
await tester.tap(find.byKey(const Key('myForm_submit'))); | ||
await tester.pumpAndSettle(); | ||
await tester.pumpAndSettle(); | ||
|
||
expect( | ||
find.text('Please ensure the email entered is valid'), | ||
findsOneWidget, | ||
); | ||
}); | ||
|
||
testWidgets('invalid password', (tester) async { | ||
await tester.pumpMyForm(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_emailInput')), | ||
'[email protected]', | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_passwordInput')), | ||
'12345678', | ||
); | ||
await tester.pumpAndSettle(); | ||
await tester.tap(find.byKey(const Key('myForm_submit'))); | ||
await tester.pumpAndSettle(); | ||
await tester.pumpAndSettle(); | ||
|
||
expect( | ||
find.text('''Password must be at least 8 characters and contain at least one letter and number'''), | ||
findsOneWidget, | ||
); | ||
}); | ||
|
||
testWidgets('empty password', (tester) async { | ||
await tester.pumpMyForm(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_emailInput')), | ||
'[email protected]', | ||
); | ||
await tester.pumpAndSettle(); | ||
|
||
await tester.enterText( | ||
find.byKey(const Key('myForm_passwordInput')), | ||
'', | ||
); | ||
await tester.pumpAndSettle(); | ||
await tester.tap(find.byKey(const Key('myForm_submit'))); | ||
await tester.pumpAndSettle(); | ||
await tester.pumpAndSettle(); | ||
|
||
expect( | ||
find.text('''Password must be at least 8 characters and contain at least one letter and number'''), | ||
findsOneWidget, | ||
); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
extension on WidgetTester { | ||
Future<void> pumpMyForm() async { | ||
await pumpWidget(MaterialApp(home: Scaffold(body: MyForm(seed: _seed)))); | ||
} | ||
} |