Open a diff as a floating window
Diffs join the app's window system: Open in a window on a diff page or a chat diff card shows the same files, on the same file, in a draggable, resizable window with the full diff viewer (keys, search, all-files view). Offered only where floating windows show; a diff window's files live in memory, so it is not restored after a reload. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/changes/changes.dart';
|
||||
import 'package:pipelines_app/features/changes/windows/diff_windows.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_kind.dart';
|
||||
import 'package:pipelines_app/shell/windows/window_manager.dart';
|
||||
|
||||
FileChange _file(String path) => FileChange(
|
||||
path: path,
|
||||
kind: ChangeKind.modified,
|
||||
patch: '--- a/$path\n+++ b/$path\n@@ -1 +1 @@\n-a\n+b\n',
|
||||
);
|
||||
|
||||
Future<DiffWindows> _pump(WidgetTester tester, Size size) async {
|
||||
tester.view.physicalSize = size;
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final windows = DiffWindows(WindowManager(kinds: WindowKinds()))..start();
|
||||
addTearDown(windows.dispose);
|
||||
final files = [_file('lib/one.dart'), _file('lib/two.dart')];
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DiffWindowsScope(
|
||||
windows: windows,
|
||||
child: Builder(
|
||||
builder: (context) => Scaffold(
|
||||
body: TextButton(
|
||||
onPressed: () =>
|
||||
showFileDiffViewer(context, files[1], files: files),
|
||||
child: const Text('open'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('open'));
|
||||
await tester.pumpAndSettle();
|
||||
return windows;
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('Open in a window leaves the page for a diff window on the '
|
||||
'same file', (tester) async {
|
||||
final windows = await _pump(tester, const Size(1200, 800));
|
||||
await tester.tap(find.byKey(const ValueKey('diff-open-window')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FileDiffPage), findsNothing);
|
||||
|
||||
final entry = windows.manager.windows.single;
|
||||
expect(entry.kind, diffWindowKind);
|
||||
final content = windows.contentOf(entry.contentId)!;
|
||||
expect(content.files, hasLength(2));
|
||||
expect(content.initialIndex, 1);
|
||||
final context = tester.element(find.text('open'));
|
||||
expect(windows.kind.title(context, entry), '2 files changed');
|
||||
|
||||
// Closing the window forgets its files; a saved one is never restored.
|
||||
windows.manager.close(entry.id);
|
||||
expect(windows.contentOf(entry.contentId), isNull);
|
||||
expect(windows.kind.decodeData(const {}), isNull);
|
||||
});
|
||||
|
||||
testWidgets('a phone-width app offers no window', (tester) async {
|
||||
await _pump(tester, const Size(400, 800));
|
||||
expect(find.byType(FileDiffPage), findsOneWidget);
|
||||
expect(find.byKey(const ValueKey('diff-open-window')), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a diff shown in a window has no Back and no Open in a window', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: FileDiffPage(files: [_file('lib/one.dart')], inWindow: true),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byKey(const ValueKey('diff-open-window')), findsNothing);
|
||||
expect(find.byType(BackButton), findsNothing);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user