4e0481fd8d
Full screen button in the viewer's bottom bar opens a root full-screen route with the same bar and top bar; exit by the bar, Close, Escape or back. It renders the already fetched bytes, never the system browser. The external Open action is now labelled Open in browser. Native web views claim their gestures (vertical drags inline, every pointer in full screen) so the page swipe no longer starves them. On the web, full screen adds zoom buttons that scale the live sandboxed frame. Links: in-page anchors scroll, http(s)/mailto open outside, everything else is inert. Capture kit: --touch, swipe=, pinch=, tabs=; html=1 fixture artifact.
181 lines
6.5 KiB
Dart
181 lines
6.5 KiB
Dart
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);
|
|
});
|
|
}
|