fix(app): refresh visible lists on foreground resume

This commit is contained in:
2026-10-22 23:37:34 +01:00
parent 48eeb5fcbd
commit d0def10490
2 changed files with 85 additions and 4 deletions
@@ -48,6 +48,9 @@ List<String> types(FakeChannel channel) => <String>[
(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(
@@ -100,21 +103,75 @@ void main() {
},
);
testWidgets('foreground resume does not churn a still-connected socket', (
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 does not refresh an open run detail', (
tester,
) async {
final channel = FakeChannel()..readyCompleter.complete();
final provider = routeProvider();
final client = PipelinesClient(channelFactory: (_) => channel);
await pumpApp(tester, provider: provider, client: client);
await replyPipelines(tester, channel, PipelineFixture());
provider.routerReportsNewRouteInformation(
RouteInformation(uri: Uri.parse('/runs/1')),
type: RouteInformationReportingType.navigate,
);
await tester.pump();
final before = countType(channel, 'list_runs');
await resume(tester);
expect(countType(channel, 'list_runs'), before);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pump();
});
}