todo-app/test/note_editor_wizard_test.dart
Krzysztof kuhy Rudnicki 10a546f6d6 Split nine oversized test files under the cap
Every split is by test-group/concern, with the shared setup moved to a
sibling helper the splits import. All 313 tests are preserved -- the count
is unchanged and `test('…')` names are byte-identical to the originals
(verified by diffing the sorted name lists).

  note_repository_test      677 -> 4 files + note_repository_helpers
  capture_screen_test       660 -> 4 files + capture_screen_harness
  note_editor_test          502 -> 3 files + note_editor_harness
  port_guard_test           405 -> 3 files + port_guard_fakes
  wrapper_server_test       402 -> 2 files + wrapper_server_harness
  settings_screen_test      391 -> 2 files + settings_screen_harness
  github_mirror_screen_test 365 -> 2 files + github_mirror_harness
  notes_list_screen_test    347 -> 2 files + notes_list_harness
  analytics_service_test    300 -> 2 files + analytics_helpers

Helpers are deliberately NOT named `*_test.dart`; the runner would collect
them and fail on the missing `main()`.

Three things did not survive a mechanical split and were handled explicitly:

  * wrapper_server's `enabledOrigin` closes over the `late root` that setUp
    assigns, so a top-level function cannot see it. It is now a
    WrapperHarness class with an install() that registers the setUp/tearDown
    pair -- the only structural change in this commit.
  * note_repository's splits each repeat `setUpAll(sqfliteFfiInit)`, and
    analytics' each repeat `@TestOn('vm')`. Omitting either fails quietly
    (uninitialised sqflite / wrong platform) rather than loudly.
  * capture_screen's `recordingMock` was declared mid-file between two
    tests, so it moved to the harness rather than being dropped.

Verified: 313 tests pass (same as before the refactor), 100% coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-14 16:42:13 +02:00

181 lines
5.4 KiB
Dart

import 'package:flutter/material.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 'note_editor_harness.dart';
void main() {
testWidgets(
'tapping Guided on an empty draft opens the priority+template wizard',
(tester) async {
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
);
await tester.tap(find.text('Guided'));
await tester.pump();
expect(find.text('Step 1 of 2'), findsOneWidget);
expect(find.byType(DropdownButtonFormField<Priority>), findsOneWidget);
expect(find.byType(LinearProgressIndicator), findsNothing);
},
);
testWidgets(
'the wizard Next/Back moves between priority and template steps',
(tester) async {
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
);
await tester.tap(find.text('Guided'));
await tester.pump();
await tester.tap(find.text('Next'));
await tester.pump();
expect(find.text('Step 2 of 2'), findsOneWidget);
expect(find.byType(DropdownButtonFormField<String>), findsOneWidget);
await tester.tap(find.text('Back'));
await tester.pump();
expect(find.text('Step 1 of 2'), findsOneWidget);
},
);
testWidgets('the wizard template step only offers structured templates', (
tester,
) async {
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
);
await tester.tap(find.text('Guided'));
await tester.pump();
await tester.tap(find.text('Next'));
await tester.pump();
await tester.tap(find.text('LLM design spec').first); // open the menu
await tester.pumpAndSettle();
expect(find.text('Blank'), findsNothing);
// Select the (only) offered template, exercising the dropdown's onChanged.
await tester.tap(find.text('LLM design spec').last);
await tester.pumpAndSettle();
expect(find.text('Step 2 of 2'), findsOneWidget);
});
testWidgets(
'wizard Start commits the chosen priority and enters the bare stepper',
(tester) async {
Priority? committed;
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
onPriorityChanged: (p) => committed = p,
);
await tester.tap(find.text('Guided'));
await tester.pump();
await tester.tap(find.byType(DropdownButtonFormField<Priority>));
await tester.pumpAndSettle();
await tester.tap(find.text('High').last);
await tester.pumpAndSettle();
await tester.tap(find.text('Next'));
await tester.pump();
await tester.tap(find.text('Start'));
await tester.pump();
expect(committed, Priority.high);
expect(find.byType(LinearProgressIndicator), findsOneWidget);
expect(find.byTooltip('Exit guided'), findsOneWidget);
},
);
testWidgets('wizard Cancel returns to Raw with the chrome restored', (
tester,
) async {
final chromeVisible = <bool>[];
await pumpEditor(
tester,
initialTemplate: spec,
initialMode: NoteEditorMode.raw,
onChromeVisibleChanged: chromeVisible.add,
);
await tester.tap(find.text('Guided'));
await tester.pump();
expect(chromeVisible.last, false);
await tester.tap(find.byTooltip('Cancel'));
await tester.pump();
expect(chromeVisible.last, true);
expect(find.byType(LinearProgressIndicator), findsNothing);
expect(find.text('Raw'), findsOneWidget); // chrome's mode selector is back
});
testWidgets('exiting bare Guided via the back arrow restores the chrome', (
tester,
) async {
final chromeVisible = <bool>[];
final conforming = assemble(spec, {'title': 'X', 'what': 'a body'});
await pumpEditor(
tester,
initialTemplate: spec,
initialText: conforming,
onChromeVisibleChanged: chromeVisible.add,
);
expect(find.byType(LinearProgressIndicator), findsOneWidget);
await tester.tap(find.byTooltip('Exit guided'));
await tester.pump();
expect(chromeVisible, contains(true));
expect(find.text('Raw'), findsOneWidget);
});
testWidgets('last step shows Done instead of Next', (tester) async {
await pumpEditor(tester, initialTemplate: spec);
// Navigate to the final step.
for (var i = 0; i < spec.sections.length - 1; i++) {
await tester.tap(find.text('Next'));
await tester.pump();
}
expect(find.text('Done'), findsOneWidget);
expect(find.text('Next'), findsNothing);
expect(
find.text('${spec.sections.length} / ${spec.sections.length}'),
findsOneWidget,
);
});
testWidgets('Done on last step exits Guided and materialises text into Raw', (
tester,
) async {
await pumpEditor(tester, initialTemplate: spec);
await tester.enterText(find.byType(TextField).first, 'My title');
await tester.pump();
for (var i = 0; i < spec.sections.length - 1; i++) {
await tester.tap(find.text('Next'));
await tester.pump();
}
await tester.tap(find.text('Done'));
await tester.pump();
expect(find.byType(LinearProgressIndicator), findsNothing);
final raw = tester.widget<TextField>(find.byType(TextField));
expect(raw.controller!.text, startsWith('# My title'));
});
}