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

139 lines
4.7 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/ui/markdown_view.dart';
import 'package:todo/ui/note_editor.dart';
import 'package:todo/ui/template_glyphs.dart';
import 'note_editor_harness.dart';
import 'text_free_guard.dart';
void main() {
testWidgets('guided: typing the title emits an assembled # heading', (
tester,
) async {
final emitted = await pumpEditor(tester, initialTemplate: spec);
expect(find.bySemanticsLabel('Exit guided'), findsOneWidget);
await tester.enterText(find.byType(TextField).first, 'Dark mode');
await tester.pump();
expect(emitted.last, startsWith('# Dark mode'));
});
testWidgets('step page Next/Back navigate and progress counter updates', (
tester,
) async {
await pumpEditor(tester, initialTemplate: spec);
expect(find.byType(LinearProgressIndicator), findsOneWidget);
expect(find.text('1 / ${spec.sections.length}'), findsOneWidget);
await tester.tap(find.bySemanticsLabel('Next'));
await tester.pump();
expect(find.text('2 / ${spec.sections.length}'), findsOneWidget);
await tester.tap(find.bySemanticsLabel('Back'));
await tester.pump();
expect(find.text('1 / ${spec.sections.length}'), findsOneWidget);
expect(find.byType(LinearProgressIndicator), findsOneWidget);
});
testWidgets('guided: the stepper walks the seven audited sections', (
tester,
) async {
// The user-visible contract of the 2026-07 template cut. Walks every step
// and asserts the label and its guidance are the ones on screen, so a
// section resurrected in note_template.dart cannot land unnoticed.
await pumpEditor(tester, initialTemplate: spec);
for (var i = 0; i < spec.sections.length; i++) {
final section = spec.sections[i];
expect(find.text('${i + 1} / ${spec.sections.length}'), findsOneWidget);
// Each step paints its section glyph; label + helper are spoken.
expect(
find.byIcon(sectionIcon(section)),
findsOneWidget,
reason: 'step ${i + 1} should show "${section.label}"',
);
expect(spoken(section.helper), findsOneWidget);
if (i < spec.sections.length - 1) {
await tester.tap(find.bySemanticsLabel('Next'));
await tester.pump();
}
}
// The last step is `read first`; there is no Next past it.
expect(spec.sections.last.label, 'read first');
expect(find.bySemanticsLabel('Next'), findsNothing);
});
testWidgets('pasting a bare link drops the draft to the blank template', (
tester,
) async {
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
);
expect(find.byIcon(Icons.assignment_outlined), findsOneWidget);
await tester.enterText(
find.byType(TextField).first,
'https://example.com/x',
);
await tester.pump();
// Freeform now, so there is no seven-step stepper to walk for a link.
expect(find.byIcon(Icons.note_outlined), findsOneWidget);
expect(find.bySemanticsLabel('Guided'), findsNothing);
// Adding prose puts the spec template back — lossless in both directions.
await tester.enterText(
find.byType(TextField).first,
'https://example.com/x — port this to Dart',
);
await tester.pump();
expect(find.byIcon(Icons.assignment_outlined), findsOneWidget);
expect(find.bySemanticsLabel('Guided'), findsOneWidget);
});
testWidgets('an explicit template choice survives further typing', (
tester,
) async {
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
);
await tester.tap(find.byIcon(Icons.assignment_outlined));
await tester.pumpAndSettle();
await tester.tap(find.byIcon(Icons.note_outlined).last);
await tester.pumpAndSettle();
expect(find.byIcon(Icons.note_outlined), findsOneWidget);
// Prose would normally re-select the spec template; an explicit pick wins.
await tester.enterText(find.byType(TextField).first, 'build a thing');
await tester.pump();
expect(find.byIcon(Icons.note_outlined), findsOneWidget);
});
testWidgets('switching to View renders the note as Markdown', (tester) async {
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
);
await tester.enterText(find.byType(TextField).first, '# Render me');
await tester.pump();
await tester.tap(find.bySemanticsLabel('View'));
await tester.pump();
expect(find.byType(MarkdownView), findsOneWidget);
expect(find.text('Render me'), findsOneWidget); // rendered heading text
});
}