Skip to content

Commit

Permalink
add tests for ProviderHelper pGet
Browse files Browse the repository at this point in the history
  • Loading branch information
SBNTT committed Mar 24, 2020
1 parent afa686c commit 879dfc8
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
48 changes: 48 additions & 0 deletions test/provider_helper_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:provider/provider.dart';
import 'package:swc_flutter/src/provider_helper.dart';

void main() {
group("Test ProviderHelper", () {
testWidgets("pGet should return content", (tester) async {
final content = "Hi!";
await tester.pumpWidget(MaterialApp(
home: _PGetTestWidget(content: content),
));
expect(find.text(content), findsOneWidget);
});

testWidgets("pGet should return null", (tester) async {
await tester.pumpWidget(MaterialApp(
home: _PGetTestWidget(),
));
expect(find.text("null"), findsOneWidget);
});
});
}

class _PGetTestWidget extends StatelessWidget with ProviderHelper {

final String content;

_PGetTestWidget({this.content});

Widget build(BuildContext context) {
return Provider<String>(
create: (_) => content,
child: Builder(builder: (context) {
return Text(pGet<String>(context).toString());
}),
);
}

}

class _InvalidPGetTestWidget extends StatelessWidget with ProviderHelper {

Widget build(BuildContext context) {
return Text(pGet<String>(context).toString());
}

}
9 changes: 5 additions & 4 deletions test/swc_stateless_widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ void main() {
await tester.pumpWidget(MaterialApp(
home: _SimpleTestWidget(content: content),
));

expect(find.text(content), findsOneWidget);
});

Expand All @@ -19,14 +20,14 @@ void main() {
home: _CounterTestWidget(),
));

expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);
expect(find.text("0"), findsOneWidget);
expect(find.text("1"), findsNothing);

await tester.tap(find.byIcon(Icons.add));
await tester.pump();

expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
expect(find.text("0"), findsNothing);
expect(find.text("1"), findsOneWidget);
});
});
}
Expand Down

0 comments on commit 879dfc8

Please sign in to comment.