-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
159 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'package:example/util/util.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
final resultProvider = | ||
StateNotifierProvider<ResultNotifier, dynamic>((ref) => ResultNotifier()); | ||
|
||
class ResultNotifier extends StateNotifier<dynamic> { | ||
ResultNotifier() : super(null); | ||
// ignore: use_setters_to_change_properties | ||
void set(dynamic text) { | ||
state = text; | ||
} | ||
|
||
void clear() => set(''); | ||
|
||
@override | ||
set state(dynamic value) { | ||
super.state = value; | ||
logger.info(state); | ||
} | ||
} |
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,99 @@ | ||
import 'package:adaptive_dialog/adaptive_dialog.dart'; | ||
import 'package:example/result_provider.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../util.dart'; | ||
|
||
extension on WidgetTester { | ||
Future<ProviderContainer> setUpAlert() => setup('Alert'); | ||
Future<void> openOkDialog() => open('OK Dialog'); | ||
Future<void> openOkOnWillPopFalseDialog() => | ||
open('OK Dialog (onWillPop: false)'); | ||
Future<void> openOkBarrierDismissibleFalseDialog() => | ||
open('OK Dialog (barrierDismissible: false)'); | ||
} | ||
|
||
void main() { | ||
group('OK Dialog', () { | ||
testWidgets('OK', (tester) async { | ||
final container = await tester.setUpAlert(); | ||
await tester.openOkDialog(); | ||
|
||
expect(find.text('Title'), findsOneWidget); | ||
expect(find.text('This is message.'), findsOneWidget); | ||
await tester.tap(find.widgetWithText(TextButton, 'OK')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(container.read(resultProvider), OkCancelResult.ok); | ||
}); | ||
testWidgets('barrier', (tester) async { | ||
final container = await tester.setUpAlert(); | ||
await tester.openOkDialog(); | ||
|
||
await tester.tapBarrier(); | ||
|
||
expect(container.read(resultProvider), OkCancelResult.cancel); | ||
}); | ||
|
||
testWidgets('maybePop', (tester) async { | ||
final container = await tester.setUpAlert(); | ||
await tester.openOkDialog(); | ||
|
||
final context = tester.element(find.text('Title')); | ||
await Navigator.of(context).maybePop(); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(container.read(resultProvider), OkCancelResult.cancel); | ||
}); | ||
}); | ||
|
||
group('OK Dialog (onWillPop: false)', () { | ||
testWidgets('OK', (tester) async { | ||
final container = await tester.setUpAlert(); | ||
await tester.openOkOnWillPopFalseDialog(); | ||
|
||
expect(find.text('Title'), findsOneWidget); | ||
expect(find.text('This is message.'), findsOneWidget); | ||
await tester.tap(find.widgetWithText(TextButton, 'OK')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(container.read(resultProvider), OkCancelResult.ok); | ||
}); | ||
testWidgets('maybePop', (tester) async { | ||
final container = await tester.setUpAlert(); | ||
await tester.openOkOnWillPopFalseDialog(); | ||
|
||
final context = tester.element(find.text('Title')); | ||
await Navigator.of(context).maybePop(); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(container.read(resultProvider), isNull); | ||
expect(find.text('Title'), findsOneWidget); | ||
}); | ||
}); | ||
|
||
group('OK Dialog (barrierDismissible: false)', () { | ||
testWidgets('OK', (tester) async { | ||
final container = await tester.setUpAlert(); | ||
await tester.openOkBarrierDismissibleFalseDialog(); | ||
|
||
expect(find.text('Title'), findsOneWidget); | ||
expect(find.text('This is message.'), findsOneWidget); | ||
await tester.tap(find.widgetWithText(TextButton, 'OK')); | ||
await tester.pumpAndSettle(); | ||
|
||
expect(container.read(resultProvider), OkCancelResult.ok); | ||
}); | ||
testWidgets('barrier', (tester) async { | ||
final container = await tester.setUpAlert(); | ||
await tester.openOkBarrierDismissibleFalseDialog(); | ||
|
||
await tester.tapBarrier(); | ||
|
||
expect(container.read(resultProvider), isNull); | ||
expect(find.text('Title'), findsOneWidget); | ||
}); | ||
}); | ||
} |
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,31 @@ | ||
import 'package:example/app.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
extension WidgetTesterX on WidgetTester { | ||
Future<ProviderContainer> setup(String pageName) async { | ||
final container = ProviderContainer(); | ||
addTearDown(container.dispose); | ||
await pumpWidget( | ||
ProviderScope( | ||
parent: container, | ||
child: const App(), | ||
), | ||
); | ||
|
||
await tap(find.widgetWithText(ListTile, pageName)); | ||
await pumpAndSettle(); | ||
return container; | ||
} | ||
|
||
Future<void> open(String label) async { | ||
await tap(find.widgetWithText(ListTile, label)); | ||
await pumpAndSettle(); | ||
} | ||
|
||
Future<void> tapBarrier() async { | ||
await tapAt(Offset.zero); | ||
await pumpAndSettle(); | ||
} | ||
} |