todo-app/test/ui_images/capture_images_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

140 lines
4.5 KiB
Dart

import 'dart:typed_data';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:todo/data/app_settings.dart';
import 'package:todo/data/note.dart';
import 'package:todo/ui/attachment_picking.dart';
import 'package:todo/ui/image_input.dart';
import 'package:todo/ui/images/attachment_strip.dart';
import '../capture_screen_harness.dart';
import '../fake_image_store.dart';
import '../text_free_guard.dart';
void main() {
testWidgets('📎 on an empty draft creates the note under the file id', (
tester,
) async {
final store = FakeImageStore();
final repo = await pumpCapture(
tester,
imageStore: store,
attachmentPicking: (_) async => [
XFile('/picked/shot.png'),
XFile('/picked/Raport.pdf'),
],
appSettings: ValueNotifier(const AppSettings(advancedMode: false)),
);
await tester.tap(find.bySemanticsLabel('Attach'));
await tester.pump();
await tester.pump();
expect(store.attachedFiles, hasLength(2));
final notes = await repo.listNotes();
expect(notes.single.text, contains('![]('));
expect(notes.single.text, contains('[Raport.pdf]('));
expect(notes.single.text, contains('/${notes.single.id}/'));
expect(find.byType(AttachmentStrip), findsOneWidget);
});
testWidgets('📎 on a started draft files under that note', (tester) async {
final store = FakeImageStore();
final repo = await pumpCapture(
tester,
imageStore: store,
attachmentPicking: (_) async => [XFile('/picked/a.pdf')],
appSettings: ValueNotifier(const AppSettings(advancedMode: false)),
);
await tester.enterText(find.byType(TextField), 'idea');
await tester.pump();
final id = (await repo.listNotes()).single.id;
await tester.tap(find.bySemanticsLabel('Attach'));
await tester.pump();
await tester.pump();
final text = (await repo.listNotes()).single.text;
expect(text, startsWith('idea\n[a.pdf]('));
expect(text, contains('/$id/'));
});
testWidgets('launch and resume reconcile with every note', (tester) async {
final store = FakeImageStore();
await pumpCapture(
tester,
imageStore: store,
seed: [
Note(
id: 'a',
text: 'one',
priority: Priority.medium,
status: Status.done,
createdAt: DateTime(2026),
updatedAt: DateTime(2026),
),
],
);
await tester.pump();
expect(store.reconciles, isNotEmpty);
expect(store.reconciles.last, ['one']);
final before = store.reconciles.length;
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pump();
expect(store.reconciles.length, before + 1);
});
testWidgets('a manual sync reconciles images after it', (tester) async {
final store = FakeImageStore();
await pumpCapture(
tester,
imageStore: store,
prefs: configuredPrefs,
httpClient: recordingMock([]),
);
await tester.pump();
final before = store.reconciles.length;
await tester.tap(find.bySemanticsLabel('Sync'));
await tester.pump();
await tester.pump(const Duration(seconds: 1));
expect(store.reconciles.length, greaterThan(before));
});
testWidgets('a drop attaches any file to the draft', (tester) async {
final store = FakeImageStore();
final repo = await pumpCapture(
tester,
imageStore: store,
appSettings: ValueNotifier(const AppSettings(advancedMode: false)),
);
tester.widget<ImageInputListener>(find.byType(ImageInputListener)).onFiles([
XFile('/dropped/clip.mp4'),
]);
await tester.pump();
await tester.pump();
expect(store.attachedFiles.single.name, 'clip.mp4');
expect((await repo.listNotes()).single.text, contains('[clip.mp4]('));
});
testWidgets('a paste attaches to the draft', (tester) async {
final store = FakeImageStore();
final repo = await pumpCapture(
tester,
imageStore: store,
appSettings: ValueNotifier(const AppSettings(advancedMode: false)),
);
tester.widget<ImageInputListener>(find.byType(ImageInputListener)).onImages(
[
Uint8List.fromList([1]),
],
1,
);
await tester.pump();
await tester.pump();
expect(store.attached, hasLength(1));
expect(
(await repo.listNotes()).single.id,
store.attached.keys.single.noteId,
);
await tester.pump(const Duration(milliseconds: 500)); // snack fades in
expect(spoken('Not an image'), findsOneWidget);
});
}