feat(app): compose live Runs with deep links and reconnect retention
This commit is contained in:
@@ -215,7 +215,7 @@ void main() {
|
||||
var backs = 0;
|
||||
await pumpDetail(tester, platform, controller, onBack: () => backs++);
|
||||
expect(find.textContaining('server unavailable'), findsOneWidget);
|
||||
await tester.tap(find.text('Back to runs'));
|
||||
await tester.tap(find.text('Back to list'));
|
||||
expect(backs, 1);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,247 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/runs/screen.dart';
|
||||
|
||||
class _Gateway implements ApiGateway {
|
||||
final framesController = StreamController<JsonMap>.broadcast();
|
||||
final listRequests = <Completer<JsonMap>>[];
|
||||
final detailRequests = <num, List<Completer<JsonMap>>>{};
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => framesController.stream;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
final request = Completer<JsonMap>();
|
||||
if (type == 'list_runs') {
|
||||
listRequests.add(request);
|
||||
} else if (type == 'get_run') {
|
||||
final id = fields['run_id'] as num;
|
||||
detailRequests.putIfAbsent(id, () => []).add(request);
|
||||
} else {
|
||||
request.completeError(UnsupportedError(type));
|
||||
}
|
||||
return request.future;
|
||||
}
|
||||
|
||||
void replyList(int index, List<JsonMap> runs) =>
|
||||
listRequests[index].complete({'runs': runs});
|
||||
|
||||
void replyDetail(num id, int index, JsonMap detail) =>
|
||||
detailRequests[id]![index].complete({'run_detail': detail});
|
||||
|
||||
void failDetail(num id, int index, Object error) =>
|
||||
detailRequests[id]![index].completeError(error);
|
||||
}
|
||||
|
||||
const _runs = [
|
||||
{'id': 1, 'title': 'Alpha run', 'name': 'alpha', 'status': 'running'},
|
||||
{'id': 2, 'title': 'Beta run', 'name': 'beta', 'status': 'failed'},
|
||||
];
|
||||
|
||||
Widget _materialScreen(
|
||||
_Gateway gateway, {
|
||||
int? initialRunId,
|
||||
int syncToken = 0,
|
||||
ValueChanged<int>? onRunSelected,
|
||||
VoidCallback? onBack,
|
||||
}) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: RunsScreen(
|
||||
gateway: gateway,
|
||||
initialRunId: initialRunId,
|
||||
syncToken: syncToken,
|
||||
onRunSelected: onRunSelected,
|
||||
onBack: onBack,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> _mountList(WidgetTester tester, _Gateway gateway) async {
|
||||
await tester.pump();
|
||||
gateway.replyList(0, _runs);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
}
|
||||
|
||||
void main() {
|
||||
late _Gateway gateway;
|
||||
|
||||
setUp(() => gateway = _Gateway());
|
||||
tearDown(() => gateway.framesController.close());
|
||||
|
||||
testWidgets('initial run opens a pending detail with Back available', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 1));
|
||||
await _mountList(tester, gateway);
|
||||
|
||||
expect(gateway.detailRequests[1], hasLength(1));
|
||||
expect(find.text('Loading run details…'), findsOneWidget);
|
||||
expect(find.text('Back to list'), findsOneWidget);
|
||||
expect(find.text('Alpha run'), findsNothing);
|
||||
|
||||
await tester.tap(find.text('Back to list'));
|
||||
await tester.pump();
|
||||
expect(find.text('Alpha run'), findsOneWidget);
|
||||
expect(find.text('Beta run'), findsOneWidget);
|
||||
|
||||
// A reply that lands after Back must not reopen the previous detail.
|
||||
gateway.replyDetail(1, 0, {'id': 1, 'title': 'Alpha run'});
|
||||
await tester.pump();
|
||||
expect(find.text('Alpha run'), findsOneWidget);
|
||||
expect(find.text('Loading run details…'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('initial run renders its detail after the reply', (tester) async {
|
||||
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 1));
|
||||
await _mountList(tester, gateway);
|
||||
gateway.replyDetail(1, 0, {
|
||||
'id': 1,
|
||||
'title': 'Alpha run',
|
||||
'status': 'succeeded',
|
||||
'input': {'prompt': 'initial prompt'},
|
||||
});
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Alpha run'), findsOneWidget);
|
||||
expect(find.text('initial prompt'), findsOneWidget);
|
||||
expect(find.text('Loading run details…'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('detail failure keeps Back and returns to the list', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 2));
|
||||
await _mountList(tester, gateway);
|
||||
gateway.failDetail(2, 0, StateError('server unavailable'));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.textContaining('server unavailable'), findsOneWidget);
|
||||
expect(find.text('Back to list'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Back to list'));
|
||||
await tester.pump();
|
||||
expect(find.text('Alpha run'), findsOneWidget);
|
||||
expect(find.textContaining('server unavailable'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('selecting a list row is driven by the controller selection', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_materialScreen(gateway));
|
||||
await _mountList(tester, gateway);
|
||||
|
||||
await tester.tap(find.text('Beta run'));
|
||||
await tester.pump();
|
||||
expect(gateway.detailRequests[2], hasLength(1));
|
||||
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
|
||||
await tester.pump();
|
||||
expect(find.text('Beta run'), findsOneWidget);
|
||||
expect(find.text('Back to list'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('selection and Back report route changes to the host', (
|
||||
tester,
|
||||
) async {
|
||||
int? selected;
|
||||
var backs = 0;
|
||||
await tester.pumpWidget(
|
||||
_materialScreen(
|
||||
gateway,
|
||||
onRunSelected: (id) => selected = id,
|
||||
onBack: () => backs++,
|
||||
),
|
||||
);
|
||||
await _mountList(tester, gateway);
|
||||
|
||||
await tester.tap(find.text('Beta run'));
|
||||
await tester.pump();
|
||||
expect(selected, 2);
|
||||
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
|
||||
await tester.pump();
|
||||
|
||||
await tester.tap(find.text('Back to list'));
|
||||
await tester.pump();
|
||||
expect(backs, 1);
|
||||
expect(find.text('Alpha run'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a route change opens and closes the named run', (tester) async {
|
||||
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 2));
|
||||
await _mountList(tester, gateway);
|
||||
expect(gateway.detailRequests[2], hasLength(1));
|
||||
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
|
||||
await tester.pump();
|
||||
expect(find.text('Beta run'), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 1));
|
||||
await tester.pump();
|
||||
expect(gateway.detailRequests[1], hasLength(1));
|
||||
gateway.replyDetail(1, 0, {'id': 1, 'title': 'Alpha run'});
|
||||
await tester.pump();
|
||||
expect(find.text('Alpha run'), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(_materialScreen(gateway));
|
||||
await tester.pump();
|
||||
expect(find.text('Alpha run'), findsOneWidget);
|
||||
expect(find.text('Beta run'), findsOneWidget);
|
||||
expect(find.text('Back to list'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('a reconnect token refreshes the open detail in place', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(_materialScreen(gateway, initialRunId: 2));
|
||||
await _mountList(tester, gateway);
|
||||
gateway.replyDetail(2, 0, {'id': 2, 'title': 'Beta run'});
|
||||
await tester.pump();
|
||||
expect(find.text('Beta run'), findsOneWidget);
|
||||
|
||||
await tester.pumpWidget(
|
||||
_materialScreen(gateway, initialRunId: 2, syncToken: 1),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(gateway.listRequests, hasLength(2));
|
||||
gateway.replyList(1, _runs);
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
expect(gateway.detailRequests[2], hasLength(2));
|
||||
gateway.replyDetail(2, 1, {
|
||||
'id': 2,
|
||||
'title': 'Beta run',
|
||||
'status': 'succeeded',
|
||||
});
|
||||
await tester.pump();
|
||||
expect(find.text('Beta run'), findsOneWidget);
|
||||
expect(find.text('Back to list'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Cupertino host keeps exactly one navigation bar while pending',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
CupertinoApp(
|
||||
home: CupertinoPageScaffold(
|
||||
navigationBar: const CupertinoNavigationBar(middle: Text('Runs')),
|
||||
child: SafeArea(
|
||||
child: RunsScreen(gateway: gateway, initialRunId: 1),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await _mountList(tester, gateway);
|
||||
|
||||
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
|
||||
expect(find.byType(CupertinoNavigationBar), findsOneWidget);
|
||||
expect(find.text('Loading run details…'), findsOneWidget);
|
||||
expect(find.byType(CupertinoActivityIndicator), findsOneWidget);
|
||||
expect(find.text('Back to list'), findsOneWidget);
|
||||
},
|
||||
variant: TargetPlatformVariant.only(TargetPlatform.iOS),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user