merge(app): expose native run rename in live details
This commit is contained in:
@@ -75,7 +75,8 @@ JsonMap usageFixture({int known = 1}) => {
|
||||
Future<void> pumpDetail(
|
||||
WidgetTester tester,
|
||||
AppPlatform platform,
|
||||
RunsController controller, {
|
||||
RunsController controller,
|
||||
FakeGateway gateway, {
|
||||
VoidCallback? onBack,
|
||||
bool settle = true,
|
||||
}) async {
|
||||
@@ -83,7 +84,11 @@ Future<void> pumpDetail(
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.resetPhysicalSize);
|
||||
addTearDown(tester.view.resetDevicePixelRatio);
|
||||
final view = RunDetailView(controller: controller, onBack: onBack ?? () {});
|
||||
final view = RunDetailView(
|
||||
controller: controller,
|
||||
gateway: gateway,
|
||||
onBack: onBack ?? () {},
|
||||
);
|
||||
final page = MediaQuery(
|
||||
data: MediaQueryData.fromView(
|
||||
tester.view,
|
||||
@@ -142,7 +147,7 @@ void main() {
|
||||
testWidgets('${platform.name} detail at 390 with 2x text', (tester) async {
|
||||
gateway.detail = runFixture(steps: 12);
|
||||
await controller.select(1);
|
||||
await pumpDetail(tester, platform, controller);
|
||||
await pumpDetail(tester, platform, controller, gateway);
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Nightly build'), findsOneWidget);
|
||||
expect(find.textContaining('Original prompt'), findsOneWidget);
|
||||
@@ -192,7 +197,7 @@ void main() {
|
||||
) async {
|
||||
gateway.hold = Completer<JsonMap>();
|
||||
final pending = controller.select(1);
|
||||
await pumpDetail(tester, platform, controller, settle: false);
|
||||
await pumpDetail(tester, platform, controller, gateway, settle: false);
|
||||
expect(find.text('Loading run details…'), findsOneWidget);
|
||||
expect(
|
||||
find.byType(
|
||||
@@ -213,7 +218,13 @@ void main() {
|
||||
controller = RunsController(RunsRepository(gateway));
|
||||
await controller.select(1);
|
||||
var backs = 0;
|
||||
await pumpDetail(tester, platform, controller, onBack: () => backs++);
|
||||
await pumpDetail(
|
||||
tester,
|
||||
platform,
|
||||
controller,
|
||||
gateway,
|
||||
onBack: () => backs++,
|
||||
);
|
||||
expect(find.textContaining('server unavailable'), findsOneWidget);
|
||||
await tester.tap(find.text('Back to list'));
|
||||
expect(backs, 1);
|
||||
@@ -229,7 +240,7 @@ void main() {
|
||||
? find.byTooltip('Copy prompt')
|
||||
: find.text('Copy prompt');
|
||||
await controller.select(1);
|
||||
await pumpDetail(tester, platform, controller);
|
||||
await pumpDetail(tester, platform, controller, gateway);
|
||||
await tester.tap(copy);
|
||||
await tester.pumpAndSettle();
|
||||
expect(copied.single, prompt);
|
||||
@@ -248,7 +259,7 @@ void main() {
|
||||
testWidgets('reported zero and missing usage stay distinct', (tester) async {
|
||||
gateway.detail = runFixture(usage: usageFixture());
|
||||
await controller.select(1);
|
||||
await pumpDetail(tester, AppPlatform.material, controller);
|
||||
await pumpDetail(tester, AppPlatform.material, controller, gateway);
|
||||
await tester.tap(find.text('Metrics'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Unavailable'), findsNothing);
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
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/core/transport/connection_state.dart';
|
||||
import 'package:pipelines_app/features/runs/actions/title_wording.dart';
|
||||
import 'package:pipelines_app/features/runs/screen.dart';
|
||||
|
||||
JsonMap _run(int id, String title) => {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'name': 'fixture',
|
||||
'status': 'running',
|
||||
};
|
||||
|
||||
JsonMap _detail(int id, String title) => {
|
||||
..._run(id, title),
|
||||
'input': {'prompt': 'the stored prompt'},
|
||||
'steps': const [],
|
||||
};
|
||||
|
||||
/// Records the exact rename request and answers only when the test releases it,
|
||||
/// so an optimistic title would be visible before the server reply.
|
||||
class _Gateway implements ApiGateway {
|
||||
final framesController = StreamController<JsonMap>.broadcast();
|
||||
final saves = <({JsonMap fields, Completer<JsonMap> reply})>[];
|
||||
final titles = {1: 'Nightly build', 2: 'Other run'};
|
||||
|
||||
@override
|
||||
Stream<JsonMap> get frames => framesController.stream;
|
||||
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
switch (type) {
|
||||
case 'list_runs':
|
||||
return Future.value({
|
||||
'runs': [
|
||||
for (final entry in titles.entries) _run(entry.key, entry.value),
|
||||
],
|
||||
});
|
||||
case 'get_run':
|
||||
final id = (fields['run_id'] as num).toInt();
|
||||
return Future.value({'run_detail': _detail(id, titles[id]!)});
|
||||
case 'set_run_title':
|
||||
final reply = Completer<JsonMap>();
|
||||
saves.add((fields: Map<String, dynamic>.from(fields), reply: reply));
|
||||
return reply.future;
|
||||
}
|
||||
return Future.error(UnsupportedError(type));
|
||||
}
|
||||
|
||||
void accept(String title) {
|
||||
final save = saves.removeAt(0);
|
||||
final id = (save.fields['run_id'] as num).toInt();
|
||||
titles[id] = title;
|
||||
save.reply.complete({'run_detail': _detail(id, title)});
|
||||
}
|
||||
|
||||
void refuse(Object error) => saves.removeAt(0).reply.completeError(error);
|
||||
}
|
||||
|
||||
Future<_Gateway> _mount(
|
||||
WidgetTester tester, {
|
||||
required bool cupertino,
|
||||
int initialRunId = 1,
|
||||
}) async {
|
||||
final gateway = _Gateway();
|
||||
final screen = RunsScreen(gateway: gateway, initialRunId: initialRunId);
|
||||
await tester.pumpWidget(
|
||||
cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: screen)),
|
||||
)
|
||||
: MaterialApp(home: Scaffold(body: screen)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
return gateway;
|
||||
}
|
||||
|
||||
String _fieldText(WidgetTester tester, {required bool cupertino}) => cupertino
|
||||
? tester
|
||||
.widget<CupertinoTextField>(find.byKey(runTitleFieldKey))
|
||||
.controller!
|
||||
.text
|
||||
: tester.widget<TextField>(find.byKey(runTitleFieldKey)).controller!.text;
|
||||
|
||||
void main() {
|
||||
testWidgets('material detail renames through the shared gateway and folds '
|
||||
'only the server reply into the detail and list', (tester) async {
|
||||
final gateway = await _mount(tester, cupertino: false);
|
||||
|
||||
expect(find.text('Nightly build'), findsOneWidget);
|
||||
expect(find.byKey(runTitleActionKey), findsOneWidget);
|
||||
expect(find.byType(OutlinedButton), findsOneWidget);
|
||||
expect(gateway.saves, isEmpty);
|
||||
|
||||
await tester.tap(find.byKey(runTitleActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(_fieldText(tester, cupertino: false), 'Nightly build');
|
||||
|
||||
await tester.enterText(find.byKey(runTitleFieldKey), 'Draft only');
|
||||
await tester.pump();
|
||||
expect(gateway.saves, isEmpty);
|
||||
await tester.tap(find.byKey(runTitleCancelKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(gateway.saves, isEmpty);
|
||||
expect(find.text('Nightly build'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(runTitleActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byKey(runTitleFieldKey), ' Release build ');
|
||||
await tester.tap(find.byKey(runTitleSaveKey));
|
||||
await tester.pump();
|
||||
|
||||
expect(gateway.saves.single.fields, {
|
||||
'run_id': 1,
|
||||
'title': ' Release build ',
|
||||
});
|
||||
// Still the stored title: nothing is applied before the server replies.
|
||||
expect(find.text('Nightly build'), findsOneWidget);
|
||||
expect(find.text('Release build'), findsNothing);
|
||||
|
||||
gateway.accept('Release build');
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
expect(find.text('Release build'), findsOneWidget);
|
||||
expect(find.text('Nightly build'), findsNothing);
|
||||
|
||||
await tester.tap(find.text('Back to list'));
|
||||
await tester.pump();
|
||||
expect(find.text('Release build'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('cupertino detail shows the native rename entry point', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _mount(tester, cupertino: true);
|
||||
|
||||
expect(find.byKey(runTitleActionKey), findsOneWidget);
|
||||
expect(find.byType(OutlinedButton), findsNothing);
|
||||
|
||||
await tester.tap(find.byKey(runTitleActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.byType(CupertinoAlertDialog), findsOneWidget);
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
|
||||
await tester.enterText(find.byKey(runTitleFieldKey), 'Release build');
|
||||
await tester.tap(find.byKey(runTitleSaveKey));
|
||||
await tester.pump();
|
||||
expect(gateway.saves.single.fields, {
|
||||
'run_id': 1,
|
||||
'title': 'Release build',
|
||||
});
|
||||
gateway.accept('Release build');
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.byType(CupertinoAlertDialog), findsNothing);
|
||||
expect(find.text('Release build'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('a refused rename keeps the typed title and the stored detail', (
|
||||
tester,
|
||||
) async {
|
||||
final gateway = await _mount(tester, cupertino: false);
|
||||
|
||||
await tester.tap(find.byKey(runTitleActionKey));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.enterText(find.byKey(runTitleFieldKey), ' locked ');
|
||||
await tester.tap(find.byKey(runTitleSaveKey));
|
||||
await tester.pump();
|
||||
gateway.refuse(const ProtocolError('rename refused by the server'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('rename refused by the server'), findsOneWidget);
|
||||
expect(_fieldText(tester, cupertino: false), ' locked ');
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
expect(find.text('Nightly build'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -341,4 +341,43 @@ void main() {
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
expect(controller.detail?['id'], 1);
|
||||
});
|
||||
|
||||
test(
|
||||
'an accepted rename folds into the selected detail and its list row',
|
||||
() async {
|
||||
final load = controller.load();
|
||||
gateway.listReply(0, [
|
||||
{'id': 1, 'title': 'Old title', 'status': 'running', 'name': 'one'},
|
||||
{'id': 2, 'title': 'Other run', 'status': 'running'},
|
||||
]);
|
||||
await load;
|
||||
|
||||
final first = controller.select(1);
|
||||
gateway.detailReply(1, 0, {
|
||||
'id': 1,
|
||||
'title': 'Old title',
|
||||
'input': {'prompt': 'stored'},
|
||||
});
|
||||
await first;
|
||||
|
||||
controller.acceptRunDetail({
|
||||
'id': 1,
|
||||
'title': 'Renamed',
|
||||
'status': 'succeeded',
|
||||
});
|
||||
expect(controller.detail?['title'], 'Renamed');
|
||||
expect(controller.runs.first['title'], 'Renamed');
|
||||
expect(controller.runs.first['name'], 'one');
|
||||
expect(controller.runs[1]['title'], 'Other run');
|
||||
|
||||
final second = controller.select(2);
|
||||
gateway.detailReply(2, 0, {'id': 2, 'title': 'Other run'});
|
||||
await second;
|
||||
|
||||
controller.acceptRunDetail({'id': 1, 'title': 'Late rename'});
|
||||
expect(controller.detail?['id'], 2);
|
||||
expect(controller.detail?['title'], 'Other run');
|
||||
expect(controller.runs.first['title'], 'Late rename');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user