Files
pipelines/app/test/application/startup_update_flow_test.dart
alan 9551eceaed Complete Material-only APIs and fixtures
Remove obsolete control-family flags and icon metadata across all callers, dead alternate themes and host helpers, obsolete test setup, and the unused icon-font dependency. Preserve native Material Back transitions. Make navigation fixtures independent of update plugins and answer auxiliary shell snapshots so the complete application suite can run deterministically.
2026-11-11 21:55:39 +00:00

260 lines
8.7 KiB
Dart

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/application/pipelines_app.dart';
import 'package:pipelines_app/application/server_endpoint.dart';
import 'package:pipelines_app/core/transport/pipelines_client.dart';
import 'package:pipelines_app/features/updates/app_updates.dart';
import 'package:pipelines_app/features/updates/launch_update.dart';
import '../core/transport/pipelines_client_test.dart' show FakeChannel;
void main() {
Future<void> mount(
WidgetTester tester, {
bool web = true,
Future<String?> Function(Uri)? read,
Future<void> Function()? refresh,
UpdateInstaller? installer,
}) async {
final channel = FakeChannel()..readyCompleter.complete();
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
);
addTearDown(provider.dispose);
await tester.pumpWidget(
PipelinesApp(
server: ServerEndpoint.resolve(
base: Uri.parse('https://rpc.test/'),
web: true,
),
client: PipelinesClient(channelFactory: (_) => channel),
routeInformationProvider: provider,
webPlatform: web,
webPageUri: Uri.parse('https://app.test/chats?selected=1'),
webBuildId: 'web-old',
androidSupported: true,
webReleaseReader:
read ??
(_) async => '{"schema":1,"platform":"web","buildId":"web-new"}',
webRefresher: refresh ?? () async {},
installedVersionReader: () async => 3,
androidFeedReader: (_) async => AppUpdate(
versionCode: 4,
versionName: '4',
apk: Uri.parse('https://rpc.test/updates/pipelines.apk'),
),
androidInstaller: installer ?? (_, {onProgress}) async {},
),
);
await tester.pump();
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
}
Future<void> resume(WidgetTester tester) async {
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.paused);
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
}
testWidgets('Android checks after a saved endpoint becomes available', (
tester,
) async {
final channel = FakeChannel()..readyCompleter.complete();
final client = PipelinesClient(channelFactory: (_) => channel);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
);
addTearDown(provider.dispose);
var reads = 0;
await tester.pumpWidget(
PipelinesApp(
server: ServerEndpoint.resolve(base: Uri(), web: false),
client: client,
routeInformationProvider: provider,
webPlatform: false,
androidSupported: true,
installedVersionReader: () async => 3,
androidFeedReader: (uri) async {
reads++;
expect(uri, Uri.parse('https://restored.test/updates/'));
return AppUpdate(
versionCode: 4,
versionName: '4',
apk: uri.resolve('pipelines.apk'),
);
},
),
);
await tester.pump();
expect(reads, 0);
await client.connect(Uri.parse('wss://restored.test/connect'));
await tester.pump();
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(reads, 1);
expect(find.text('Download'), findsOneWidget);
await tester.tap(find.text('Later'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
});
testWidgets(
'changing servers during Android check never offers the stale APK',
(tester) async {
final client = PipelinesClient(
channelFactory: (_) => FakeChannel()..readyCompleter.complete(),
);
final provider = PlatformRouteInformationProvider(
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
);
addTearDown(provider.dispose);
final stale = Completer<AppUpdate>();
final requested = <Uri>[];
Uri? installed;
await tester.pumpWidget(
PipelinesApp(
server: ServerEndpoint.resolve(
base: Uri.parse('https://original.test/'),
web: true,
),
client: client,
routeInformationProvider: provider,
webPlatform: false,
androidSupported: true,
installedVersionReader: () async => 3,
androidFeedReader: (uri) async {
requested.add(uri);
if (uri.host == 'original.test') return stale.future;
return AppUpdate(
versionCode: 5,
versionName: '5',
apk: uri.resolve('new.apk'),
);
},
androidInstaller: (update, {onProgress}) async {
installed = update.apk;
},
),
);
await tester.pump();
await tester.pump();
expect(requested, [Uri.parse('https://original.test/updates/')]);
unawaited(client.connect(Uri.parse('wss://selected.test/connect')));
await tester.pump();
await tester.pump();
stale.complete(
AppUpdate(
versionCode: 4,
versionName: '4',
apk: Uri.parse('https://original.test/old.apk'),
),
);
await tester.pump();
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(requested, [
Uri.parse('https://original.test/updates/'),
Uri.parse('https://selected.test/updates/'),
]);
expect(find.text('Download'), findsOneWidget);
await tester.tap(find.text('Download'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(installed, Uri.parse('https://selected.test/updates/new.apk'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
},
);
testWidgets('web refresh requires consent and uses same page origin', (
tester,
) async {
var refreshes = 0;
await mount(
tester,
read: (uri) async {
expect(uri, Uri.parse('https://app.test/release.json'));
return '{"schema":1,"platform":"web","buildId":"web-new"}';
},
refresh: () async {
refreshes++;
},
);
expect(find.byType(AlertDialog), findsOneWidget);
expect(refreshes, 0);
await tester.tap(find.text('Refresh'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(refreshes, 1);
await tester.pump(const Duration(milliseconds: 400));
expect(find.text('Update available'), findsNothing);
});
testWidgets(
'offline startup is quiet, resume retries and later dismisses that release',
(tester) async {
var reads = 0;
await mount(
tester,
read: (_) async {
reads++;
if (reads == 1) throw StateError('offline');
return '{"schema":1,"platform":"web","buildId":"web-new"}';
},
);
expect(find.text('Update available'), findsNothing);
expect(tester.takeException(), isNull);
await resume(tester);
expect(reads, 2);
expect(find.text('Update available'), findsOneWidget);
await tester.tap(find.text('Later'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await resume(tester);
expect(reads, 3);
expect(find.text('Update available'), findsNothing);
},
);
testWidgets(
'Android download shows progress, reports failure and leaves app usable',
(tester) async {
final finish = Completer<void>();
void Function(double)? progress;
var installs = 0;
await mount(
tester,
web: false,
installer: (_, {onProgress}) async {
installs++;
progress = onProgress;
await finish.future;
},
);
expect(installs, 0);
await tester.tap(find.text('Download'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(installs, 1);
progress!(0.5);
await tester.pump();
expect(find.text('Downloading update… 50%'), findsOneWidget);
finish.completeError(StateError('download failed'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
await tester.pump();
expect(find.text('Update failed'), findsOneWidget);
expect(find.textContaining('download failed'), findsOneWidget);
await tester.tap(find.text('OK'));
await tester.pump();
await tester.pump(const Duration(milliseconds: 400));
expect(find.text('Update failed'), findsNothing);
expect(tester.takeException(), isNull);
},
);
}