Skip to content
Merged
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
6 changes: 5 additions & 1 deletion lib/src/view/puzzle/puzzle_feedback_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:lichess_mobile/src/model/settings/brightness.dart';
import 'package:lichess_mobile/src/styles/styles.dart';
import 'package:lichess_mobile/src/utils/l10n_context.dart';
import 'package:lichess_mobile/src/utils/string.dart';
import 'package:lichess_mobile/src/view/account/rating_pref_aware.dart';

class PuzzleFeedbackWidget extends ConsumerWidget {
const PuzzleFeedbackWidget({
Expand Down Expand Up @@ -61,7 +62,10 @@ class PuzzleFeedbackWidget extends ConsumerWidget {
),
subtitle: onStreak && state.result == PuzzleResult.lose
? null
: Text('$puzzleRating. $playedXTimes.'),
: RatingPrefAware(
orElse: Text('$playedXTimes.'),
child: Text('$puzzleRating. $playedXTimes.'),
),
);
case PuzzleMode.load:
case PuzzleMode.play:
Expand Down
26 changes: 20 additions & 6 deletions test/view/puzzle/puzzle_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:http/testing.dart';
import 'package:lichess_mobile/src/model/account/account_preferences.dart';
import 'package:lichess_mobile/src/model/common/http.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/model/common/perf.dart';
Expand All @@ -13,6 +14,7 @@ import 'package:lichess_mobile/src/model/puzzle/puzzle_angle.dart';
import 'package:lichess_mobile/src/model/puzzle/puzzle_batch_storage.dart';
import 'package:lichess_mobile/src/model/puzzle/puzzle_storage.dart';
import 'package:lichess_mobile/src/model/puzzle/puzzle_theme.dart';
import 'package:lichess_mobile/src/utils/string.dart';
import 'package:lichess_mobile/src/view/puzzle/puzzle_screen.dart';
import 'package:lichess_mobile/src/widgets/bottom_bar_button.dart';
import 'package:mocktail/mocktail.dart';
Expand Down Expand Up @@ -249,10 +251,9 @@ void main() {
},
);

testWidgets(
'fails a puzzle',
variant: kPlatformVariant,
(tester) async {
for (final showRatings in [true, false]) {
testWidgets('fails a puzzle, (showRatings: $showRatings)',
variant: kPlatformVariant, (tester) async {
final mockClient = MockClient((request) {
if (request.url.path == '/api/puzzle/batch/mix') {
return mockResponse(batchOf1, 200);
Expand All @@ -277,6 +278,9 @@ void main() {
return mockBatchStorage;
}),
puzzleStorageProvider.overrideWith((ref) => mockHistoryStorage),
showRatingsPrefProvider.overrideWith((ref) {
return showRatings;
}),
],
);

Expand Down Expand Up @@ -343,14 +347,24 @@ void main() {
find.text('Puzzle complete!'),
findsOneWidget,
);
final expectedPlayedXTimes =
'Played ${puzzle2.puzzle.plays.toString().localizeNumbers()} times.';
expect(
find.text(
showRatings
? 'Rating: ${puzzle2.puzzle.rating}. $expectedPlayedXTimes'
: expectedPlayedXTimes,
),
findsOneWidget,
);

// wait for move animation
await tester.pumpAndSettle();

// called once to save solution and once after fetching a new puzzle
verify(saveDBReq).called(2);
},
);
});
}

testWidgets(
'view solution',
Expand Down