halkyon/halkyon_learn_flutter/test/support/fake_review_gateway.dart
Tizian 「ティツィアーン」 aad6110da3
feat(app): lock the study screen, and undo the last rating
- Lock screen (header): a light scrim takes every touch; a tap shows
  Unlock for three seconds. Time locked doesn't count to the session's,
  and a running Pomodoro timer pauses, going on once unlocked (also
  when the session is left locked).
- Undo last rating (header): takes back one rating at a time within the
  round, its review deleted from the log, the round as it was; the card
  shows again from its question. Starting a round anew, or deleting a
  card, clears what can be undone.
- The review log deletes entries of any kind made at a moment (resets
  and ratings alike).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-09 18:09:13 +02:00

53 lines
1.3 KiB
Dart

import 'package:halkyon_learn_flutter/src/feature/study/data/review_gateway.dart';
/// A [ReviewGateway] in memory; ids sort by creation, as UUID v7 ids do.
class FakeReviewGateway() implements ReviewGateway {
var _nextId = 1;
/// Every review stored, in order.
final rows = <ReviewRow>[];
/// When set, storing a review fails with it.
Exception? failWrites;
@override
Future<List<ReviewRow>> reviewsOf(Set<String> cardIds) async => [
for (final row in rows)
if (cardIds.contains(row.cardId)) row,
];
@override
Future<List<ReviewRow>> allReviews() async => [...rows];
@override
Future<void> insert(Iterable<ReviewRow> reviews) async {
if (failWrites case final error?) {
throw error;
}
for (final review in reviews) {
rows.add((
id: 'review-${(_nextId++).toString().padLeft(4, '0')}',
cardId: review.cardId,
rating: review.rating,
reviewedAt: review.reviewedAt,
durationMs: review.durationMs,
mode: review.mode,
));
}
}
@override
Future<void> deleteReviews(
Set<String> cardIds,
DateTime at,
String mode,
) async => rows.removeWhere(
(row) =>
cardIds.contains(row.cardId) &&
row.mode == mode &&
row.reviewedAt == at,
);
@override
Stream<void> get remoteChanges => const Stream.empty();
}