todo-app/test/notes_list_assign_test.dart
Krzysztof kuhy Rudnicki 3a747c2e51
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Report errors and slow waits to the board
crdt_sync_flutter 0.9.0's installAppErrors in main(): uncaught errors and
every spinner shown over 1 s (WaitWatch: sync.run, mirror.test) upload to
RTDB /todo/errors/<device> with the versionCode, where the PC app-errors
ingest files board tickets (kuhyx/utils DOCS-app-errors.md).

The app moves to material_ui first: sync_settings_ui 0.8.x and
design_system 0.4.x sit on it, and Flutter 3.50 deprecates
flutter/material. Pins: crdt_sync 0.14.1, csf 0.9.0, ssui 0.8.3,
gda 0.5.1, design_system 0.4.1, image 4.13.1, mcp_dart 2.4.4.
file_picker stays 13.3.3, held by data_transfer_flutter 0.2.2
(allowlisted, self-clearing).

appRoute takes a route name so each report names its screen; the
release build passes APP_BUILD/APP_VERSION. Nothing new on screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 23:07:58 +01:00

127 lines
3.8 KiB
Dart

/// Assign-to-repo from the selection bar: picker, move, refusal.
library;
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:todo/data/note.dart';
import 'fake_note_repository.dart';
import 'notes_list_harness.dart';
void _phone(WidgetTester t) {
t.view
..physicalSize = const Size(1080, 2400)
..devicePixelRatio = 2.625;
addTearDown(t.view.reset);
}
Note _repoNote(String id, String text, String repo) {
final n = note(id, text);
return n.copyWith(repo: repo);
}
Future<FakeNoteRepository> _select(
WidgetTester t,
List<Note> seed,
List<String> titles,
) async {
final repo = await pumpList(t, seed: seed, applyFilter: true);
await t.tap(find.byKey(const ValueKey('select-mode')));
await t.pump();
for (final title in titles) {
await t.tap(find.text(title));
await t.pump();
}
await t.tap(find.byKey(const ValueKey('bulk-assign')));
await t.pump();
await t.pump(const Duration(milliseconds: 400));
return repo;
}
Future<void> _settle(WidgetTester t) async {
await t.pump();
await t.pump(const Duration(milliseconds: 400));
}
void main() {
testWidgets('picker lists known repos; picking one moves the notes', (
t,
) async {
_phone(t);
final repo = await _select(
t,
[
_repoNote('r', 'app todos\n\n## Old', 'kuhyx/app'),
_repoNote('o', 'web todos', 'kuhyx/web'),
note('p1', 'Fix login'),
note('p2', 'Tidy up'),
],
['Fix login', 'Tidy up'],
);
expect(find.byKey(const ValueKey('repo-kuhyx/app')), findsOneWidget);
expect(find.byKey(const ValueKey('repo-kuhyx/web')), findsOneWidget);
await t.tap(find.byKey(const ValueKey('repo-kuhyx/app')));
await _settle(t);
final notes = {for (final n in await repo.listNotes()) n.id: n};
expect(notes.keys, unorderedEquals(['r', 'o']));
expect(
notes['r']!.text,
'app todos\n\n## Old\n\n## Fix login\n\n## Tidy up',
);
expect(repo.upsertCalls, 0);
expect(find.byKey(const ValueKey('selection-bar')), findsNothing);
});
testWidgets('a new kuhyx/<name> typed in the field creates its note', (
t,
) async {
_phone(t);
final repo = await _select(t, [note('p', 'Ship it')], ['Ship it']);
final field = find.byKey(const ValueKey('repo-new'));
expect(t.widget<TextField>(field).controller!.text, 'kuhyx/');
await t.enterText(field, 'kuhyx/');
await t.tap(find.byKey(const ValueKey('repo-new-submit')));
await _settle(t);
expect(find.byKey(const ValueKey('repo-picker')), findsOneWidget);
await t.enterText(field, 'kuhyx/fresh');
await t.testTextInput.receiveAction(TextInputAction.done);
await _settle(t);
final made = (await repo.listNotes()).single;
expect(made.repo, 'kuhyx/fresh');
expect(made.text, 'fresh todos\n\n## Ship it');
});
testWidgets('dismissing the picker changes nothing', (t) async {
_phone(t);
final repo = await _select(t, [note('p', 'Ship it')], ['Ship it']);
await t.tapAt(const Offset(10, 40));
await _settle(t);
expect((await repo.listNotes()).single.id, 'p');
expect(find.byKey(const ValueKey('selection-bar')), findsOneWidget);
});
testWidgets('a note already in a repo is refused with a block icon', (
t,
) async {
_phone(t);
final repo = await _select(
t,
[_repoNote('r', 'app todos\n\n## Old', 'kuhyx/app')],
['app todos'],
);
await t.tap(find.byKey(const ValueKey('repo-kuhyx/app')));
await _settle(t);
expect((await repo.listNotes()).single.text, 'app todos\n\n## Old');
expect(find.byIcon(Icons.block), findsOneWidget);
expect(find.byKey(const ValueKey('selection-bar')), findsOneWidget);
await t.pump(const Duration(seconds: 2));
expect(find.byIcon(Icons.block), findsNothing);
});
}