Files
clide/test/builtin/editor/editor_view_test.dart
T
jpmschweitzerandClaude 203f8e7681
test / unit + widget + golden + a11y (push) Failing after 25s
test / integration_test (xvfb) (push) Has been skipped
test / bundle smoke (xvfb 5s) (push) Has been skipped
test / daemon subprocess + web WASM smoke (push) Has been skipped
test / dart doc (lib API) (push) Failing after 24s
test: cover editor edit/save/close paths + SyntaxTextController
Follow-up to the multi-tab editor: extends the controller and view
tests to the close-tab, type-to-edit, and Ctrl+S-save paths, plus a
handful of controller edge branches (read errors, null-id events, the
suppressed self-echo, sibling-dirty marking). Adds a SyntaxTextController
suite driving a fake TreeSitterService so the span→TextSpan rendering
and byte→char mapping (including surrogate pairs) are exercised without
the native grammar. Restores total line coverage above the 95% floor.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-05-22 12:59:59 +02:00

146 lines
5.2 KiB
Dart

/// Widget tests for the multi-tab editor view: a tab per open buffer
/// (filename + dirty marker), the empty-state hint, and tab taps
/// routing to `editor.activate`. Buffer-list logic itself is covered
/// in editor_controller_test.dart.
library;
import 'package:clide/builtin/editor/src/editor_view.dart';
import 'package:clide/clide.dart';
import 'package:clide/widgets/widgets.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../helpers/kernel_fixture.dart';
import '../../helpers/widget_harness.dart';
Finder _closeIcons() => find.byWidgetPredicate((w) => w is ClideIcon && w.painter is CloseIcon);
IpcResponse _ok(Map<String, Object?> data) => IpcResponse.ok(id: '', data: data);
Map<String, Object?> _buf(String id, String path, {bool dirty = false}) => {'id': id, 'path': path, 'dirty': dirty};
Map<String, Object?> _read(String id, String path) => {
'id': id,
'path': path,
'content': 'content of $path',
'selection': {'start': 0, 'end': 0},
'dirty': false,
};
void main() {
group('EditorView tabs', () {
late KernelFixture f;
setUp(() async => f = await KernelFixture.create());
tearDown(() => f.dispose());
void stubBuffers(List<Map<String, Object?>> buffers, {String? active}) {
f.ipc.stub('editor.list', (_) async => _ok({'buffers': buffers}));
f.ipc.stub(
'editor.active',
(_) async => active == null
? _ok(const {})
: _ok({
'active': {'id': active}
}));
f.ipc.stub('editor.read', (a) async {
final id = a['id'] as String;
final b = buffers.firstWhere((b) => b['id'] == id);
return _ok(_read(id, b['path'] as String));
});
}
testWidgets('renders one tab per open buffer, by filename', (tester) async {
stubBuffers([_buf('b_1', 'lib/a.dart'), _buf('b_2', 'src/b.dart')], active: 'b_1');
await tester.pumpWidget(harness(f, const EditorView()));
await tester.pumpAndSettle();
expect(find.text('a.dart'), findsOneWidget);
expect(find.text('b.dart'), findsOneWidget);
});
testWidgets('a dirty buffer carries a marker in its tab title', (tester) async {
stubBuffers([_buf('b_1', 'lib/a.dart', dirty: true)], active: 'b_1');
await tester.pumpWidget(harness(f, const EditorView()));
await tester.pumpAndSettle();
expect(find.text('a.dart •'), findsOneWidget);
});
testWidgets('no open buffers shows the open-a-file hint', (tester) async {
stubBuffers(const [], active: null);
await tester.pumpWidget(harness(f, const EditorView()));
await tester.pumpAndSettle();
expect(find.text('Open a file to begin editing.'), findsOneWidget);
});
testWidgets('tapping an inactive tab routes to editor.activate', (tester) async {
stubBuffers([_buf('b_1', 'lib/a.dart'), _buf('b_2', 'src/b.dart')], active: 'b_1');
String? activated;
f.ipc.stub('editor.activate', (a) async {
activated = a['id'] as String?;
return _ok({'active': a['id']});
});
await tester.pumpWidget(harness(f, const EditorView()));
await tester.pumpAndSettle();
await tester.tap(find.text('b.dart'));
await tester.pumpAndSettle();
expect(activated, 'b_2');
});
testWidgets('closing a tab routes to editor.close', (tester) async {
stubBuffers([_buf('b_1', 'lib/a.dart')], active: 'b_1');
String? closed;
f.ipc.stub('editor.close', (a) async {
closed = a['id'] as String?;
return _ok(const {});
});
await tester.pumpWidget(harness(f, const EditorView()));
await tester.pumpAndSettle();
expect(_closeIcons(), findsWidgets);
await tester.tap(_closeIcons().first);
await tester.pumpAndSettle();
expect(closed, 'b_1');
});
testWidgets('typing in the editor mirrors to editor.set-content', (tester) async {
stubBuffers([_buf('b_1', 'lib/a.dart')], active: 'b_1');
Map<String, Object?>? setArgs;
f.ipc.stub('editor.set-content', (a) async {
setArgs = a;
return _ok(const {});
});
await tester.pumpWidget(harness(f, const EditorView()));
await tester.pumpAndSettle();
await tester.enterText(find.byType(EditableText), 'edited body');
await tester.pumpAndSettle();
expect(setArgs?['id'], 'b_1');
expect(setArgs?['text'], 'edited body');
});
testWidgets('Ctrl+S in the editor triggers editor.save', (tester) async {
stubBuffers([_buf('b_1', 'lib/a.dart')], active: 'b_1');
String? saved;
f.ipc.stub('editor.save', (a) async {
saved = a['id'] as String?;
return _ok(const {});
});
await tester.pumpWidget(harness(f, const EditorView()));
await tester.pumpAndSettle();
await tester.tap(find.byType(EditableText));
await tester.pump();
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft);
await tester.sendKeyEvent(LogicalKeyboardKey.keyS);
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft);
await tester.pumpAndSettle();
expect(saved, 'b_1');
});
});
}