Page through a folder's files in the file viewer
Opening a file from the Files panel now passes the folder's previewable files in their shown order, so the arrows, swipes and Previous/Next step through them and Escape closes the viewer. Download follows the file on screen.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.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';
|
||||
@@ -324,4 +325,45 @@ void main() {
|
||||
expect(find.text("Couldn't load this folder."), findsOneWidget);
|
||||
expect(find.textContaining('internal transport'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('arrows step through the folder\'s previewable files and '
|
||||
'Escape closes the viewer', (tester) async {
|
||||
final fetched = <String>[];
|
||||
await pump(
|
||||
tester,
|
||||
viewer: FilesViewer(
|
||||
fetch: (url) async {
|
||||
fetched.add(url.queryParameters['path'] ?? '');
|
||||
return ArtifactFetchResult(
|
||||
status: 200,
|
||||
bytes: url.queryParameters['path']!.endsWith('.png')
|
||||
? base64Decode(
|
||||
'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==',
|
||||
)
|
||||
: utf8.encode('A text file preview'),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
Finder shown(String name) => find.descendant(
|
||||
of: find.byType(ArtifactViewerPage),
|
||||
matching: find.text(name),
|
||||
);
|
||||
await tester.tap(find.text('notes.txt'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsOneWidget);
|
||||
expect(shown('notes.txt'), findsWidgets);
|
||||
// The zip and PDF are not previewable, so the next file is the image.
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pumpAndSettle();
|
||||
expect(shown('picture.png'), findsWidgets);
|
||||
expect(fetched, contains('/home/demo/picture.png'));
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
|
||||
await tester.pumpAndSettle();
|
||||
expect(shown('notes.txt'), findsWidgets);
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(ArtifactViewerPage), findsNothing);
|
||||
expect(find.text('notes.txt'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user