9b6809c9a1
Run the full-app fixture entry on an iOS simulator: options from a file in the app's tmp dir or the environment, route via a route provider, a narrow strip for Split View widths, and a small in-app tap/type driver.
75 lines
2.9 KiB
Dart
75 lines
2.9 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:pipelines_app/application/server_endpoint.dart';
|
|
|
|
import 'fixture_steps.dart';
|
|
import 'narrow_view.dart';
|
|
|
|
/// The fixture options on a native build. `simctl launch` passes the child
|
|
/// environment through `SIMCTL_CHILD_FIXTURE_QUERY`, so one installed build
|
|
/// opens any route/option set without rebuilding:
|
|
///
|
|
/// SIMCTL_CHILD_FIXTURE_QUERY='route=/chat/perf-chat-0&chats=3&rich=1' \
|
|
/// xcrun simctl launch SIM net.awan.pipelines.next
|
|
///
|
|
/// Native-only keys: `server=ws://127.0.0.1:PORT/connect` (an artifact
|
|
/// file server; the socket itself stays in-process), `orient=landscape|
|
|
/// portrait`, `width=N` (logical px, draws the app in a left strip of that
|
|
/// width to approximate an iPad Split View pane) and `do=` steps (see
|
|
/// fixture_steps.dart). When the launch environment does not reach the app,
|
|
/// the same query is read from `fixture_query.txt` in the app's temporary
|
|
/// directory (`simctl get_app_container SIM BUNDLE data`/tmp), then from
|
|
/// `--dart-define=FIXTURE_QUERY=...`.
|
|
Map<String, String> fixtureParams() {
|
|
var raw =
|
|
Platform.environment['FIXTURE_QUERY'] ??
|
|
const String.fromEnvironment('FIXTURE_QUERY');
|
|
final file = File('${Directory.systemTemp.path}/fixture_query.txt');
|
|
if (raw.isEmpty && file.existsSync()) raw = file.readAsStringSync().trim();
|
|
return raw.isEmpty ? const {} : Uri.splitQueryString(raw);
|
|
}
|
|
|
|
/// The DevTools probes are browser-only.
|
|
void installHostProbes(Map<String, String> params) {}
|
|
|
|
/// The route goes through [fixtureRouteProvider] instead.
|
|
void openFixtureRoute(String route, {required bool cupertino}) {}
|
|
|
|
/// An explicit loopback endpoint; nothing connects to it but artifact fetches.
|
|
ServerEndpoint fixtureServer(Map<String, String> params) =>
|
|
ServerEndpoint.resolve(
|
|
base: Uri(),
|
|
web: false,
|
|
configured: params['server'] ?? 'ws://127.0.0.1:9/connect',
|
|
);
|
|
|
|
/// Opens [route] as the launch location.
|
|
RouteInformationProvider? fixtureRouteProvider(String? route) =>
|
|
PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(
|
|
uri: Uri.parse(route ?? '/pipelines'),
|
|
),
|
|
);
|
|
|
|
/// Runs [app] with the native capture options applied.
|
|
void runFixtureApp(Widget app, Map<String, String> params) {
|
|
final binding = WidgetsFlutterBinding.ensureInitialized();
|
|
switch (params['orient']) {
|
|
case 'landscape':
|
|
SystemChrome.setPreferredOrientations([
|
|
DeviceOrientation.landscapeLeft,
|
|
DeviceOrientation.landscapeRight,
|
|
]);
|
|
case 'portrait':
|
|
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
|
|
}
|
|
final width = double.tryParse(params['width'] ?? '');
|
|
final view = binding.platformDispatcher.implicitView!;
|
|
runWidget(
|
|
View(view: width == null ? view : NarrowView(view, width), child: app),
|
|
);
|
|
runFixtureSteps(params['do'] ?? '');
|
|
}
|