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

166 lines
5.2 KiB
Dart

import 'package:material_ui/material_ui.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:todo/data/note.dart';
import 'package:todo/data/note_template.dart';
import 'package:todo/data/note_template_parser.dart';
import 'package:todo/ui/image_attach.dart';
import 'package:todo/ui/note_editor.dart';
void main() {
late ImageAttachController attach;
late List<String> emitted;
Future<void> pump(
WidgetTester tester, {
String text = '',
NoteTemplate? template,
NoteEditorMode mode = NoteEditorMode.raw,
ValueChanged<NoteEditorMode>? onModeChanged,
Key? key,
}) async {
attach = ImageAttachController();
emitted = [];
tester.view.physicalSize = const Size(1200, 2400);
tester.view.devicePixelRatio = 1.0;
addTearDown(tester.view.resetPhysicalSize);
addTearDown(tester.view.resetDevicePixelRatio);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: NoteEditor(
key: key,
initialText: text,
initialTemplate: template,
initialMode: mode,
priority: Priority.medium,
onPriorityChanged: (_) {},
onChromeVisibleChanged: (_) {},
onChanged: emitted.add,
attachController: attach,
onModeChanged: onModeChanged,
),
),
),
);
await tester.pump();
}
TextEditingController field(WidgetTester tester) =>
tester.widget<TextField>(find.byType(TextField)).controller!;
testWidgets('raw: inserts on its own line at the cursor', (tester) async {
await pump(tester, text: 'line1\nline2', template: NoteTemplate.blank);
field(tester).selection = const TextSelection.collapsed(offset: 5);
attach.insert(['IMG1', 'IMG2']);
await tester.pump();
expect(field(tester).text, 'line1\nIMG1\nIMG2\nline2');
expect(field(tester).selection.baseOffset, 'line1\nIMG1\nIMG2'.length);
expect(emitted.last, 'line1\nIMG1\nIMG2\nline2');
});
testWidgets('raw: a selection is replaced; no cursor appends', (
tester,
) async {
await pump(tester, text: 'abc', template: NoteTemplate.blank);
field(tester).selection = const TextSelection(
baseOffset: 1,
extentOffset: 2,
);
attach.insert(['I']);
await tester.pump();
expect(field(tester).text, 'a\nI\nc');
field(tester).selection = const TextSelection.collapsed(offset: -1);
attach.insert(['J']);
await tester.pump();
expect(field(tester).text, 'a\nI\nc\nJ\n');
});
testWidgets('raw: an empty note gets just the link', (tester) async {
await pump(tester, template: NoteTemplate.blank);
attach.insert(['I']);
await tester.pump();
expect(field(tester).text, 'I\n');
});
testWidgets('guided: goes into the current step', (tester) async {
await pump(
tester,
template: NoteTemplate.llmDesignSpec,
mode: NoteEditorMode.guided,
);
// In the guided stepper: its exit arrow is present.
expect(find.bySemanticsLabel('Exit guided'), findsOneWidget);
attach.insert(['IMG']);
await tester.pump();
expect(field(tester).text, 'IMG\n');
expect(emitted.last, contains('IMG'));
});
testWidgets('view over a raw note appends to the end', (tester) async {
final modes = <NoteEditorMode>[];
await pump(
tester,
text: 'freeform text',
template: NoteTemplate.blank,
onModeChanged: modes.add,
);
await tester.tap(find.bySemanticsLabel('View'));
await tester.pump();
expect(modes, [NoteEditorMode.preview]);
attach.insert(['IMG']);
await tester.pump();
expect(emitted.last, 'freeform text\nIMG\n');
});
testWidgets('view over guided sections appends to the last section', (
tester,
) async {
const spec = NoteTemplate.llmDesignSpec;
final text = assemble(spec, {
for (final s in spec.sections) s.key: s.isTitle ? 'Title' : 'v ${s.key}',
});
await pump(
tester,
text: text,
template: spec,
mode: NoteEditorMode.preview,
);
attach.insert(['IMG']);
await tester.pump();
final last = spec.sections.last;
final tail = emitted.last.substring(
emitted.last.indexOf('## ${last.label}'),
);
expect(tail, contains('v ${last.key}\nIMG'));
});
testWidgets('a new controller on the same editor is rebound', (tester) async {
await pump(tester, text: 'a', template: NoteTemplate.blank);
final first = attach;
await pump(tester, text: 'a', template: NoteTemplate.blank);
expect(first.insert(['x']), isFalse);
expect(attach.insert(['y']), isTrue);
// Same controller again: nothing to rebind.
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: NoteEditor(
priority: Priority.medium,
onPriorityChanged: (_) {},
onChromeVisibleChanged: (_) {},
onChanged: (_) {},
attachController: attach,
),
),
),
);
expect(attach.insert(['z']), isTrue);
});
testWidgets('disposing the editor unbinds it', (tester) async {
await pump(tester, template: NoteTemplate.blank);
await tester.pumpWidget(const SizedBox());
expect(attach.insert(['x']), isFalse);
});
}