Skip to content

Commit

Permalink
fix: use Chessboard instead of ChessboardEditor for coordinate training
Browse files Browse the repository at this point in the history
Fixes #1017
  • Loading branch information
tom-anders committed Dec 26, 2024
1 parent 59a38b0 commit b3f114f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ class _TrainingBoardState extends ConsumerState<_TrainingBoard> {
Stack(
alignment: Alignment.center,
children: [
ChessboardEditor(
Chessboard.fixed(
size: widget.boardSize,
pieces: readFen(trainingPrefs.showPieces ? kInitialFEN : kEmptyFEN),
fen: trainingPrefs.showPieces ? kInitialFEN : kEmptyFEN,
squareHighlights: widget.squareHighlights,
orientation: widget.orientation,
settings: boardPrefs.toBoardSettings().copyWith(
Expand All @@ -444,8 +444,7 @@ class _TrainingBoardState extends ConsumerState<_TrainingBoard> {
: BorderRadius.zero,
boxShadow: widget.isTablet ? boardShadows : const <BoxShadow>[],
),
pointerMode: EditorPointerMode.edit,
onEditedSquare: (square) {
onTappedSquare: (square) {
if (trainingState.trainingActive && trainingPrefs.mode == TrainingMode.findSquare) {
widget.onGuess(square);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies:
async: ^2.10.0
auto_size_text: ^3.0.0
cached_network_image: ^3.2.2
chessground: ^6.2.3
chessground: ^6.3.0
clock: ^1.1.1
collection: ^1.17.0
connectivity_plus: ^6.0.2
Expand Down
35 changes: 16 additions & 19 deletions test/view/coordinate_training/coordinate_training_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import 'package:dartchess/dartchess.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lichess_mobile/src/model/common/game.dart';
import 'package:lichess_mobile/src/model/coordinate_training/coordinate_training_controller.dart';
import 'package:lichess_mobile/src/model/coordinate_training/coordinate_training_preferences.dart';
import 'package:lichess_mobile/src/view/coordinate_training/coordinate_training_screen.dart';

import '../../test_helpers.dart';
import '../../test_provider_scope.dart';

void main() {
Expand All @@ -18,13 +20,11 @@ void main() {
await tester.tap(find.text('Start Training'));
await tester.pumpAndSettle();

final container = ProviderScope.containerOf(tester.element(find.byType(ChessboardEditor)));
final container = ProviderScope.containerOf(tester.element(find.byType(Chessboard)));
final controllerProvider = coordinateTrainingControllerProvider;

final trainingPrefsNotifier = container.read(coordinateTrainingPreferencesProvider.notifier);
trainingPrefsNotifier.setMode(TrainingMode.findSquare);
// This way all squares can be found via find.byKey(ValueKey('${square.name}-empty'))
trainingPrefsNotifier.setShowPieces(false);
await tester.pumpAndSettle();

expect(container.read(controllerProvider).score, 0);
Expand All @@ -41,24 +41,22 @@ void main() {
final app = await makeTestProviderScopeApp(tester, home: const CoordinateTrainingScreen());
await tester.pumpWidget(app);

final container = ProviderScope.containerOf(tester.element(find.byType(Chessboard)));
final trainingPrefsNotifier = container.read(coordinateTrainingPreferencesProvider.notifier);
trainingPrefsNotifier.setMode(TrainingMode.findSquare);
trainingPrefsNotifier.setSideChoice(SideChoice.white);

await tester.tap(find.text('Start Training'));
await tester.pumpAndSettle();

final container = ProviderScope.containerOf(tester.element(find.byType(ChessboardEditor)));
final controllerProvider = coordinateTrainingControllerProvider;

final trainingPrefsNotifier = container.read(coordinateTrainingPreferencesProvider.notifier);
trainingPrefsNotifier.setMode(TrainingMode.findSquare);
// This way all squares can be found via find.byKey(ValueKey('${square.name}-empty'))
trainingPrefsNotifier.setShowPieces(false);
await tester.pumpAndSettle();

final currentCoord = container.read(controllerProvider).currentCoord;
final nextCoord = container.read(controllerProvider).nextCoord;

final wrongCoord = Square.values[(currentCoord! + 1) % Square.values.length];

await tester.tap(find.byKey(ValueKey('${wrongCoord.name}-empty')));
await tester.tapAt(squareOffset(wrongCoord, tester.getRect(find.byType(Chessboard))));
await tester.pump();

expect(container.read(controllerProvider).score, 0);
Expand All @@ -76,22 +74,21 @@ void main() {
final app = await makeTestProviderScopeApp(tester, home: const CoordinateTrainingScreen());
await tester.pumpWidget(app);

await tester.tap(find.text('Start Training'));
await tester.pumpAndSettle();
final container = ProviderScope.containerOf(tester.element(find.byType(Chessboard)));
final trainingPrefsNotifier = container.read(coordinateTrainingPreferencesProvider.notifier);
trainingPrefsNotifier.setMode(TrainingMode.findSquare);
trainingPrefsNotifier.setSideChoice(SideChoice.white);

final container = ProviderScope.containerOf(tester.element(find.byType(ChessboardEditor)));
final controllerProvider = coordinateTrainingControllerProvider;

final trainingPrefsNotifier = container.read(coordinateTrainingPreferencesProvider.notifier);
trainingPrefsNotifier.setMode(TrainingMode.findSquare);
// This way all squares can be found via find.byKey(ValueKey('${square.name}-empty'))
trainingPrefsNotifier.setShowPieces(false);
await tester.tap(find.text('Start Training'));
await tester.pumpAndSettle();

final currentCoord = container.read(controllerProvider).currentCoord;
final nextCoord = container.read(controllerProvider).nextCoord;

await tester.tap(find.byKey(ValueKey('${currentCoord!.name}-empty')));
await tester.tapAt(squareOffset(currentCoord!, tester.getRect(find.byType(Chessboard))));

await tester.pump();

expect(find.byKey(ValueKey('${currentCoord.name}-highlight')), findsOneWidget);
Expand Down

0 comments on commit b3f114f

Please sign in to comment.