9551eceaed
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.
292 lines
10 KiB
Dart
292 lines
10 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/application/pipelines_app.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 'pipelines_app_test.dart' show webServer;
|
|
import 'pipelines_replies.dart';
|
|
|
|
Future<void> pumpApp(
|
|
WidgetTester tester, {
|
|
required PlatformRouteInformationProvider provider,
|
|
required PipelinesClient client,
|
|
}) async {
|
|
await tester.pumpWidget(
|
|
PipelinesApp(
|
|
androidSupported: false,
|
|
server: webServer(),
|
|
client: client,
|
|
routeInformationProvider: provider,
|
|
),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
|
|
PlatformRouteInformationProvider routeProvider() {
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/pipelines')),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
return provider;
|
|
}
|
|
|
|
/// The app receives a real return-to-foreground as the engine's lifecycle
|
|
/// transition does: backgrounded, then resumed.
|
|
Future<void> resume(WidgetTester tester) async {
|
|
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.inactive);
|
|
tester.binding.handleAppLifecycleStateChanged(AppLifecycleState.resumed);
|
|
await tester.pump();
|
|
await tester.pump();
|
|
}
|
|
|
|
List<String> types(FakeChannel channel) => <String>[
|
|
for (final frame in channel.outgoing)
|
|
(jsonDecode(frame as String) as Map<String, dynamic>)['type'] as String,
|
|
];
|
|
|
|
int countType(FakeChannel channel, String type) =>
|
|
types(channel).where((value) => value == type).length;
|
|
|
|
void main() {
|
|
tearDown(() {
|
|
WidgetsBinding.instance.handleAppLifecycleStateChanged(
|
|
AppLifecycleState.resumed,
|
|
);
|
|
});
|
|
|
|
test('only a dropped socket is reopened on foreground', () {
|
|
expect(shouldReconnectOnForeground(ConnectionKind.disconnected), isTrue);
|
|
// A deliberate Disconnect reaches idle and must stay disconnected.
|
|
expect(shouldReconnectOnForeground(ConnectionKind.idle), isFalse);
|
|
// These states already have their own answer; foregrounding does not churn
|
|
// a live socket or restart an attempt that is already in flight.
|
|
expect(shouldReconnectOnForeground(ConnectionKind.connected), isFalse);
|
|
expect(shouldReconnectOnForeground(ConnectionKind.connecting), isFalse);
|
|
});
|
|
|
|
testWidgets(
|
|
'foreground resume reopens a dropped socket and re-watches it once',
|
|
(tester) async {
|
|
final first = FakeChannel()..readyCompleter.complete();
|
|
final second = FakeChannel()..readyCompleter.complete();
|
|
var sockets = 0;
|
|
final client = PipelinesClient(
|
|
channelFactory: (_) => sockets++ == 0 ? first : second,
|
|
// Keep the client's own backoff retry far away, so the new socket can
|
|
// only come from the foreground transition under test.
|
|
backoffBase: const Duration(minutes: 1),
|
|
);
|
|
await pumpApp(tester, provider: routeProvider(), client: client);
|
|
await replyPipelines(tester, first, PipelineFixture());
|
|
expect(sockets, 1);
|
|
expect(types(first), contains('subscribe'));
|
|
expect(client.state.kind, ConnectionKind.connected);
|
|
|
|
first.incoming.addError(StateError('network drop'));
|
|
await tester.pump();
|
|
await tester.pump();
|
|
expect(client.state.kind, ConnectionKind.disconnected);
|
|
expect(sockets, 1, reason: 'the backoff retry is still pending');
|
|
|
|
await resume(tester);
|
|
|
|
expect(sockets, 2);
|
|
expect(types(second), contains('subscribe'));
|
|
expect(client.state.kind, ConnectionKind.connected);
|
|
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
},
|
|
);
|
|
|
|
testWidgets('foreground resume refreshes the visible Pipelines list once', (
|
|
tester,
|
|
) async {
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
|
await pumpApp(tester, provider: routeProvider(), client: client);
|
|
await replyPipelines(tester, channel, PipelineFixture());
|
|
final before = countType(channel, 'list_pipelines');
|
|
expect(types(channel).where((type) => type == 'subscribe'), hasLength(1));
|
|
|
|
await resume(tester);
|
|
|
|
expect(countType(channel, 'list_pipelines'), before + 1);
|
|
expect(types(channel).where((type) => type == 'subscribe'), hasLength(1));
|
|
expect(client.state.kind, ConnectionKind.connected);
|
|
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
});
|
|
|
|
testWidgets('foreground resume refreshes the visible Runs list once', (
|
|
tester,
|
|
) async {
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
|
await pumpApp(tester, provider: provider, client: client);
|
|
await waitForRequest(tester, channel, 'list_runs');
|
|
final initialRuns = pipelineRequest(channel, 'list_runs')!;
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': initialRuns['id'],
|
|
'type': 'runs',
|
|
'runs': PipelineFixture().runs,
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
final before = countType(channel, 'list_runs');
|
|
|
|
await resume(tester);
|
|
|
|
expect(countType(channel, 'list_runs'), before + 1);
|
|
expect(countType(channel, 'subscribe'), 1);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
});
|
|
|
|
testWidgets('foreground resume preserves an open dialog and skips refresh', (
|
|
tester,
|
|
) async {
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
|
await pumpApp(tester, provider: provider, client: client);
|
|
await waitForRequest(tester, channel, 'list_runs');
|
|
final initialRuns = pipelineRequest(channel, 'list_runs')!;
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': initialRuns['id'],
|
|
'type': 'runs',
|
|
'runs': PipelineFixture().runs,
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
final before = countType(channel, 'list_runs');
|
|
showDialog<void>(
|
|
context: tester.element(find.byType(Scaffold).first),
|
|
builder: (_) => const AlertDialog(content: Text('Still open')),
|
|
);
|
|
await tester.pump();
|
|
|
|
await resume(tester);
|
|
|
|
expect(countType(channel, 'list_runs'), before);
|
|
expect(find.text('Still open'), findsOneWidget);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
});
|
|
|
|
testWidgets('foreground resume skips refresh while a text field has focus', (
|
|
tester,
|
|
) async {
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
|
await pumpApp(tester, provider: provider, client: client);
|
|
await waitForRequest(tester, channel, 'list_runs');
|
|
final initialRuns = pipelineRequest(channel, 'list_runs')!;
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': initialRuns['id'],
|
|
'type': 'runs',
|
|
'runs': PipelineFixture().runs,
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
final before = countType(channel, 'list_runs');
|
|
showDialog<void>(
|
|
context: tester.element(find.byType(Scaffold).first),
|
|
builder: (_) => const AlertDialog(content: TextField()),
|
|
);
|
|
await tester.pump();
|
|
await tester.tap(find.byType(TextField).last);
|
|
await tester.pump();
|
|
|
|
await resume(tester);
|
|
|
|
expect(countType(channel, 'list_runs'), before);
|
|
expect(FocusManager.instance.primaryFocus?.hasFocus, isTrue);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
});
|
|
|
|
testWidgets(
|
|
'foreground resume refreshes an open run detail without navigation',
|
|
(tester) async {
|
|
final channel = FakeChannel()..readyCompleter.complete();
|
|
final provider = PlatformRouteInformationProvider(
|
|
initialRouteInformation: RouteInformation(uri: Uri.parse('/runs/1')),
|
|
);
|
|
addTearDown(provider.dispose);
|
|
final client = PipelinesClient(channelFactory: (_) => channel);
|
|
await pumpApp(tester, provider: provider, client: client);
|
|
await waitForRequest(tester, channel, 'list_runs');
|
|
final initialList = pipelineRequest(channel, 'list_runs')!;
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': initialList['id'],
|
|
'type': 'runs',
|
|
'runs': [
|
|
{'id': 1, 'title': 'Live run', 'status': 'running'},
|
|
],
|
|
}),
|
|
);
|
|
await waitForRequest(tester, channel, 'get_run');
|
|
final initialDetail = pipelineRequest(channel, 'get_run')!;
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': initialDetail['id'],
|
|
'type': 'run',
|
|
'run_detail': {'id': 1, 'title': 'Live run', 'status': 'running'},
|
|
}),
|
|
);
|
|
await tester.pump();
|
|
final before = countType(channel, 'list_runs');
|
|
|
|
await resume(tester);
|
|
|
|
expect(countType(channel, 'list_runs'), before + 1);
|
|
final refreshedList = await waitForLaterRequest(
|
|
tester,
|
|
channel,
|
|
'list_runs',
|
|
initialList['id'] as String,
|
|
);
|
|
channel.incoming.add(
|
|
jsonEncode({
|
|
'id': refreshedList['id'],
|
|
'type': 'runs',
|
|
'runs': [
|
|
{'id': 1, 'title': 'Live run', 'status': 'succeeded'},
|
|
],
|
|
}),
|
|
);
|
|
final refreshedDetail = await waitForLaterRequest(
|
|
tester,
|
|
channel,
|
|
'get_run',
|
|
initialDetail['id'] as String,
|
|
);
|
|
expect(refreshedDetail['run_id'], 1);
|
|
expect(countType(channel, 'subscribe'), 1);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await tester.pump();
|
|
},
|
|
);
|
|
}
|