Merge branch 'ws-files-viewer'
# Conflicts: # app/tool/capture/README.md
This commit is contained in:
@@ -113,6 +113,10 @@ void main() {
|
||||
artifactPreviewFormat('text/html', 'report.html'),
|
||||
ArtifactPreviewFormat.html,
|
||||
);
|
||||
expect(
|
||||
artifactPreviewFormat('audio/mpeg', 'recording.mp3'),
|
||||
ArtifactPreviewFormat.audio,
|
||||
);
|
||||
expect(
|
||||
artifactPreviewFormat('', 'session-repair-3-ab12.html'),
|
||||
ArtifactPreviewFormat.none,
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_preview.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_kind.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_file_bridge.dart';
|
||||
import 'package:pipelines_app/features/artifacts/actions/artifact_transfer.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_fetch.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_page.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_controller.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_models.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_panel.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_thumbnail.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_urls.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_viewer.dart';
|
||||
|
||||
class Gateway extends PipelinesClient {
|
||||
@override
|
||||
Uri get endpoint => Uri.parse('ws://example.test/connect');
|
||||
bool fail = false;
|
||||
@override
|
||||
Stream<JsonMap> get frames => const Stream.empty();
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
if (fail) throw StateError('internal transport secret');
|
||||
return {
|
||||
'directory_listing': {
|
||||
'path': '/home/demo',
|
||||
'home': '/home',
|
||||
'entries': [
|
||||
for (final name in [
|
||||
'notes.txt',
|
||||
'picture.png',
|
||||
'archive.zip',
|
||||
'report.pdf',
|
||||
])
|
||||
{'name': name, 'path': '/home/demo/$name', 'size': 1234},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
late FileUrlResolver original;
|
||||
setUp(() {
|
||||
original = resolveFileUrls;
|
||||
resolveFileUrls = (_, path) => fileUrls('ws://example.test/connect', path);
|
||||
});
|
||||
tearDown(() => resolveFileUrls = original);
|
||||
Future<FilesController> pump(
|
||||
WidgetTester tester, {
|
||||
Gateway? gateway,
|
||||
FilesViewer? viewer,
|
||||
}) async {
|
||||
final controller = FilesController(
|
||||
gateway: gateway ?? Gateway(),
|
||||
initialPath: '/home/demo',
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: FilesPanel(
|
||||
controller: controller,
|
||||
viewer: viewer ?? const FilesViewer(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return controller;
|
||||
}
|
||||
|
||||
testWidgets('text tap opens shared viewer and fetches inline URL', (
|
||||
tester,
|
||||
) async {
|
||||
Uri? fetched;
|
||||
await pump(
|
||||
tester,
|
||||
viewer: FilesViewer(
|
||||
fetch: (url) async {
|
||||
fetched = url;
|
||||
return ArtifactFetchResult(
|
||||
status: 200,
|
||||
bytes: utf8.encode('A text file preview'),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('notes.txt'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
expect(find.text('A text file preview'), findsOneWidget);
|
||||
expect(fetched?.queryParameters['path'], '/home/demo/notes.txt');
|
||||
expect(fetched?.queryParameters.containsKey('download'), isFalse);
|
||||
});
|
||||
testWidgets('image tap opens shared image viewer', (tester) async {
|
||||
await pump(
|
||||
tester,
|
||||
viewer: FilesViewer(
|
||||
fetch: (_) async => ArtifactFetchResult(
|
||||
status: 200,
|
||||
bytes: base64Decode(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('picture.png'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
expect(find.byType(Image), findsWidgets);
|
||||
});
|
||||
testWidgets('unknown file has metadata and a working download', (
|
||||
tester,
|
||||
) async {
|
||||
String? saved;
|
||||
await pump(
|
||||
tester,
|
||||
viewer: FilesViewer(
|
||||
fetch: (_) async =>
|
||||
ArtifactFetchResult(status: 200, bytes: utf8.encode('bytes')),
|
||||
bridge: ArtifactFileBridge(
|
||||
download: (file) async {
|
||||
saved = file.name;
|
||||
return const ArtifactTransferResult(
|
||||
ArtifactTransferState.saved,
|
||||
'Saved file.',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('archive.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('This file type cannot be previewed here.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
await tester.tap(find.text('Download'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(saved, 'archive.zip');
|
||||
expect(find.text('Saved file.'), findsOneWidget);
|
||||
});
|
||||
for (final grid in [false, true]) {
|
||||
testWidgets(
|
||||
'${grid ? 'grid' : 'list'} PDF menu downloads without opening',
|
||||
(tester) async {
|
||||
String? saved;
|
||||
var opened = false;
|
||||
final controller = await pump(
|
||||
tester,
|
||||
viewer: FilesViewer(
|
||||
fetch: (_) async => ArtifactFetchResult(
|
||||
status: 200,
|
||||
bytes: utf8.encode('pdf bytes'),
|
||||
),
|
||||
openExternal: (_) async {
|
||||
opened = true;
|
||||
return true;
|
||||
},
|
||||
bridge: ArtifactFileBridge(
|
||||
download: (file) async {
|
||||
saved = file.name;
|
||||
return const ArtifactTransferResult(
|
||||
ArtifactTransferState.saved,
|
||||
'Saved',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
if (grid) {
|
||||
controller.setView(FilesViewMode.grid);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
await tester.tap(find.byTooltip('File actions').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open'), findsOneWidget);
|
||||
await tester.tap(find.text('Download'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(saved, 'report.pdf');
|
||||
expect(opened, isFalse);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
}
|
||||
testWidgets('thumbnail error falls back to icon and decode stays bounded', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = await pump(tester);
|
||||
controller.setView(FilesViewMode.grid);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(FileThumbnail), findsNWidgets(4));
|
||||
expect(find.byIcon(Icons.image_outlined), findsOneWidget);
|
||||
expect(filesThumbnailDecodeSize(10), 224);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('Cupertino unknown file and menu use native controls', (
|
||||
tester,
|
||||
) async {
|
||||
final controller = FilesController(
|
||||
gateway: Gateway(),
|
||||
initialPath: '/home/demo',
|
||||
);
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: FilesPanel(controller: controller)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('archive.zip'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Download'), findsOneWidget);
|
||||
expect(find.byType(CupertinoButton), findsWidgets);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('PDF external-open failures keep download available', (
|
||||
tester,
|
||||
) async {
|
||||
await pump(
|
||||
tester,
|
||||
viewer: FilesViewer(
|
||||
openExternal: (_) async => throw StateError('no handler'),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.text('report.pdf'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Download'), findsOneWidget);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
testWidgets('download thrown host errors become feedback', (tester) async {
|
||||
await pump(
|
||||
tester,
|
||||
viewer: FilesViewer(
|
||||
fetch: (_) async =>
|
||||
ArtifactFetchResult(status: 200, bytes: utf8.encode('bytes')),
|
||||
bridge: ArtifactFileBridge(
|
||||
download: (_) async => throw StateError('host failure'),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.tap(find.byTooltip('File actions').last);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('Download'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(
|
||||
find.text('Could not download the file. Try again.'),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(tester.takeException(), isNull);
|
||||
});
|
||||
test('file-specific HTML previews preserve artifact export exclusions', () {
|
||||
expect(
|
||||
filePreviewFormat('text/html', 'session.html'),
|
||||
ArtifactPreviewFormat.html,
|
||||
);
|
||||
expect(
|
||||
artifactPreviewFormat('text/html', 'session.html'),
|
||||
ArtifactPreviewFormat.none,
|
||||
);
|
||||
expect(
|
||||
filePreviewFormat('image/svg+xml', 'icon.svg'),
|
||||
ArtifactPreviewFormat.html,
|
||||
);
|
||||
expect(fileContentType('code.dart'), 'text/plain');
|
||||
expect(fileSizeLabel(1024), '1.0 KiB');
|
||||
expect(fileSizeLabel(1024 * 1024), '1.0 MiB');
|
||||
});
|
||||
testWidgets('folder errors hide technical detail', (tester) async {
|
||||
await pump(tester, gateway: Gateway()..fail = true);
|
||||
expect(find.text("Couldn't load this folder."), findsOneWidget);
|
||||
expect(find.textContaining('internal transport'), findsNothing);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/chat/files/files_urls.dart';
|
||||
|
||||
void main() {
|
||||
test('resolves view and attachment urls with encoded paths', () {
|
||||
final urls = fileUrls(
|
||||
'ws://example.test:8081/connect?old=1',
|
||||
'~/My folder/naïve file.txt',
|
||||
);
|
||||
expect(urls, isNotNull);
|
||||
expect(urls!.view.path, '/files');
|
||||
expect(urls.view.queryParameters['path'], '~/My folder/naïve file.txt');
|
||||
expect(urls.view.toString(), contains('My+folder'));
|
||||
expect(urls.view.toString(), contains('na%C3%AFve+file.txt'));
|
||||
expect(urls.download.queryParameters['download'], '1');
|
||||
});
|
||||
|
||||
test('preserves whitespace in actual filenames', () {
|
||||
final urls = fileUrls('ws://example.test/connect', '/home/file.txt ');
|
||||
expect(urls!.view.queryParameters['path'], '/home/file.txt ');
|
||||
});
|
||||
|
||||
test('rejects a missing or invalid endpoint', () {
|
||||
expect(fileUrls('', '/tmp/a.txt'), isNull);
|
||||
expect(fileUrls('http://example.test/connect', '/tmp/a.txt'), isNull);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user