f46b82e207
Keep the Material implementation while preserving public parameters needed by callers. Remove Cupertino-only tests and variants because the app runs exclusively under MaterialApp.
167 lines
5.8 KiB
Dart
167 lines
5.8 KiB
Dart
import 'dart:convert';
|
|
|
|
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,
|
|
) 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: (_) => MaterialPageRoute<void>(builder: (_) => page),
|
|
),
|
|
),
|
|
const SizedBox(key: _shellBar, height: 56, child: Text('Tabs')),
|
|
],
|
|
);
|
|
await tester.pumpWidget(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 Material tooltip.
|
|
Finder _named(String name) => find.byTooltip(name);
|
|
|
|
void main() {
|
|
testWidgets('the bottom actions offer Full screen', (tester) async {
|
|
final result = await _pump(tester);
|
|
final bar = find.byKey(const Key('artifact-viewer-actions'));
|
|
expect(
|
|
find.descendant(of: bar, matching: find.byKey(artifactFullscreenKey)),
|
|
findsOneWidget,
|
|
);
|
|
expect(_named('Full screen'), findsOneWidget);
|
|
expect(result.rendered.single, ('<h1>Hi</h1>', false));
|
|
});
|
|
|
|
testWidgets('full screen covers the shell, keeps the actions and '
|
|
'renders the fetched document in the app', (tester) async {
|
|
final result = await _pump(tester);
|
|
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('Exit full screen'), findsOneWidget);
|
|
expect(_named('Open in browser'), findsOneWidget);
|
|
});
|
|
|
|
testWidgets('Exit full screen returns to the viewer', (tester) async {
|
|
await _pump(tester);
|
|
await _enter(tester);
|
|
await tester.tap(find.byKey(artifactFullscreenKey));
|
|
await tester.pumpAndSettle();
|
|
expect(find.byKey(_shellBar), findsOneWidget);
|
|
expect(_named('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);
|
|
});
|
|
}
|