open a file in the diff panel via clide ui open diff
Adds diff as a fourth ui.open target. The diff extension now retains an app-scoped DiffController and subscribes to its builtin.diff/selection channel: a selection reveals the diff tab and focuses the file, which the view scrolls into view and highlights. Retaining the controller in the extension (not the view) lets a focus survive the tab being revealed/remounted, mirroring the ReaderNav viewers. Closes T-233. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
/// Tests DiffController's load + focus behaviour (T-233): loading hydrates the
|
||||
/// diff list and clears stale focus; focus() records a path, notifies, and
|
||||
/// reloads; git.changed refreshes.
|
||||
library;
|
||||
|
||||
import 'package:clide/builtin/diff/src/diff_controller.dart';
|
||||
import 'package:clide/clide.dart';
|
||||
import 'package:clide/kernel/kernel.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../helpers/fake_ipc.dart';
|
||||
|
||||
IpcResponse _ok(Map<String, Object?> data) => IpcResponse.ok(id: '', data: data);
|
||||
|
||||
Map<String, Object?> _file(String path) => {'path': path, 'hunks': const []};
|
||||
|
||||
void main() {
|
||||
late DaemonBus bus;
|
||||
late FakeDaemonClient ipc;
|
||||
late DiffController c;
|
||||
late int diffCalls;
|
||||
|
||||
setUp(() {
|
||||
bus = DaemonBus();
|
||||
ipc = FakeDaemonClient(log: Logger(), events: bus);
|
||||
diffCalls = 0;
|
||||
ipc.stub('git.diff', (_) async {
|
||||
diffCalls++;
|
||||
return _ok({
|
||||
'diffs': [_file('lib/a.dart'), _file('lib/b.dart')],
|
||||
});
|
||||
});
|
||||
c = DiffController(ipc: ipc, events: bus);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
c.dispose();
|
||||
await bus.dispose();
|
||||
});
|
||||
|
||||
test('load hydrates the diff list', () async {
|
||||
await c.load();
|
||||
expect(c.diffs.map((d) => d['path']), ['lib/a.dart', 'lib/b.dart']);
|
||||
expect(c.error, isNull);
|
||||
});
|
||||
|
||||
test('focus records the path, notifies, and reloads', () async {
|
||||
await c.load();
|
||||
final before = diffCalls;
|
||||
var notified = 0;
|
||||
c.addListener(() => notified++);
|
||||
|
||||
c.focus('lib/b.dart');
|
||||
expect(c.focusPath, 'lib/b.dart');
|
||||
expect(notified, greaterThan(0));
|
||||
// focus() reloads so the latest edits to that file are present.
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(diffCalls, greaterThan(before));
|
||||
});
|
||||
|
||||
test('a focus whose file leaves the diff is dropped on reload', () async {
|
||||
c.focus('lib/gone.dart');
|
||||
expect(c.focusPath, 'lib/gone.dart');
|
||||
// The reload triggered by focus() returns a list without that file.
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(c.focusPath, isNull);
|
||||
});
|
||||
|
||||
test('a focus that stays in the diff survives reload', () async {
|
||||
c.focus('lib/a.dart');
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(c.focusPath, 'lib/a.dart');
|
||||
});
|
||||
|
||||
test('git.changed refreshes the diff', () async {
|
||||
await c.load();
|
||||
final before = diffCalls;
|
||||
bus.emit(DaemonEvent(subsystem: 'git', kind: 'git.changed', data: const {}, ts: DateTime.now().toUtc()));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(diffCalls, greaterThan(before));
|
||||
});
|
||||
|
||||
test('a git.diff error surfaces on the controller', () async {
|
||||
ipc.stub('git.diff', (_) async => IpcResponse.err(id: '', error: IpcError(code: IpcExitCode.toolError, kind: IpcErrorKind.toolError, message: 'boom')));
|
||||
await c.load();
|
||||
expect(c.error, 'boom');
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/// Widget tests for DiffView focus (T-233): an injected controller renders its
|
||||
/// diffs, and focusing a file highlights its header with the focus accent.
|
||||
library;
|
||||
|
||||
import 'package:clide/builtin/diff/src/diff_controller.dart';
|
||||
import 'package:clide/builtin/diff/src/diff_view.dart';
|
||||
import 'package:clide/clide.dart';
|
||||
import 'package:clide/kernel/kernel.dart';
|
||||
import 'package:clide/widgets/widgets.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import '../../helpers/fake_ipc.dart';
|
||||
import '../../helpers/kernel_fixture.dart';
|
||||
import '../../helpers/widget_harness.dart';
|
||||
|
||||
IpcResponse _ok(Map<String, Object?> data) => IpcResponse.ok(id: '', data: data);
|
||||
Map<String, Object?> _file(String path) => {'path': path, 'hunks': const []};
|
||||
|
||||
ClideText _header(WidgetTester tester, String path) => tester.widget<ClideText>(find.byWidgetPredicate((w) => w is ClideText && w.data == path));
|
||||
|
||||
void main() {
|
||||
late KernelFixture f;
|
||||
late DaemonBus bus;
|
||||
late FakeDaemonClient ipc;
|
||||
late DiffController c;
|
||||
|
||||
setUp(() async {
|
||||
f = await KernelFixture.create();
|
||||
bus = DaemonBus();
|
||||
ipc = FakeDaemonClient(log: Logger(), events: bus);
|
||||
ipc.stub(
|
||||
'git.diff',
|
||||
(_) async => _ok({
|
||||
'diffs': [_file('lib/a.dart'), _file('lib/b.dart')]
|
||||
}));
|
||||
c = DiffController(ipc: ipc, events: bus);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
c.dispose();
|
||||
await bus.dispose();
|
||||
f.dispose();
|
||||
});
|
||||
|
||||
testWidgets('renders the injected controller\'s diffs', (tester) async {
|
||||
await c.load();
|
||||
await tester.pumpWidget(harness(f, DiffView(controller: c)));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byWidgetPredicate((w) => w is ClideText && w.data == 'lib/a.dart'), findsOneWidget);
|
||||
expect(find.byWidgetPredicate((w) => w is ClideText && w.data == 'lib/b.dart'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('focusing a file highlights its header with the focus accent', (tester) async {
|
||||
await c.load();
|
||||
await tester.pumpWidget(harness(f, DiffView(controller: c)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final ctx = tester.element(find.byType(DiffView));
|
||||
final tokens = ClideTheme.of(ctx).surface;
|
||||
// Before focus: header uses the plain panel-header foreground.
|
||||
expect(_header(tester, 'lib/b.dart').color, tokens.panelHeaderForeground);
|
||||
|
||||
c.focus('lib/b.dart');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// After focus: the targeted file's header switches to the focus accent.
|
||||
expect(_header(tester, 'lib/b.dart').color, tokens.globalFocus);
|
||||
// The other file stays unhighlighted.
|
||||
expect(_header(tester, 'lib/a.dart').color, tokens.panelHeaderForeground);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user