364fd5b538
Keep the Material-only run action behavior while preserving public Cupertino parameters for callers that will be cleaned up separately. Narrow the related tests to the supported Material path.
155 lines
5.2 KiB
Dart
155 lines
5.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'run_detail_finders.dart';
|
|
import 'package:pipelines_app/features/runs/ui/run_more_menu.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, {
|
|
int initialRunId = 1,
|
|
}) async {
|
|
final gateway = _Gateway();
|
|
final screen = RunsScreen(gateway: gateway, initialRunId: initialRunId);
|
|
await tester.pumpWidget(MaterialApp(home: Scaffold(body: screen)));
|
|
await tester.pumpAndSettle();
|
|
return gateway;
|
|
}
|
|
|
|
String _fieldText(WidgetTester tester) =>
|
|
tester.widget<TextField>(find.byKey(runTitleFieldKey)).controller!.text;
|
|
|
|
/// Rename lives in the run detail's more menu.
|
|
Future<void> _openRename(WidgetTester tester) async {
|
|
await tester.tap(find.byKey(runMoreMenuKey));
|
|
await tester.pumpAndSettle();
|
|
await tester.tap(find.text(runTitleActionLabel).last);
|
|
await tester.pumpAndSettle();
|
|
}
|
|
|
|
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);
|
|
|
|
expect(runDetailText('Nightly build'), findsOneWidget);
|
|
expect(find.byKey(runMoreMenuKey), findsOneWidget);
|
|
expect(gateway.saves, isEmpty);
|
|
|
|
await _openRename(tester);
|
|
expect(find.byType(AlertDialog), findsOneWidget);
|
|
expect(_fieldText(tester), '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(runDetailText('Nightly build'), findsOneWidget);
|
|
|
|
await _openRename(tester);
|
|
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(runDetailText('Nightly build'), findsOneWidget);
|
|
expect(find.text('Release build'), findsNothing);
|
|
|
|
gateway.accept('Release build');
|
|
await tester.pumpAndSettle();
|
|
expect(find.byType(AlertDialog), findsNothing);
|
|
expect(runDetailText('Release build'), findsOneWidget);
|
|
expect(find.text('Nightly build'), findsNothing);
|
|
|
|
// The list stays visible, and its row follows the accepted rename too.
|
|
expect(
|
|
find.descendant(
|
|
of: find.byKey(const ValueKey('run-row-1')),
|
|
matching: find.text('Release build'),
|
|
),
|
|
findsOneWidget,
|
|
);
|
|
});
|
|
|
|
testWidgets('a refused rename keeps the typed title and the stored detail', (
|
|
tester,
|
|
) async {
|
|
final gateway = await _mount(tester);
|
|
|
|
await _openRename(tester);
|
|
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), ' locked ');
|
|
expect(find.byType(AlertDialog), findsOneWidget);
|
|
expect(runDetailText('Nightly build'), findsOneWidget);
|
|
});
|
|
}
|