Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use Chessboard instead of ChessboardEditor for coordinate training #1311

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading