From ab77ebec6799e96170ab4259dd0536c7f11ce06f Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Mon, 28 Feb 2022 17:10:05 +0000 Subject: [PATCH] feat: include game files (#2) * feat: included flame and flame_forge2d dependency * feat: included initial LandingPage with PinballGame * feat: included test * feat: included navigation test * fix: landing page test * feat: used l10n string for "Play" Co-authored-by: Erick Zanardo --- lib/app/view/app.dart | 4 ++- lib/game/game.dart | 2 ++ lib/game/pinball_game.dart | 3 ++ lib/game/view/pinball_game_page.dart | 16 ++++++++++ lib/l10n/arb/app_en.arb | 5 +-- lib/l10n/arb/app_es.arb | 5 +-- lib/landing/landing.dart | 1 + lib/landing/view/landing_page.dart | 21 ++++++++++++ pubspec.lock | 37 +++++++++++++++++++++- pubspec.yaml | 3 ++ test/app/view/app_test.dart | 6 ++-- test/game/view/pinball_game_page_test.dart | 14 ++++++++ test/helpers/pump_app.dart | 10 ++++-- test/landing/view/landing_page_test.dart | 33 +++++++++++++++++++ 14 files changed, 145 insertions(+), 15 deletions(-) create mode 100644 lib/game/game.dart create mode 100644 lib/game/pinball_game.dart create mode 100644 lib/game/view/pinball_game_page.dart create mode 100644 lib/landing/landing.dart create mode 100644 lib/landing/view/landing_page.dart create mode 100644 test/game/view/pinball_game_page_test.dart create mode 100644 test/landing/view/landing_page_test.dart diff --git a/lib/app/view/app.dart b/lib/app/view/app.dart index 164daf90..7e3fdf17 100644 --- a/lib/app/view/app.dart +++ b/lib/app/view/app.dart @@ -8,6 +8,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:pinball/l10n/l10n.dart'; +import 'package:pinball/landing/landing.dart'; class App extends StatelessWidget { const App({Key? key}) : super(key: key); @@ -15,6 +16,7 @@ class App extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( + title: 'I/O Pinball', theme: ThemeData( appBarTheme: const AppBarTheme(color: Color(0xFF13B9FF)), colorScheme: ColorScheme.fromSwatch( @@ -26,7 +28,7 @@ class App extends StatelessWidget { GlobalMaterialLocalizations.delegate, ], supportedLocales: AppLocalizations.supportedLocales, - home: Container(), + home: const LandingPage(), ); } } diff --git a/lib/game/game.dart b/lib/game/game.dart new file mode 100644 index 00000000..ec8e0824 --- /dev/null +++ b/lib/game/game.dart @@ -0,0 +1,2 @@ +export 'pinball_game.dart'; +export 'view/pinball_game_page.dart'; diff --git a/lib/game/pinball_game.dart b/lib/game/pinball_game.dart new file mode 100644 index 00000000..306d03f0 --- /dev/null +++ b/lib/game/pinball_game.dart @@ -0,0 +1,3 @@ +import 'package:flame_forge2d/forge2d_game.dart'; + +class PinballGame extends Forge2DGame {} diff --git a/lib/game/view/pinball_game_page.dart b/lib/game/view/pinball_game_page.dart new file mode 100644 index 00000000..cfe8d5bc --- /dev/null +++ b/lib/game/view/pinball_game_page.dart @@ -0,0 +1,16 @@ +import 'package:flame/game.dart'; +import 'package:flutter/material.dart'; +import 'package:pinball/game/game.dart'; + +class PinballGamePage extends StatelessWidget { + const PinballGamePage({Key? key}) : super(key: key); + + static Route route() { + return MaterialPageRoute(builder: (_) => const PinballGamePage()); + } + + @override + Widget build(BuildContext context) { + return GameWidget(game: PinballGame()); + } +} diff --git a/lib/l10n/arb/app_en.arb b/lib/l10n/arb/app_en.arb index a5484a06..fa732ac7 100644 --- a/lib/l10n/arb/app_en.arb +++ b/lib/l10n/arb/app_en.arb @@ -1,7 +1,4 @@ { "@@locale": "en", - "counterAppBarTitle": "Counter", - "@counterAppBarTitle": { - "description": "Text shown in the AppBar of the Counter Page" - } + "play": "Play" } \ No newline at end of file diff --git a/lib/l10n/arb/app_es.arb b/lib/l10n/arb/app_es.arb index f1405f02..405ef51f 100644 --- a/lib/l10n/arb/app_es.arb +++ b/lib/l10n/arb/app_es.arb @@ -1,7 +1,4 @@ { "@@locale": "es", - "counterAppBarTitle": "Contador", - "@counterAppBarTitle": { - "description": "Texto mostrado en la AppBar de la página del contador" - } + "play": "Jugar" } \ No newline at end of file diff --git a/lib/landing/landing.dart b/lib/landing/landing.dart new file mode 100644 index 00000000..b7da30c3 --- /dev/null +++ b/lib/landing/landing.dart @@ -0,0 +1 @@ +export 'view/landing_page.dart'; diff --git a/lib/landing/view/landing_page.dart b/lib/landing/view/landing_page.dart new file mode 100644 index 00000000..a688dee1 --- /dev/null +++ b/lib/landing/view/landing_page.dart @@ -0,0 +1,21 @@ +import 'package:flutter/material.dart'; +import 'package:pinball/game/game.dart'; +import 'package:pinball/l10n/l10n.dart'; + +class LandingPage extends StatelessWidget { + const LandingPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + final l10n = context.l10n; + return Scaffold( + body: Center( + child: TextButton( + onPressed: () => + Navigator.of(context).push(PinballGamePage.route()), + child: Text(l10n.play), + ), + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index 9b2a4b10..86f1fbe5 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -127,6 +127,20 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "6.1.2" + flame: + dependency: "direct main" + description: + name: flame + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" + flame_forge2d: + dependency: "direct main" + description: + name: flame_forge2d + url: "https://pub.dartlang.org" + source: hosted + version: "0.8.3" flutter: dependency: "direct main" description: flutter @@ -149,6 +163,13 @@ packages: description: flutter source: sdk version: "0.0.0" + forge2d: + dependency: transitive + description: + name: forge2d + url: "https://pub.dartlang.org" + source: hosted + version: "0.8.1" frontend_server_client: dependency: transitive description: @@ -233,6 +254,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.1" + mockingjay: + dependency: "direct dev" + description: + name: mockingjay + url: "https://pub.dartlang.org" + source: hosted + version: "0.2.0" mocktail: dependency: "direct dev" description: @@ -254,6 +282,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.0.1" + ordered_set: + dependency: transitive + description: + name: ordered_set + url: "https://pub.dartlang.org" + source: hosted + version: "5.0.0" package_config: dependency: transitive description: @@ -450,4 +485,4 @@ packages: version: "3.1.0" sdks: dart: ">=2.16.0 <3.0.0" - flutter: ">=1.16.0" + flutter: ">=2.5.0" diff --git a/pubspec.yaml b/pubspec.yaml index 3e03070d..f703cd22 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -8,6 +8,8 @@ environment: dependencies: bloc: ^8.0.2 + flame: ^1.0.0 + flame_forge2d: ^0.8.3 flutter: sdk: flutter flutter_bloc: ^8.0.1 @@ -19,6 +21,7 @@ dev_dependencies: bloc_test: ^9.0.2 flutter_test: sdk: flutter + mockingjay: ^0.2.0 mocktail: ^0.2.0 very_good_analysis: ^2.4.0 diff --git a/test/app/view/app_test.dart b/test/app/view/app_test.dart index ab4cb16c..d0fd36b9 100644 --- a/test/app/view/app_test.dart +++ b/test/app/view/app_test.dart @@ -5,15 +5,15 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. -import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pinball/app/app.dart'; +import 'package:pinball/landing/landing.dart'; void main() { group('App', () { - testWidgets('renders CounterPage', (tester) async { + testWidgets('renders LandingPage', (tester) async { await tester.pumpWidget(const App()); - expect(find.byType(Container), findsOneWidget); + expect(find.byType(LandingPage), findsOneWidget); }); }); } diff --git a/test/game/view/pinball_game_page_test.dart b/test/game/view/pinball_game_page_test.dart new file mode 100644 index 00000000..955ce763 --- /dev/null +++ b/test/game/view/pinball_game_page_test.dart @@ -0,0 +1,14 @@ +import 'package:flame/game.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pinball/game/game.dart'; + +import '../../helpers/helpers.dart'; + +void main() { + group('PinballGamePage', () { + testWidgets('renders single GameWidget with PinballGame', (tester) async { + await tester.pumpApp(const PinballGamePage()); + expect(find.byType(GameWidget), findsOneWidget); + }); + }); +} diff --git a/test/helpers/pump_app.dart b/test/helpers/pump_app.dart index 2f1ecb0a..97ca4590 100644 --- a/test/helpers/pump_app.dart +++ b/test/helpers/pump_app.dart @@ -8,10 +8,14 @@ import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:mockingjay/mockingjay.dart'; import 'package:pinball/l10n/l10n.dart'; extension PumpApp on WidgetTester { - Future pumpApp(Widget widget) { + Future pumpApp( + Widget widget, { + MockNavigator? navigator, + }) { return pumpWidget( MaterialApp( localizationsDelegates: const [ @@ -19,7 +23,9 @@ extension PumpApp on WidgetTester { GlobalMaterialLocalizations.delegate, ], supportedLocales: AppLocalizations.supportedLocales, - home: widget, + home: navigator != null + ? MockNavigatorProvider(navigator: navigator, child: widget) + : widget, ), ); } diff --git a/test/landing/view/landing_page_test.dart b/test/landing/view/landing_page_test.dart new file mode 100644 index 00000000..d754864c --- /dev/null +++ b/test/landing/view/landing_page_test.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockingjay/mockingjay.dart'; +import 'package:pinball/landing/landing.dart'; + +import '../../helpers/helpers.dart'; + +void main() { + group('LandingPage', () { + testWidgets('renders TextButton', (tester) async { + await tester.pumpApp(const LandingPage()); + expect(find.byType(TextButton), findsOneWidget); + }); + + testWidgets('tapping on TextButton navigates to PinballGamePage', + (tester) async { + final navigator = MockNavigator(); + when(() => navigator.push(any())).thenAnswer((_) async {}); + + await tester.pumpApp( + const LandingPage(), + navigator: navigator, + ); + await tester.tap( + find.byType( + TextButton, + ), + ); + + verify(() => navigator.push(any())).called(1); + }); + }); +}