-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from davidsdearaujo/main
[BuilderPlus] Include "buildWhen"
- Loading branch information
Showing
3 changed files
with
86 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,66 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:value_notifier_plus/value_notifier_plus.dart'; | ||
|
||
import '../../conter_notifier.dart'; | ||
|
||
void main() { | ||
testWidgets('BuilderPlus rebuilds when state changes', (tester) async { | ||
final counterNotifier = CounterNotifier(); | ||
|
||
await tester.pumpWidget( | ||
BuilderPlus<CounterNotifier, int>( | ||
notifier: counterNotifier, | ||
builder: (context, state) { | ||
return Text('$state', textDirection: TextDirection.ltr); | ||
}, | ||
), | ||
); | ||
|
||
expect(find.text('0'), findsOneWidget); | ||
counterNotifier.increment(); | ||
await tester.pump(); | ||
expect(find.text('1'), findsOneWidget); | ||
group('BuilderPlus', () { | ||
testWidgets('rebuilds when state changes', (tester) async { | ||
final counterNotifier = CounterNotifier(); | ||
|
||
await tester.pumpWidget( | ||
BuilderPlus<CounterNotifier, int>( | ||
notifier: counterNotifier, | ||
builder: (context, state) { | ||
return Text('$state', textDirection: TextDirection.ltr); | ||
}, | ||
), | ||
); | ||
|
||
expect(find.text('0'), findsOneWidget); | ||
counterNotifier.increment(); | ||
await tester.pump(); | ||
expect(find.text('1'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('do NOT rebuilds when "buildWhen" is not true', (tester) async { | ||
final counterNotifier = CounterNotifier(); | ||
|
||
await tester.pumpWidget( | ||
BuilderPlus<CounterNotifier, int>( | ||
notifier: counterNotifier, | ||
buildWhen: (previous, current) => current > previous + 2, | ||
builder: (context, state) { | ||
return Text('$state', textDirection: TextDirection.ltr); | ||
}, | ||
), | ||
); | ||
|
||
expect(find.text('0'), findsOneWidget); | ||
counterNotifier.increment(); | ||
await tester.pump(); | ||
expect(find.text('0'), findsOneWidget); | ||
}); | ||
|
||
testWidgets('rebuilds when "buildWhen" is true', (tester) async { | ||
final counterNotifier = CounterNotifier(); | ||
|
||
await tester.pumpWidget( | ||
BuilderPlus<CounterNotifier, int>( | ||
notifier: counterNotifier, | ||
builder: (context, state) { | ||
return Text('$state', textDirection: TextDirection.ltr); | ||
}, | ||
), | ||
); | ||
|
||
expect(find.text('0'), findsOneWidget); | ||
counterNotifier.increment(); | ||
counterNotifier.increment(); | ||
counterNotifier.increment(); | ||
await tester.pump(); | ||
expect(find.text('3'), findsOneWidget); | ||
}); | ||
}); | ||
} |