halkyon/halkyon_learn_flutter/test/support/fake_settings_gateway.dart
Tizian 「ティツィアーン」 f66595a1d6
All checks were successful
CI / check (push) Successful in 5m44s
CI / deploy (push) Successful in 1m2s
feat(app): study by tag, chosen in synced settings
The study screen's session settings choose tags to study a studyset by:
its cards with any of them. The choice lives in the person's settings
row, synced, by tag id and name, so a renamed tag stays chosen and so
does one folded into another of its name. Two settings rows made offline
fold into the one with the smallest id, which gets what only the other
has.

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

57 lines
1.6 KiB
Dart

import 'dart:async';
import 'dart:typed_data';
import 'package:halkyon_learn_flutter/src/feature/settings/data/settings_gateway.dart';
/// A [SettingsGateway] in memory: ids are `settings-001`, `settings-002`, …,
/// in the order of creation as UUID v7s are, and [receiveRemoteRow] plays a
/// sync that brought a row.
class FakeSettingsGateway() implements SettingsGateway {
final _rows = <String, ByteData>{};
final _remoteChanges = StreamController<void>.broadcast();
var _next = 1;
/// Every payload written, in order, as (id, payload).
final writes = <(String, ByteData)>[];
/// The ids of the deleted rows, in order.
final deleted = <String>[];
/// Stores the row [id] as if another device had written it and a sync had
/// brought it here.
void receiveRemoteRow(String id, ByteData payload) {
_rows[id] = payload;
_remoteChanges.add(null);
}
@override
Future<List<SettingsRow>> rows() async => [
for (final MapEntry(key: id, value: payload) in _rows.entries)
(id: id, payload: payload),
];
@override
Future<String> insert(ByteData payload) async {
final id = 'settings-${'${_next++}'.padLeft(3, '0')}';
_rows[id] = payload;
writes.add((id, payload));
return id;
}
@override
Future<void> updatePayload(String id, ByteData payload) async {
if (_rows.containsKey(id)) {
_rows[id] = payload;
writes.add((id, payload));
}
}
@override
Future<void> delete(String id) async {
_rows.remove(id);
deleted.add(id);
}
@override
Stream<void> get remoteChanges => _remoteChanges.stream;
}