Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/player/bloc' into feat/play…
Browse files Browse the repository at this point in the history
…er/bloc
  • Loading branch information
AyadLaouissi committed Apr 15, 2024
2 parents 0ca5f21 + f40083e commit c9da461
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 265 deletions.
7 changes: 1 addition & 6 deletions lib/bottom_bar/view/bottom_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
2 changes: 1 addition & 1 deletion lib/word_selection/view/view.dart
Original file line number Diff line number Diff line change
@@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion test/crossword/game/crossword_game_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void main() {
targetWord.height / 2,
).translated(
game.camera.visibleWorldRect.size.width *
WordFocusedDesktopView.widthRatio /
WordSelectionLargeView.widthRatio /
2,
0,
);
Expand Down
79 changes: 2 additions & 77 deletions test/crossword/view/crossword_page_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -208,7 +133,7 @@ void main() {
crosswordBloc: crosswordBloc,
);

expect(find.byType(WordFocusedMobilePage), findsNothing);
expect(find.byType(WordSelectionView), findsOneWidget);
},
);

Expand Down
Loading

0 comments on commit c9da461

Please sign in to comment.