From 453bd6823a3e8a11f5df4ff47576ae672652b2a2 Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Wed, 24 Apr 2024 11:00:54 +0100 Subject: [PATCH 1/4] feat: replace widget --- lib/crossword/view/crossword_page.dart | 63 ++------------------ test/crossword/view/crossword_page_test.dart | 41 ++++--------- 2 files changed, 15 insertions(+), 89 deletions(-) diff --git a/lib/crossword/view/crossword_page.dart b/lib/crossword/view/crossword_page.dart index 1bc88dfe5..8358c74cf 100644 --- a/lib/crossword/view/crossword_page.dart +++ b/lib/crossword/view/crossword_page.dart @@ -1,9 +1,9 @@ import 'package:api_client/api_client.dart'; -import 'package:flame/game.dart' hide Route; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:io_crossword/bottom_bar/view/bottom_bar.dart'; import 'package:io_crossword/crossword/crossword.dart'; +import 'package:io_crossword/crossword2/crossword2.dart'; import 'package:io_crossword/drawer/drawer.dart'; import 'package:io_crossword/l10n/l10n.dart'; import 'package:io_crossword/music/music.dart'; @@ -81,76 +81,21 @@ class CrosswordView extends StatelessWidget { } } -class LoadedBoardView extends StatefulWidget { +@visibleForTesting +class LoadedBoardView extends StatelessWidget { @visibleForTesting const LoadedBoardView({super.key}); - @visibleForTesting - static const zoomInKey = Key('game_zoomIn'); - - @visibleForTesting - static const zoomOutKey = Key('game_zoomOut'); - - @override - State createState() => LoadedBoardViewState(); -} - -@visibleForTesting -class LoadedBoardViewState extends State { - late final CrosswordGame game; - - @override - void initState() { - super.initState(); - game = CrosswordGame( - crosswordBloc: context.read(), - wordSelectionBloc: context.read(), - playerBloc: context.read(), - ); - } - @override Widget build(BuildContext context) { final layout = IoLayout.of(context); return Stack( children: [ - GameWidget(game: game), + const Crossword2View(), const WordSelectionPage(), if (layout == IoLayoutData.large) const BottomBar(), - _ZoomControls(game: game), ], ); } } - -class _ZoomControls extends StatelessWidget { - const _ZoomControls({ - required this.game, - }); - - final CrosswordGame game; - - @override - Widget build(BuildContext context) { - return Positioned( - left: 16, - bottom: 16, - child: Column( - children: [ - ElevatedButton( - key: LoadedBoardView.zoomInKey, - onPressed: game.zoomIn, - child: const Icon(Icons.zoom_in), - ), - const SizedBox(height: 16), - ElevatedButton( - key: LoadedBoardView.zoomOutKey, - onPressed: game.zoomOut, - child: const Icon(Icons.zoom_out), - ), - ], - ), - ); - } -} diff --git a/test/crossword/view/crossword_page_test.dart b/test/crossword/view/crossword_page_test.dart index 68e24ce02..1600a7407 100644 --- a/test/crossword/view/crossword_page_test.dart +++ b/test/crossword/view/crossword_page_test.dart @@ -3,12 +3,11 @@ import 'package:bloc_test/bloc_test.dart'; import 'package:flame/cache.dart'; import 'package:flame/flame.dart'; -import 'package:flame/game.dart'; import 'package:flutter/material.dart' hide Axis; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:game_domain/game_domain.dart'; import 'package:io_crossword/crossword/crossword.dart'; +import 'package:io_crossword/crossword2/crossword2.dart'; import 'package:io_crossword/drawer/drawer.dart'; import 'package:io_crossword/music/widget/mute_button.dart'; import 'package:io_crossword/player/player.dart'; @@ -28,11 +27,6 @@ class _MockWordSelectionBloc extends MockBloc implements WordSelectionBloc {} -class _FakeBoardSection extends Fake implements BoardSection { - @override - List get words => []; -} - void main() { group('$CrosswordPage', () { testWidgets('renders $CrosswordView', (tester) async { @@ -49,6 +43,12 @@ void main() { setUp(() { Flame.images = Images(prefix: ''); crosswordBloc = _MockCrosswordBloc(); + when(() => crosswordBloc.state).thenReturn( + CrosswordState( + status: CrosswordStatus.success, + sectionSize: 40, + ), + ); }); testWidgets('renders $IoAppBar', (tester) async { @@ -108,38 +108,19 @@ void main() { expect(find.byType(ErrorView), findsOneWidget); }); - testWidgets('renders game with ${CrosswordStatus.success}', (tester) async { - when(() => crosswordBloc.state).thenReturn( - CrosswordState( - status: CrosswordStatus.success, - sectionSize: 40, - sections: { - (0, 0): _FakeBoardSection(), - }, - ), - ); - + testWidgets('renders $Crossword2View with ${CrosswordStatus.success}', + (tester) async { await tester.pumpSubject( - CrosswordView(), crosswordBloc: crosswordBloc, + CrosswordView(), ); - expect(find.byType(GameWidget), findsOneWidget); + expect(find.byType(Crossword2View), findsOneWidget); }); testWidgets( 'renders $WordSelectionPage when loaded', (tester) async { - when(() => crosswordBloc.state).thenReturn( - CrosswordState( - status: CrosswordStatus.success, - sectionSize: 40, - sections: { - (0, 0): _FakeBoardSection(), - }, - ), - ); - await tester.pumpSubject( CrosswordView(), crosswordBloc: crosswordBloc, From 708b64f2b1971cb8dc6065bd334338aa3f33fd46 Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Wed, 24 Apr 2024 11:01:12 +0100 Subject: [PATCH 2/4] refactor: rename collection --- .../crossword_repository/lib/src/crossword_repository.dart | 2 +- .../test/src/crossword_repository_test.dart | 2 +- packages/board_generator/lib/src/crossword_repository.dart | 2 +- packages/crossword_repository/lib/src/crossword_repository.dart | 2 +- .../test/src/crossword_repository_test.dart | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/packages/crossword_repository/lib/src/crossword_repository.dart b/api/packages/crossword_repository/lib/src/crossword_repository.dart index 3326992b9..e312ca460 100644 --- a/api/packages/crossword_repository/lib/src/crossword_repository.dart +++ b/api/packages/crossword_repository/lib/src/crossword_repository.dart @@ -15,7 +15,7 @@ class CrosswordRepository { final DbClient _dbClient; - static const _sectionsCollection = 'boardChunks'; + static const _sectionsCollection = 'boardChunks2'; static const _answersCollection = 'answers'; static const _boardInfoCollection = 'boardInfo'; diff --git a/api/packages/crossword_repository/test/src/crossword_repository_test.dart b/api/packages/crossword_repository/test/src/crossword_repository_test.dart index 4f56cb447..e068e56cc 100644 --- a/api/packages/crossword_repository/test/src/crossword_repository_test.dart +++ b/api/packages/crossword_repository/test/src/crossword_repository_test.dart @@ -16,7 +16,7 @@ void main() { group('CrosswordRepository', () { late DbClient dbClient; - const sectionsCollection = 'boardChunks'; + const sectionsCollection = 'boardChunks2'; const answersCollection = 'answers'; setUpAll(() { diff --git a/packages/board_generator/lib/src/crossword_repository.dart b/packages/board_generator/lib/src/crossword_repository.dart index 0e516ae61..66e8f40e5 100644 --- a/packages/board_generator/lib/src/crossword_repository.dart +++ b/packages/board_generator/lib/src/crossword_repository.dart @@ -38,7 +38,7 @@ class CrosswordRepository { /// Adds a list of sections to the database. Future _addSections(List sections) async { for (final section in sections) { - await firestore.collection('boardChunks').add(section.toJson()); + await firestore.collection('boardChunks2').add(section.toJson()); } } diff --git a/packages/crossword_repository/lib/src/crossword_repository.dart b/packages/crossword_repository/lib/src/crossword_repository.dart index 3f96cf3b3..323f3d40b 100644 --- a/packages/crossword_repository/lib/src/crossword_repository.dart +++ b/packages/crossword_repository/lib/src/crossword_repository.dart @@ -9,7 +9,7 @@ class CrosswordRepository { CrosswordRepository({ required this.db, }) { - sectionCollection = db.collection('boardChunks'); + sectionCollection = db.collection('boardChunks2'); } /// The [FirebaseFirestore] instance. diff --git a/packages/crossword_repository/test/src/crossword_repository_test.dart b/packages/crossword_repository/test/src/crossword_repository_test.dart index 1f9d2c3af..f7aefed20 100644 --- a/packages/crossword_repository/test/src/crossword_repository_test.dart +++ b/packages/crossword_repository/test/src/crossword_repository_test.dart @@ -25,7 +25,7 @@ void main() { ], borderWords: const [], ); - const sectionsCollection = 'boardChunks'; + const sectionsCollection = 'boardChunks2'; late FirebaseFirestore firebaseFirestore; late CrosswordRepository crosswordRepository; From 9cb311949caf8db6ad5b64b0fdfd10b14ffa3168 Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Wed, 24 Apr 2024 11:22:18 +0100 Subject: [PATCH 3/4] chore: remove dead line --- lib/crossword/game/crossword_game.dart | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/crossword/game/crossword_game.dart b/lib/crossword/game/crossword_game.dart index c360abee9..bda16846e 100644 --- a/lib/crossword/game/crossword_game.dart +++ b/lib/crossword/game/crossword_game.dart @@ -206,11 +206,6 @@ class CrosswordGame extends FlameGame _updateVisibleSections(); } - @override - Color backgroundColor() { - return const Color(0xFF212123); - } - bool get isMobile { return defaultTargetPlatform == TargetPlatform.android || defaultTargetPlatform == TargetPlatform.iOS; From a65c364f39baa28379e9e9ea6c6d9befd492483d Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Wed, 24 Apr 2024 11:36:49 +0100 Subject: [PATCH 4/4] feat: rename answers to answers2 --- .../crossword_repository/lib/src/crossword_repository.dart | 2 +- .../test/src/crossword_repository_test.dart | 2 +- api/packages/hint_repository/lib/src/hint_repository.dart | 2 +- packages/board_generator/lib/src/crossword_repository.dart | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/api/packages/crossword_repository/lib/src/crossword_repository.dart b/api/packages/crossword_repository/lib/src/crossword_repository.dart index e312ca460..f9c1f226d 100644 --- a/api/packages/crossword_repository/lib/src/crossword_repository.dart +++ b/api/packages/crossword_repository/lib/src/crossword_repository.dart @@ -16,7 +16,7 @@ class CrosswordRepository { final DbClient _dbClient; static const _sectionsCollection = 'boardChunks2'; - static const _answersCollection = 'answers'; + static const _answersCollection = 'answers2'; static const _boardInfoCollection = 'boardInfo'; /// Fetches all sections from the board. diff --git a/api/packages/crossword_repository/test/src/crossword_repository_test.dart b/api/packages/crossword_repository/test/src/crossword_repository_test.dart index e068e56cc..6871d152f 100644 --- a/api/packages/crossword_repository/test/src/crossword_repository_test.dart +++ b/api/packages/crossword_repository/test/src/crossword_repository_test.dart @@ -17,7 +17,7 @@ void main() { late DbClient dbClient; const sectionsCollection = 'boardChunks2'; - const answersCollection = 'answers'; + const answersCollection = 'answers2'; setUpAll(() { registerFallbackValue(_MockDbEntityRecord()); diff --git a/api/packages/hint_repository/lib/src/hint_repository.dart b/api/packages/hint_repository/lib/src/hint_repository.dart index c4a0be050..f2a484ed2 100644 --- a/api/packages/hint_repository/lib/src/hint_repository.dart +++ b/api/packages/hint_repository/lib/src/hint_repository.dart @@ -16,7 +16,7 @@ class HintRepository { final DbClient _dbClient; final GenerativeModelWrapper _generativeModel; - static const _answersCollection = 'answers'; + static const _answersCollection = 'answers2'; static const _hintsCollection = 'hints'; static const _boardInfoCollection = 'boardInfo'; diff --git a/packages/board_generator/lib/src/crossword_repository.dart b/packages/board_generator/lib/src/crossword_repository.dart index 66e8f40e5..3b0677e54 100644 --- a/packages/board_generator/lib/src/crossword_repository.dart +++ b/packages/board_generator/lib/src/crossword_repository.dart @@ -21,7 +21,7 @@ class CrosswordRepository { } Future _addAnswers(List answers) async { - final answersCollection = firestore.collection('answers'); + final answersCollection = firestore.collection('answers2'); for (final answer in answers) { await answersCollection.doc(answer.id).set(answer.toJson()); }