Merge: artifact full screen; HTML scrolls, pans and zooms; links open safely

This commit is contained in:
2026-11-03 18:51:15 +00:00
26 changed files with 1305 additions and 319 deletions
@@ -244,7 +244,7 @@ void main() {
expect(find.byType(AlertDialog), findsOneWidget);
expect(find.text('Download'), findsOneWidget);
expect(find.text('Share'), findsOneWidget);
expect(find.text('Open'), findsOneWidget);
expect(find.text('Open in browser'), findsOneWidget);
expect(find.text('Copy link'), findsOneWidget);
await tester.tap(find.text('Download'));
@@ -0,0 +1,42 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_html_links.dart';
void main() {
const inDocument = ArtifactHtmlLinkAction.inDocument;
const external = ArtifactHtmlLinkAction.external;
const blocked = ArtifactHtmlLinkAction.blocked;
final cases = <String, ArtifactHtmlLinkAction>{
'#section-2': inDocument,
' #top ': inDocument,
'about:blank': inDocument,
'about:blank#section-2': inDocument,
'about:srcdoc#top': inDocument,
'https://example.com/report': external,
'HTTP://Example.com': external,
'http://127.0.0.1:8080/x': external,
'mailto:ops@example.com': external,
'javascript:alert(1)': blocked,
' JavaScript:alert(1)': blocked,
'file:///etc/passwd': blocked,
'data:text/html,<b>x</b>': blocked,
'about:config': blocked,
'intent://scan#Intent;end': blocked,
'tel:+15551234': blocked,
'report.html': blocked,
'../7/2/other.html': blocked,
'/api/runs': blocked,
'//example.com/x': blocked,
'http:no-host': blocked,
'': blocked,
};
for (final entry in cases.entries) {
test(
'${entry.key.isEmpty ? '(empty)' : entry.key} -> ${entry.value.name}',
() {
expect(artifactHtmlLinkAction(entry.key), entry.value);
},
);
}
}
@@ -0,0 +1,180 @@
import 'dart:convert';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_fullscreen.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_body.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/artifacts/ui/artifact_visit_list.dart';
import 'artifact_visit_list_fixture.dart';
const _endpoint = 'ws://127.0.0.1:8081/connect';
const _shellBar = Key('shell-tab-bar');
final ArtifactRecord _report = recordedArtifact(
'report.html',
url: '/artifacts/1/1/report.html',
contentType: 'text/html',
);
final ArtifactRecord _log = recordedArtifact(
'build.log',
url: '/artifacts/1/1/build.log',
contentType: 'text/plain',
);
final ArtifactGroup _group = visitGroup(artifacts: [_report, _log]);
/// Each rendered HTML document, with whether it rendered in full screen.
typedef _Rendered = List<(String, bool)>;
Future<({_Rendered rendered, List<Uri> opened})> _pump(
WidgetTester tester, {
bool cupertino = false,
}) async {
final rendered = <(String, bool)>[];
final opened = <Uri>[];
final page = ArtifactViewerPage(
groups: [_group],
selectedIdentity: artifactVisitIdentity(_group, _report),
configuredEndpoint: _endpoint,
fetch: (uri) async => ArtifactFetchResult(
status: 200,
bytes: utf8.encode(uri.path.endsWith('.html') ? '<h1>Hi</h1>' : 'ok'),
),
openExternal: (uri) async {
opened.add(uri);
return true;
},
htmlBuilder: (context, html) {
rendered.add((html, ArtifactFullscreenScope.maybeOf(context) != null));
return Text('html:$html');
},
);
// A stand-in for the shell: a nested navigator holding the viewer above a
// tab bar the full-screen view must cover.
final shell = Column(
children: [
Expanded(
child: Navigator(
onGenerateRoute: (_) => cupertino
? CupertinoPageRoute<void>(builder: (_) => page)
: MaterialPageRoute<void>(builder: (_) => page),
),
),
const SizedBox(key: _shellBar, height: 56, child: Text('Tabs')),
],
);
await tester.pumpWidget(
cupertino ? CupertinoApp(home: shell) : MaterialApp(home: shell),
);
await tester.pumpAndSettle();
return (rendered: rendered, opened: opened);
}
Future<void> _enter(WidgetTester tester) async {
await tester.tap(find.byKey(artifactFullscreenKey));
await tester.pumpAndSettle();
}
/// A bar control by its accessible name: the Material button's tooltip, the
/// Cupertino button's semantics label.
Finder _named(bool cupertino, String name) =>
cupertino ? find.bySemanticsLabel(name) : find.byTooltip(name);
void main() {
for (final cupertino in [false, true]) {
final host = cupertino ? 'Cupertino' : 'Material';
testWidgets('$host: the bottom actions offer Full screen', (tester) async {
final result = await _pump(tester, cupertino: cupertino);
final bar = find.byKey(const Key('artifact-viewer-actions'));
expect(
find.descendant(of: bar, matching: find.byKey(artifactFullscreenKey)),
findsOneWidget,
);
expect(_named(cupertino, 'Full screen'), findsOneWidget);
expect(result.rendered.single, ('<h1>Hi</h1>', false));
});
testWidgets('$host: full screen covers the shell, keeps the actions and '
'renders the fetched document in the app', (tester) async {
final result = await _pump(tester, cupertino: cupertino);
await _enter(tester);
expect(find.byKey(_shellBar), findsNothing);
// The same document, fetched once with the app's session, now in the
// full-screen scope; nothing was handed to the system browser.
expect(result.rendered.last, ('<h1>Hi</h1>', true));
expect(result.opened, isEmpty);
final bar = find.byKey(const Key('artifact-viewer-actions'));
expect(bar, findsOneWidget);
for (final key in const [
Key('artifact-open'),
Key('artifact-copy-link'),
artifactPreviousKey,
artifactNextKey,
]) {
expect(find.descendant(of: bar, matching: find.byKey(key)), findsOne);
}
expect(_named(cupertino, 'Exit full screen'), findsOneWidget);
expect(_named(cupertino, 'Open in browser'), findsOneWidget);
});
testWidgets('$host: Exit full screen returns to the viewer', (
tester,
) async {
await _pump(tester, cupertino: cupertino);
await _enter(tester);
await tester.tap(find.byKey(artifactFullscreenKey));
await tester.pumpAndSettle();
expect(find.byKey(_shellBar), findsOneWidget);
expect(_named(cupertino, 'Full screen'), findsOneWidget);
});
}
testWidgets('Escape and the system back leave full screen', (tester) async {
await _pump(tester);
await _enter(tester);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pumpAndSettle();
expect(find.byKey(_shellBar), findsOneWidget);
expect(find.text('html:<h1>Hi</h1>'), findsOneWidget);
await _enter(tester);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(find.byKey(_shellBar), findsOneWidget);
// Back left full screen only, not the viewer as well.
expect(find.text('html:<h1>Hi</h1>'), findsOneWidget);
});
testWidgets('paging in full screen follows the viewer, any kind', (
tester,
) async {
await _pump(tester);
await _enter(tester);
await tester.tap(find.byKey(artifactNextKey));
await tester.pumpAndSettle();
expect(find.text('build.log'), findsOneWidget);
expect(find.byKey(const Key('artifact-text-preview')), findsOneWidget);
expect(find.byKey(_shellBar), findsNothing);
await tester.tap(find.byKey(artifactFullscreenKey));
await tester.pumpAndSettle();
expect(find.text('build.log'), findsOneWidget);
expect(find.byKey(_shellBar), findsOneWidget);
});
test('zoom steps walk the list and hold at both ends', () {
expect(artifactHtmlZoomStep(1, 1), 1.1);
expect(artifactHtmlZoomStep(1, -1), 0.9);
expect(artifactHtmlZoomStep(4, 1), 4);
expect(artifactHtmlZoomStep(0.5, -1), 0.5);
expect(artifactHtmlZoomStep(1.3, -1), 1.25);
});
}
@@ -188,7 +188,7 @@ void main() {
expect(find.byType(ArtifactViewerPage), findsNothing);
expect(_dialog(platform, 'session.html'), findsOneWidget);
expect(_dialog(platform, 'text/plain · 512\u00a0B'), findsOneWidget);
await tester.tap(_dialog(platform, 'Open'));
await tester.tap(_dialog(platform, 'Open in browser'));
await tester.pumpAndSettle();
expect(find.byType(ArtifactViewerPage), findsNothing);
expect(opened, [
@@ -214,7 +214,7 @@ void main() {
);
await tester.tap(find.text('result.zip'));
await tester.pumpAndSettle();
await tester.tap(_inDialog(_Platform.material, 'Open'));
await tester.tap(_inDialog(_Platform.material, 'Open in browser'));
await tester.pumpAndSettle();
expect(opened, [
@@ -243,7 +243,7 @@ void main() {
),
findsOneWidget,
);
expect(_inDialog(_Platform.material, 'Open'), findsNothing);
expect(_inDialog(_Platform.material, 'Open in browser'), findsNothing);
expect(_inDialog(_Platform.material, 'Copy link'), findsNothing);
});
@@ -270,7 +270,7 @@ void main() {
_inDialog(_Platform.material, 'No artifact URL recorded.'),
findsOneWidget,
);
expect(_inDialog(_Platform.material, 'Open'), findsNothing);
expect(_inDialog(_Platform.material, 'Open in browser'), findsNothing);
});
testWidgets('Copy link copies the resolved url, separate from Open', (
@@ -504,7 +504,7 @@ void main() {
}
expect(orderOf('Close'), lessThan(orderOf('Copy link')));
expect(orderOf('Copy link'), lessThan(orderOf('Open')));
expect(orderOf('Copy link'), lessThan(orderOf('Open in browser')));
},
);
}