fix(app): restore standard Android back navigation
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// Asks before Back leaves the app from the top of a tab. True to leave.
|
||||
Future<bool> confirmAppExit(
|
||||
BuildContext context, {
|
||||
required bool cupertino,
|
||||
}) async {
|
||||
const title = Text('Close Pipelines?');
|
||||
final leave = cupertino
|
||||
? await showCupertinoDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoAlertDialog(
|
||||
title: title,
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
key: const Key('app-exit-stay'),
|
||||
isDefaultAction: true,
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Stay'),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
key: const Key('app-exit-close'),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: title,
|
||||
actions: [
|
||||
TextButton(
|
||||
key: const Key('app-exit-stay'),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('Stay'),
|
||||
),
|
||||
FilledButton(
|
||||
key: const Key('app-exit-close'),
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
return leave ?? false;
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'app_exit_dialog.dart';
|
||||
import 'app_route.dart';
|
||||
|
||||
/// Parses the browser (or platform) location into the app's routes.
|
||||
@@ -152,9 +149,9 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
_page(
|
||||
_pageKey,
|
||||
PopScope(
|
||||
canPop: !_canStepUp && !_asksBeforeExit,
|
||||
canPop: !_canStepUp,
|
||||
onPopInvokedWithResult: (didPop, _) {
|
||||
if (!didPop && !_stepUp()) _confirmExit();
|
||||
if (!didPop) _stepUp();
|
||||
},
|
||||
child: builder(context, shellRoute),
|
||||
),
|
||||
@@ -247,26 +244,7 @@ class AppRouterDelegate extends RouterDelegate<AppRoute> with ChangeNotifier {
|
||||
return true;
|
||||
}
|
||||
if (_stepUp()) return true;
|
||||
return _confirmExit();
|
||||
}
|
||||
|
||||
/// At the top of a tab Android's Back would leave the app; ask first.
|
||||
/// Elsewhere (a browser) Back keeps its usual meaning.
|
||||
bool get _asksBeforeExit =>
|
||||
!kIsWeb && defaultTargetPlatform == TargetPlatform.android;
|
||||
|
||||
bool _confirming = false;
|
||||
|
||||
bool _confirmExit() {
|
||||
final context = _navigatorKey.currentContext;
|
||||
if (!_asksBeforeExit || context == null) return false;
|
||||
if (_confirming) return true;
|
||||
_confirming = true;
|
||||
confirmAppExit(context, cupertino: cupertino).then((leave) {
|
||||
_confirming = false;
|
||||
if (leave) SystemNavigator.pop();
|
||||
});
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Whether the open route has a level above it in its own tab (a stage,
|
||||
|
||||
@@ -51,12 +51,13 @@ class DetailPageHost {
|
||||
// Pushing during a build is not allowed; the page follows this frame.
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!context.mounted || _route != route) return;
|
||||
Navigator.of(context).push(route).then((_) {
|
||||
Navigator.of(context).push(route);
|
||||
route.completed.then((_) {
|
||||
if (_route != route) return;
|
||||
_route = null;
|
||||
// Rebuild what lies underneath (route, tab bar, list) once the
|
||||
// page has finished sliding away, not during its animation.
|
||||
_afterExit(route, onClosed);
|
||||
// Keep ownership until the route is actually gone. Live updates
|
||||
// during its exit must not push a second copy of the detail page.
|
||||
onClosed();
|
||||
});
|
||||
});
|
||||
} else if (!selected && _route != null) {
|
||||
@@ -68,21 +69,6 @@ class DetailPageHost {
|
||||
}
|
||||
}
|
||||
|
||||
static void _afterExit(Route<void> route, VoidCallback onClosed) {
|
||||
final animation = route is ModalRoute<void> ? route.animation : null;
|
||||
if (animation == null || animation.status == AnimationStatus.dismissed) {
|
||||
onClosed();
|
||||
return;
|
||||
}
|
||||
late final AnimationStatusListener listener;
|
||||
listener = (status) {
|
||||
if (status != AnimationStatus.dismissed) return;
|
||||
animation.removeStatusListener(listener);
|
||||
onClosed();
|
||||
};
|
||||
animation.addStatusListener(listener);
|
||||
}
|
||||
|
||||
/// Removes the page with its owner.
|
||||
void dispose() {
|
||||
// The notifier is left to the page: a page still animating out keeps
|
||||
@@ -95,7 +81,7 @@ class DetailPageHost {
|
||||
|
||||
/// A full-screen page whose bar shows what the page's content publishes
|
||||
/// through [ShellBar] (title and actions), with the platform's Back.
|
||||
Route<void> detailPageRoute(
|
||||
PageRoute<void> detailPageRoute(
|
||||
BuildContext context, {
|
||||
required AppDestination destination,
|
||||
required WidgetBuilder builder,
|
||||
|
||||
@@ -30,12 +30,11 @@ ThemeData appLightTheme() => ThemeData(
|
||||
pageTransitionsTheme: appPageTransitions,
|
||||
);
|
||||
|
||||
/// Pages slide in and out quickly. Android's default fades the whole page,
|
||||
/// which is costly for long pages (a chat) and made Back feel slow; iOS keeps
|
||||
/// its native transition and swipe-back.
|
||||
/// Android and iOS keep their native transitions and interactive back gestures.
|
||||
/// Desktop hosts use the short horizontal slide.
|
||||
const appPageTransitions = PageTransitionsTheme(
|
||||
builders: {
|
||||
TargetPlatform.android: FastSlidePageTransitionsBuilder(),
|
||||
TargetPlatform.android: PredictiveBackPageTransitionsBuilder(),
|
||||
TargetPlatform.fuchsia: FastSlidePageTransitionsBuilder(),
|
||||
TargetPlatform.linux: FastSlidePageTransitionsBuilder(),
|
||||
TargetPlatform.windows: FastSlidePageTransitionsBuilder(),
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# Standard back navigation
|
||||
|
||||
## Source and verification
|
||||
|
||||
- Restored Flutter's Android predictive-back transition in both themes. The
|
||||
custom Android slide omitted Flutter's gesture observer; real-app composition
|
||||
tests proved gesture start was not handled before restoring the native builder.
|
||||
- Removed the Android exit-confirmation dialog and direct SystemNavigator.pop
|
||||
workaround. Back at a list root falls through to the platform.
|
||||
- Kept detail-route ownership until PageRoute.completed. Previously push's
|
||||
returned future cleared ownership at pop start; an owner rebuild during the
|
||||
reverse animation could push another page or notify listeners during build.
|
||||
- Regressions cover Pipelines/Runs/Chat: actual system-back dispatch, dialog first,
|
||||
canceled and committed predictive gestures, list restoration and platform exit.
|
||||
A separate lifecycle regression rebuilds the owner during an ordinary pop and
|
||||
a committed gesture. Existing deep-link, wide-screen and browser route tests pass.
|
||||
- `FLUTTER=/Users/alan/development/flutter/bin/flutter sh tool/check_full.sh`:
|
||||
clean analysis, all 1,744 tests pass.
|
||||
- `flutter build web -o build/navigation_web`: pass.
|
||||
- `node tool/detail_navigation_probe.mjs build/navigation_web build/navigation-evidence`:
|
||||
12 checks, 9 captures; real Chrome at 390x844 exercises list selection, browser
|
||||
Back/Forward, toolbar Back and repeated opening/closing for all three features.
|
||||
Captures and result.json are in `app/build/navigation-evidence/`.
|
||||
The chat fixture explicitly lacks chat_shells; its visible unavailable message
|
||||
is fixture evidence, not a navigation failure.
|
||||
- Android device behavior is unverified. Gesture coverage dispatches Flutter's
|
||||
actual flutter/backgesture platform messages in widget tests, not on a device.
|
||||
|
||||
## Delivery
|
||||
|
||||
The user explicitly approved overriding the app's no-deploy/no-APK rules for
|
||||
the requested web/server installation and APK publication, without device tests.
|
||||
Deployment results are recorded after running the installers.
|
||||
@@ -0,0 +1,151 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_router.dart';
|
||||
import 'package:pipelines_app/core/transport/pipelines_client.dart';
|
||||
|
||||
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
|
||||
import '../features/pipelines/fixtures.dart';
|
||||
import 'chat_registration_test.dart' as chat;
|
||||
import 'pipelines_app_test.dart' as app;
|
||||
import 'pipelines_replies.dart' as pipelines;
|
||||
|
||||
Future<void> backGesture(WidgetTester tester, String method) async {
|
||||
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
|
||||
'flutter/backgesture',
|
||||
const StandardMethodCodec().encodeMethodCall(
|
||||
MethodCall(
|
||||
method,
|
||||
method == 'startBackGesture'
|
||||
? {
|
||||
'touchOffset': <double>[5, 300],
|
||||
'progress': 0.0,
|
||||
'swipeEdge': 0,
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
(_) {},
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final predictive in [false, true]) {
|
||||
for (final destination in ['pipelines', 'runs', 'chat']) {
|
||||
testWidgets(
|
||||
'$destination: ${predictive ? 'gesture' : 'button'} Back pops dialog, detail, then app',
|
||||
(tester) async {
|
||||
tester.view.physicalSize = const Size(390, 844);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final exits = <String>[];
|
||||
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
SystemChannels.platform,
|
||||
(call) async {
|
||||
if (call.method == 'SystemNavigator.pop') exits.add(call.method);
|
||||
return null;
|
||||
},
|
||||
);
|
||||
addTearDown(
|
||||
() => tester.binding.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(SystemChannels.platform, null),
|
||||
);
|
||||
final channel = FakeChannel()..readyCompleter.complete();
|
||||
final provider = PlatformRouteInformationProvider(
|
||||
initialRouteInformation: RouteInformation(
|
||||
uri: Uri.parse('/$destination'),
|
||||
),
|
||||
);
|
||||
addTearDown(provider.dispose);
|
||||
await app.pumpApp(
|
||||
tester,
|
||||
channel: channel,
|
||||
client: PipelinesClient(channelFactory: (_) => channel),
|
||||
provider: provider,
|
||||
);
|
||||
final fixture = PipelineFixture();
|
||||
final String title;
|
||||
switch (destination) {
|
||||
case 'pipelines':
|
||||
title = 'Alpha review';
|
||||
await pipelines.replyPipelines(tester, channel, fixture);
|
||||
case 'runs':
|
||||
title = 'Navigation run';
|
||||
await app.replyList(
|
||||
tester,
|
||||
channel,
|
||||
runs: [
|
||||
{'id': 1, 'title': title, 'status': 'succeeded'},
|
||||
],
|
||||
);
|
||||
default:
|
||||
title = 'Wire chat';
|
||||
await chat.replySessions(tester, channel);
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text(title).first);
|
||||
await tester.pump();
|
||||
switch (destination) {
|
||||
case 'pipelines':
|
||||
await pipelines.replyPipelineDetail(tester, channel, fixture);
|
||||
case 'runs':
|
||||
await app.replyDetail(tester, channel, 1);
|
||||
default:
|
||||
await chat.replySubscribe(tester, channel);
|
||||
await chat.replyHistory(tester, channel);
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
final detailPath = provider.value.uri.path;
|
||||
expect(detailPath, isNot('/$destination'));
|
||||
final navigator = tester.state<NavigatorState>(
|
||||
find.byType(Navigator),
|
||||
);
|
||||
expect(navigator.canPop(), isTrue);
|
||||
|
||||
if (predictive) {
|
||||
await backGesture(tester, 'startBackGesture');
|
||||
expect(navigator.userGestureInProgress, isTrue);
|
||||
await backGesture(tester, 'cancelBackGesture');
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, detailPath);
|
||||
expect(navigator.canPop(), isTrue);
|
||||
}
|
||||
|
||||
// A real route on top of the detail must consume Back first.
|
||||
showDialog<void>(
|
||||
context: navigator.overlay!.context,
|
||||
builder: (_) => const AlertDialog(title: Text('Navigation dialog')),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Navigation dialog'), findsNothing);
|
||||
expect(provider.value.uri.path, detailPath);
|
||||
expect(find.byKey(const ValueKey('shell.back')), findsOneWidget);
|
||||
|
||||
if (predictive) {
|
||||
await backGesture(tester, 'startBackGesture');
|
||||
await backGesture(tester, 'commitBackGesture');
|
||||
} else {
|
||||
await tester.binding.handlePopRoute();
|
||||
}
|
||||
await tester.pumpAndSettle();
|
||||
expect(provider.value.uri.path, '/$destination');
|
||||
expect(find.text(title), findsWidgets);
|
||||
expect(navigator.canPop(), isFalse);
|
||||
expect(exits, isEmpty);
|
||||
|
||||
// No confirmation, double-back requirement, or hidden detail route.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
expect(find.text('Close Pipelines?'), findsNothing);
|
||||
final router =
|
||||
Router.of(navigator.context).routerDelegate as AppRouterDelegate;
|
||||
expect(router.route.path, '/$destination');
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -213,20 +213,12 @@ void main() {
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
expect(exits, isEmpty);
|
||||
|
||||
// From the list, Back asks before leaving the app.
|
||||
// From the list, Back is left to Android. No custom exit dialog.
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Close Pipelines?'), findsOneWidget);
|
||||
await tester.tap(find.byKey(const Key('app-exit-stay')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(exits, isEmpty);
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.byKey(const Key('app-exit-close')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Close Pipelines?'), findsNothing);
|
||||
expect(exits, ['SystemNavigator.pop']);
|
||||
expect(provider.value.uri.path, '/runs');
|
||||
});
|
||||
|
||||
testWidgets('tabs and run selection update the route; browser Back pops it', (
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/shell/destination.dart';
|
||||
import 'package:pipelines_app/shell/detail_page.dart';
|
||||
@@ -82,7 +83,12 @@ void main() {
|
||||
expect(find.text('detail 3'), findsNothing);
|
||||
expect(find.text('the list'), findsOneWidget);
|
||||
// Removed by the owner, so nothing is reported back.
|
||||
expect(tester.state<_OwnerState>(find.byType(_Owner)).closed, 0);
|
||||
expect(
|
||||
tester
|
||||
.state<_OwnerState>(find.byType(_Owner, skipOffstage: false))
|
||||
.closed,
|
||||
0,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('the system Back closes the page first', (tester) async {
|
||||
@@ -95,4 +101,80 @@ void main() {
|
||||
expect(find.text('the list'), findsOneWidget);
|
||||
expect(selection.value, isNull);
|
||||
});
|
||||
|
||||
testWidgets('an owner update during Back does not push the detail again', (
|
||||
tester,
|
||||
) async {
|
||||
final selection = ValueNotifier<String?>('5');
|
||||
await tester.pumpWidget(MaterialApp(home: _Owner(selection: selection)));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.binding.handlePopRoute();
|
||||
await tester.pump(const Duration(milliseconds: 30));
|
||||
// A live reply rebuilds the owner while the page is sliding away.
|
||||
selection.value = '6';
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('the list'), findsOneWidget);
|
||||
expect(find.text('detail 6'), findsNothing);
|
||||
expect(selection.value, isNull);
|
||||
expect(tester.state<_OwnerState>(find.byType(_Owner)).closed, 1);
|
||||
expect(
|
||||
tester.state<NavigatorState>(find.byType(Navigator)).canPop(),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('Android predictive Back can cancel, then commit one pop', (
|
||||
tester,
|
||||
) async {
|
||||
final selection = ValueNotifier<String?>('5');
|
||||
await tester.pumpWidget(MaterialApp(home: _Owner(selection: selection)));
|
||||
await tester.pumpAndSettle();
|
||||
final navigator = tester.state<NavigatorState>(find.byType(Navigator));
|
||||
|
||||
Future<void> gesture(String method) async {
|
||||
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
|
||||
'flutter/backgesture',
|
||||
const StandardMethodCodec().encodeMethodCall(
|
||||
MethodCall(
|
||||
method,
|
||||
method == 'startBackGesture'
|
||||
? {
|
||||
'touchOffset': <double>[5, 300],
|
||||
'progress': 0.0,
|
||||
'swipeEdge': 0,
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
(_) {},
|
||||
);
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
await gesture('startBackGesture');
|
||||
expect(navigator.userGestureInProgress, isTrue);
|
||||
await gesture('cancelBackGesture');
|
||||
await tester.pumpAndSettle();
|
||||
expect(selection.value, '5');
|
||||
expect(find.text('detail 5'), findsOneWidget);
|
||||
expect(
|
||||
tester
|
||||
.state<_OwnerState>(find.byType(_Owner, skipOffstage: false))
|
||||
.closed,
|
||||
0,
|
||||
);
|
||||
|
||||
await gesture('startBackGesture');
|
||||
expect(navigator.userGestureInProgress, isTrue);
|
||||
await gesture('commitBackGesture');
|
||||
// Rebuild during the committed gesture's closing animation as well.
|
||||
selection.value = '6';
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('the list'), findsOneWidget);
|
||||
expect(selection.value, isNull);
|
||||
expect(tester.state<_OwnerState>(find.byType(_Owner)).closed, 1);
|
||||
expect(navigator.canPop(), isFalse);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
@@ -26,18 +27,14 @@ void main() {
|
||||
expect(AppColors.groupedBackground.darkColor, isNot(CupertinoColors.black));
|
||||
});
|
||||
|
||||
test('Android pages slide quickly, without a fade', () {
|
||||
final builder =
|
||||
appDarkTheme().pageTransitionsTheme.builders[TargetPlatform.android]!;
|
||||
expect(builder, isA<FastSlidePageTransitionsBuilder>());
|
||||
expect(builder.transitionDuration.inMilliseconds, lessThanOrEqualTo(200));
|
||||
test('Android pages retain native predictive Back in both themes', () {
|
||||
expect(
|
||||
builder.reverseTransitionDuration.inMilliseconds,
|
||||
lessThanOrEqualTo(200),
|
||||
appDarkTheme().pageTransitionsTheme.builders[TargetPlatform.android],
|
||||
isA<PredictiveBackPageTransitionsBuilder>(),
|
||||
);
|
||||
expect(
|
||||
appLightTheme().pageTransitionsTheme.builders[TargetPlatform.android],
|
||||
isA<FastSlidePageTransitionsBuilder>(),
|
||||
isA<PredictiveBackPageTransitionsBuilder>(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
// Real web navigation against the isolated fixture; no deployed service/data.
|
||||
// node tool/detail_navigation_probe.mjs build/navigation_web build/navigation-evidence
|
||||
import assert from 'node:assert/strict';
|
||||
import { mkdtemp, mkdir, writeFile } from 'node:fs/promises';
|
||||
import { once } from 'node:events';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { startFixture } from './runs_probe_server.mjs';
|
||||
import { startWiringFixture } from './pipelines_wiring_probe_server.mjs';
|
||||
import {
|
||||
launchChrome, waitForPort, waitForPage, connect, sleep,
|
||||
} from './pipelines_probe_cdp_lib.mjs';
|
||||
import {
|
||||
enableSemantics, click, clickAt, assertName, capture, waitFor, axNodes,
|
||||
} from './pipelines_probe_cdp_input.mjs';
|
||||
|
||||
const build = resolve(process.argv[2] ?? 'build/navigation_web');
|
||||
const output = resolve(process.argv[3] ?? 'build/navigation-evidence');
|
||||
await mkdir(output, { recursive: true });
|
||||
const fixture = await startFixture({ root: build });
|
||||
const pipelineFixture = await startWiringFixture({ root: build });
|
||||
const profile = await mkdtemp(join(tmpdir(), 'detail-navigation-'));
|
||||
const chrome = launchChrome(
|
||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||
profile,
|
||||
'about:blank',
|
||||
);
|
||||
const log = { checks: [], captures: [] };
|
||||
let connection;
|
||||
try {
|
||||
const port = await waitForPort(join(profile, 'DevToolsActivePort'));
|
||||
connection = await connect((await waitForPage(port)).webSocketDebuggerUrl);
|
||||
await connection.send('Page.enable');
|
||||
await connection.send('Emulation.setDeviceMetricsOverride', {
|
||||
width: 390, height: 844, deviceScaleFactor: 1, mobile: true,
|
||||
});
|
||||
const path = () => connection.evaluate('location.pathname');
|
||||
const expectPath = async (expected) => {
|
||||
assert.ok(await waitFor(async () => await path() === expected, 12000),
|
||||
`Expected ${expected}, got ${await path()}`);
|
||||
};
|
||||
const clickRow = async (label) => {
|
||||
const group = (await axNodes(connection)).find(node =>
|
||||
node.role?.value === 'group' && node.name?.value?.startsWith(label));
|
||||
if (!group) return click(connection, label);
|
||||
const { model } = await connection.send('DOM.getBoxModel', {
|
||||
backendNodeId: group.backendDOMNodeId,
|
||||
});
|
||||
const [x1, y1, , , x3, y3] = model.content;
|
||||
await clickAt(connection, (x1 + x3) / 2, (y1 + y3) / 2);
|
||||
};
|
||||
for (const [root, row, detail, server] of [
|
||||
['/pipelines', 'Release verification', '/pipelines/3', pipelineFixture],
|
||||
['/runs', 'Fixture live run', '/runs/1', fixture],
|
||||
['/chat', 'Probe conversation', '/chat/ses_probechat', fixture],
|
||||
]) {
|
||||
if (process.env.PROBE_DESTINATION && root !== process.env.PROBE_DESTINATION) continue;
|
||||
await connection.send('Page.navigate', { url: server.url + root });
|
||||
assert.ok(await waitFor(() => connection.evaluate(
|
||||
"Boolean(document.querySelector('flt-semantics-placeholder'))",
|
||||
), 12000), 'Flutter semantics ready');
|
||||
await enableSemantics(connection);
|
||||
await assertName(connection, row, `${root} list loaded`, log);
|
||||
await capture(connection, output, log, `${root.slice(1)}-list`);
|
||||
await writeFile(join(output, `${root.slice(1)}-ax.json`),
|
||||
JSON.stringify(await axNodes(connection), null, 2));
|
||||
await clickRow(row);
|
||||
await expectPath(detail);
|
||||
await sleep(800);
|
||||
await capture(connection, output, log, `${root.slice(1)}-detail`);
|
||||
|
||||
// Browser history uses the Router; this must remove the pushed detail,
|
||||
// not leave a hidden page which reappears on the next selection.
|
||||
await connection.evaluate('history.back()');
|
||||
await expectPath(root);
|
||||
await assertName(connection, row, `${root} browser Back restores list`, log);
|
||||
await capture(connection, output, log, `${root.slice(1)}-back`);
|
||||
await connection.evaluate('history.forward()');
|
||||
await expectPath(detail);
|
||||
await sleep(800);
|
||||
await click(connection, 'Back');
|
||||
await expectPath(root);
|
||||
await assertName(connection, row, `${root} toolbar Back restores list`, log);
|
||||
await clickRow(row);
|
||||
await expectPath(detail);
|
||||
await sleep(800);
|
||||
await click(connection, 'Back');
|
||||
await expectPath(root);
|
||||
await assertName(connection, row, `${root} repeated open/pop restores list`, log);
|
||||
}
|
||||
console.log(JSON.stringify(log, null, 2));
|
||||
} finally {
|
||||
await writeFile(join(output, 'result.json'), JSON.stringify(log, null, 2));
|
||||
connection?.close();
|
||||
const exited = once(chrome, 'exit');
|
||||
chrome.kill();
|
||||
await exited;
|
||||
await fixture.close();
|
||||
await pipelineFixture.close();
|
||||
}
|
||||
Reference in New Issue
Block a user