diff --git a/lib/bottom_bar/view/bottom_bar.dart b/lib/bottom_bar/view/bottom_bar.dart index f7820de96..c641ef31d 100644 --- a/lib/bottom_bar/view/bottom_bar.dart +++ b/lib/bottom_bar/view/bottom_bar.dart @@ -28,8 +28,6 @@ class BottomBarContent extends StatelessWidget { @override Widget build(BuildContext context) { final l10n = context.l10n; - - final layout = IoLayout.of(context); final theme = Theme.of(context); return Align( @@ -45,10 +43,7 @@ class BottomBarContent extends StatelessWidget { onPressed: () {}, // coverage:ignore-line child: Text( l10n.submitScore, - style: switch (layout) { - IoLayoutData.small => theme.textTheme.bodySmall, - IoLayoutData.large => theme.textTheme.bodyMedium, - }, + style: theme.textTheme.bodySmall, ), ), const SizedBox(width: 16), diff --git a/lib/crossword/game/section_component/section_component.dart b/lib/crossword/game/section_component/section_component.dart index 3c7b34b30..978264601 100644 --- a/lib/crossword/game/section_component/section_component.dart +++ b/lib/crossword/game/section_component/section_component.dart @@ -13,7 +13,7 @@ import 'package:io_crossword/crossword/extensions/characters_rectangle.dart'; import 'package:io_crossword/crossword/extensions/extensions.dart'; import 'package:io_crossword/crossword/game/section_component/models/models.dart'; import 'package:io_crossword/word_selection/word_selection.dart' - show WordFocusedDesktopView; + show WordSelectionLargeView; part 'section_debug.dart'; part 'section_keyboard_handler.dart'; diff --git a/lib/crossword/game/section_component/section_tap_controller.dart b/lib/crossword/game/section_component/section_tap_controller.dart index 39b6ca3a1..0a9ee79d0 100644 --- a/lib/crossword/game/section_component/section_tap_controller.dart +++ b/lib/crossword/game/section_component/section_tap_controller.dart @@ -40,7 +40,7 @@ class SectionTapController extends PositionComponent wordRect.left + wordRect.width / 2, wordRect.top + wordRect.height / 2, ).translated( - viewportWidth * WordFocusedDesktopView.widthRatio / 2, + viewportWidth * WordSelectionLargeView.widthRatio / 2, 0, ); diff --git a/lib/word_selection/view/view.dart b/lib/word_selection/view/view.dart index 9b9ad839a..8d1d7db75 100644 --- a/lib/word_selection/view/view.dart +++ b/lib/word_selection/view/view.dart @@ -1,4 +1,4 @@ -export 'word_focused_view.dart'; export 'word_pre_solving_view.dart'; +export 'word_selection_view.dart'; export 'word_solving_view.dart'; export 'word_success_view.dart'; diff --git a/lib/word_selection/view/word_focused_view.dart b/lib/word_selection/view/word_selection_view.dart similarity index 75% rename from lib/word_selection/view/word_focused_view.dart rename to lib/word_selection/view/word_selection_view.dart index 2c453f2d3..1cb8559cc 100644 --- a/lib/word_selection/view/word_focused_view.dart +++ b/lib/word_selection/view/word_selection_view.dart @@ -9,34 +9,23 @@ class WordSelectionView extends StatelessWidget { @override Widget build(BuildContext context) { - final layout = IoLayout.of(context); - - return layout == IoLayoutData.large - ? const WordFocusedDesktopPage() - : const WordFocusedMobilePage(); - } -} - -@visibleForTesting -class WordFocusedDesktopPage extends StatelessWidget { - @visibleForTesting - const WordFocusedDesktopPage({super.key}); - - @override - Widget build(BuildContext context) { - final selectedWord = context.select( - (CrosswordBloc bloc) => bloc.state.selectedWord, - ); + final selectedWord = + context.select((CrosswordBloc bloc) => bloc.state.selectedWord); if (selectedWord == null) { return const SizedBox.shrink(); } - return WordFocusedDesktopView(selectedWord); + final layout = IoLayout.of(context); + + return layout == IoLayoutData.large + ? WordSelectionLargeView(selectedWord) + : WordSelectionSmallView(selectedWord); } } -class WordFocusedDesktopView extends StatelessWidget { - const WordFocusedDesktopView(this.selectedWord, {super.key}); +class WordSelectionLargeView extends StatelessWidget { + @visibleForTesting + const WordSelectionLargeView(this.selectedWord, {super.key}); final WordSelection selectedWord; @@ -77,25 +66,9 @@ class WordFocusedDesktopView extends StatelessWidget { } @visibleForTesting -class WordFocusedMobilePage extends StatelessWidget { +class WordSelectionSmallView extends StatelessWidget { @visibleForTesting - const WordFocusedMobilePage({super.key}); - - @override - Widget build(BuildContext context) { - final selectedWord = context.select( - (CrosswordBloc bloc) => bloc.state.selectedWord, - ); - if (selectedWord == null) { - return const SizedBox.shrink(); - } - - return WordFocusedMobileView(selectedWord); - } -} - -class WordFocusedMobileView extends StatelessWidget { - const WordFocusedMobileView(this.selectedWord, {super.key}); + const WordSelectionSmallView(this.selectedWord, {super.key}); final WordSelection selectedWord; diff --git a/test/crossword/game/crossword_game_test.dart b/test/crossword/game/crossword_game_test.dart index 72b6ac0f7..11989156c 100644 --- a/test/crossword/game/crossword_game_test.dart +++ b/test/crossword/game/crossword_game_test.dart @@ -233,7 +233,7 @@ void main() { targetWord.height / 2, ).translated( game.camera.visibleWorldRect.size.width * - WordFocusedDesktopView.widthRatio / + WordSelectionLargeView.widthRatio / 2, 0, ); diff --git a/test/crossword/view/crossword_page_test.dart b/test/crossword/view/crossword_page_test.dart index 80c20999b..e9bb978fd 100644 --- a/test/crossword/view/crossword_page_test.dart +++ b/test/crossword/view/crossword_page_test.dart @@ -116,83 +116,8 @@ void main() { }); testWidgets( - 'renders $WordFocusedDesktopPage when is loaded with desktop size', + 'renders $WordSelectionView when loaded', (tester) async { - tester.setDisplaySize(Size(IoCrosswordBreakpoints.medium, 800)); - - when(() => crosswordBloc.state).thenReturn( - CrosswordState( - status: CrosswordStatus.success, - sectionSize: 40, - sections: { - (0, 0): _FakeBoardSection(), - }, - ), - ); - - await tester.pumpSubject( - CrosswordView(), - crosswordBloc: crosswordBloc, - ); - - expect(find.byType(WordFocusedDesktopPage), findsOneWidget); - }, - ); - - testWidgets( - 'does not render $WordFocusedDesktopPage when is loaded with mobile size', - (tester) async { - tester.setDisplaySize(Size(IoCrosswordBreakpoints.medium - 1, 800)); - - when(() => crosswordBloc.state).thenReturn( - CrosswordState( - status: CrosswordStatus.success, - sectionSize: 40, - sections: { - (0, 0): _FakeBoardSection(), - }, - ), - ); - - await tester.pumpSubject( - CrosswordView(), - crosswordBloc: crosswordBloc, - ); - - expect(find.byType(WordFocusedDesktopPage), findsNothing); - }, - ); - - testWidgets( - 'renders $WordFocusedMobilePage when game is loaded with mobile size', - (tester) async { - tester.setDisplaySize(Size(IoCrosswordBreakpoints.medium - 1, 800)); - - when(() => crosswordBloc.state).thenReturn( - CrosswordState( - status: CrosswordStatus.success, - sectionSize: 40, - sections: { - (0, 0): _FakeBoardSection(), - }, - ), - ); - - await tester.pumpSubject( - CrosswordView(), - crosswordBloc: crosswordBloc, - ); - - expect(find.byType(WordFocusedMobilePage), findsOneWidget); - }, - ); - - testWidgets( - 'does not render $WordFocusedMobilePage when game is loaded with ' - 'desktop size', - (tester) async { - tester.setDisplaySize(Size(IoCrosswordBreakpoints.medium, 800)); - when(() => crosswordBloc.state).thenReturn( CrosswordState( status: CrosswordStatus.success, @@ -208,7 +133,7 @@ void main() { crosswordBloc: crosswordBloc, ); - expect(find.byType(WordFocusedMobilePage), findsNothing); + expect(find.byType(WordSelectionView), findsOneWidget); }, ); diff --git a/test/word_focused/view/word_focused_view_test.dart b/test/word_focused/view/word_selection_view_test.dart similarity index 59% rename from test/word_focused/view/word_focused_view_test.dart rename to test/word_focused/view/word_selection_view_test.dart index fc6a1a110..691550e5b 100644 --- a/test/word_focused/view/word_focused_view_test.dart +++ b/test/word_focused/view/word_selection_view_test.dart @@ -35,95 +35,84 @@ class _FakeWord extends Fake implements Word { void main() { group('$WordSelectionView', () { - testWidgets( - 'renders WordFocusedDesktopPage when layout is large', - (tester) async { - await tester.pumpApp( - IoLayout( - data: IoLayoutData.large, - child: WordSelectionView(), - ), - ); - - expect(find.byType(WordFocusedDesktopPage), findsOneWidget); - }, - ); + group('renders', () { + late CrosswordBloc crosswordBloc; + late WordSelectionBloc wordSelectionBloc; + late WordSelection selectedWord; + + setUp(() { + crosswordBloc = _MockCrosswordBloc(); + wordSelectionBloc = _MockWordSelectionBloc(); + selectedWord = WordSelection(section: (0, 0), word: _FakeWord()); + }); + + testWidgets('SizedBox when there is no selected word', (tester) async { + when(() => crosswordBloc.state) + .thenReturn(CrosswordState(sectionSize: 20)); - testWidgets( - 'renders WordFocusedMobilePage when layout is small', - (tester) async { await tester.pumpApp( - IoLayout( - data: IoLayoutData.small, - child: WordSelectionView(), - ), + crosswordBloc: crosswordBloc, + WordSelectionView(), ); - expect(find.byType(WordFocusedMobilePage), findsOneWidget); - }, - ); - }); - - group('WordFocusedDesktopPage', () { - late CrosswordBloc crosswordBloc; - late WordSelectionBloc wordSelectionBloc; - late Widget widget; - - final selectedWord = WordSelection(section: (0, 0), word: _FakeWord()); - - setUp(() { - crosswordBloc = _MockCrosswordBloc(); - wordSelectionBloc = _MockWordSelectionBloc(); + expect(find.byType(SizedBox), findsOneWidget); + }); + + testWidgets( + '$WordSelectionLargeView when layout is large', + (tester) async { + when(() => crosswordBloc.state).thenReturn( + CrosswordState( + sectionSize: 20, + selectedWord: selectedWord, + ), + ); + when(() => wordSelectionBloc.state).thenReturn( + WordSelectionState(status: WordSelectionStatus.preSolving), + ); + + await tester.pumpApp( + layout: IoLayoutData.large, + crosswordBloc: crosswordBloc, + BlocProvider( + create: (_) => wordSelectionBloc, + child: WordSelectionView(), + ), + ); + + expect(find.byType(WordSelectionLargeView), findsOneWidget); + }, + ); - widget = MultiBlocProvider( - providers: [ - BlocProvider.value( - value: crosswordBloc, - ), - BlocProvider.value( - value: wordSelectionBloc, - ), - ], - child: WordFocusedDesktopPage(), + testWidgets( + '$WordSelectionSmallView when layout is small', + (tester) async { + when(() => crosswordBloc.state).thenReturn( + CrosswordState( + sectionSize: 20, + selectedWord: selectedWord, + ), + ); + when(() => wordSelectionBloc.state).thenReturn( + WordSelectionState(status: WordSelectionStatus.preSolving), + ); + + await tester.pumpApp( + layout: IoLayoutData.small, + crosswordBloc: crosswordBloc, + BlocProvider( + create: (_) => wordSelectionBloc, + child: WordSelectionView(), + ), + ); + + expect(find.byType(WordSelectionSmallView), findsOneWidget); + }, ); }); - - testWidgets( - 'renders SizedBox.shrink when selectedWord is null', - (tester) async { - when(() => crosswordBloc.state) - .thenReturn(CrosswordState(sectionSize: 20)); - - await tester.pumpApp(widget); - - expect(find.byType(SizedBox), findsOneWidget); - }, - ); - - testWidgets( - 'renders WordFocusedDesktopView when selectedWord is not null', - (tester) async { - when(() => crosswordBloc.state).thenReturn( - CrosswordState( - sectionSize: 20, - selectedWord: selectedWord, - ), - ); - when(() => wordSelectionBloc.state).thenReturn( - WordSelectionState( - status: WordSelectionStatus.preSolving, - wordIdentifier: '1', - ), - ); - - await tester.pumpApp(widget); - - expect(find.byType(WordFocusedDesktopView), findsOneWidget); - }, - ); }); - group('WordFocusedDesktopView', () { + group('$WordSelectionLargeView', () { late WordSelectionBloc wordSelectionBloc; late CrosswordBloc crosswordBloc; late Widget widget; @@ -139,7 +128,7 @@ void main() { BlocProvider.value(value: wordSelectionBloc), BlocProvider.value(value: crosswordBloc), ], - child: WordFocusedDesktopView(selectedWord), + child: WordSelectionLargeView(selectedWord), ); }); @@ -199,62 +188,7 @@ void main() { ); }); - group('WordFocusedMobilePage', () { - late CrosswordBloc crosswordBloc; - late WordSelectionBloc wordSelectionBloc; - late Widget widget; - - final selectedWord = WordSelection(section: (0, 0), word: _FakeWord()); - - setUp(() { - crosswordBloc = _MockCrosswordBloc(); - wordSelectionBloc = _MockWordSelectionBloc(); - - widget = MultiBlocProvider( - providers: [ - BlocProvider.value(value: crosswordBloc), - BlocProvider.value(value: wordSelectionBloc), - ], - child: WordFocusedMobilePage(), - ); - }); - - testWidgets( - 'renders SizedBox.shrink when selectedWord is null', - (tester) async { - when(() => crosswordBloc.state) - .thenReturn(CrosswordState(sectionSize: 20)); - - await tester.pumpApp(widget); - - expect(find.byType(SizedBox), findsOneWidget); - }, - ); - - testWidgets( - 'renders WordFocusedMobileView when selectedWord is not null', - (tester) async { - when(() => crosswordBloc.state).thenReturn( - CrosswordState( - sectionSize: 20, - selectedWord: selectedWord, - ), - ); - when(() => wordSelectionBloc.state).thenReturn( - WordSelectionState( - status: WordSelectionStatus.preSolving, - wordIdentifier: '1', - ), - ); - - await tester.pumpApp(widget); - - expect(find.byType(WordFocusedMobileView), findsOneWidget); - }, - ); - }); - - group('WordFocusedMobileView', () { + group('$WordSelectionSmallView', () { late WordSelectionBloc wordSelectionBloc; late CrosswordBloc crosswordBloc; late Widget widget; @@ -272,7 +206,7 @@ void main() { BlocProvider.value(value: wordSelectionBloc), BlocProvider.value(value: crosswordBloc), ], - child: WordFocusedMobileView(selectedWord), + child: WordSelectionSmallView(selectedWord), ), ); }); diff --git a/test/word_focused/view/word_solving_view_test.dart b/test/word_focused/view/word_solving_view_test.dart index ab598f494..4bfa3002e 100644 --- a/test/word_focused/view/word_solving_view_test.dart +++ b/test/word_focused/view/word_solving_view_test.dart @@ -145,7 +145,7 @@ void main() { BlocProvider.value(value: wordFocusedBloc), BlocProvider.value(value: crosswordBloc), ], - child: WordFocusedMobileView(selectedWord), + child: WordSelectionSmallView(selectedWord), ), );