Files
pipelines/app/test/features/runs/actions/title_action_test.dart
T
alan 364fd5b538 Remove Cupertino run action branches
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.
2026-11-11 04:18:26 +00:00

185 lines
5.9 KiB
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_action.dart';
import 'package:pipelines_app/features/runs/actions/title_wording.dart';
import 'title_test_support.dart';
String _materialFieldText(WidgetTester tester) =>
tester.widget<TextField>(find.byKey(runTitleFieldKey)).controller!.text;
void main() {
testWidgets(
'material rename starts from the stored title, typing sends nothing, '
'Cancel sends nothing and Save sends the exact text',
(tester) async {
final accepted = renamedRun(title: 'Release build');
final gateway = FakeTitleGateway(
(type, fields) async => {'run_detail': accepted},
);
final changed = <JsonMap>[];
await tester.pumpWidget(
titleApp(
TitleHost(gateway: gateway, initial: titledRun(), changed: changed),
),
);
expect(find.byKey(runTitleActionKey), findsOneWidget);
expect(find.byType(OutlinedButton), findsOneWidget);
expect(gateway.calls, isEmpty);
await tester.tap(find.byKey(runTitleActionKey));
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsOneWidget);
expect(find.text(runTitleDialogTitle), findsWidgets);
expect(find.text(runTitleFieldLabel), findsOneWidget);
expect(_materialFieldText(tester), 'Nightly build');
await tester.enterText(
find.byKey(runTitleFieldKey),
' 发布 🚀 — nightly ',
);
await tester.pump();
expect(gateway.calls, isEmpty);
await tester.tap(find.byKey(runTitleCancelKey));
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsNothing);
expect(gateway.calls, isEmpty);
expect(changed, isEmpty);
expect(
tester.widget<Text>(find.byKey(titleHostTitleKey)).data,
'Nightly build',
);
await tester.tap(find.byKey(runTitleActionKey));
await tester.pumpAndSettle();
expect(_materialFieldText(tester), 'Nightly build');
await tester.enterText(
find.byKey(runTitleFieldKey),
' 发布 🚀 — nightly ',
);
await tester.tap(find.byKey(runTitleSaveKey));
await tester.pumpAndSettle();
expect(gateway.calls.map((call) => call.type), ['set_run_title']);
expect(gateway.calls.single.fields, {
'run_id': 7,
'title': ' 发布 🚀 — nightly ',
});
expect(changed.single, equals(accepted));
expect(find.byType(AlertDialog), findsNothing);
expect(
tester.widget<Text>(find.byKey(titleHostTitleKey)).data,
'Release build',
);
},
);
testWidgets('a blank title is sent exactly and the server refusal is shown', (
tester,
) async {
const refusal = 'title must not be blank';
final gateway = FakeTitleGateway(
(type, fields) async => throw const ProtocolError(refusal),
);
final changed = <JsonMap>[];
await tester.pumpWidget(
titleApp(
TitleHost(gateway: gateway, initial: titledRun(), changed: changed),
),
);
await tester.tap(find.byKey(runTitleActionKey));
await tester.pumpAndSettle();
await tester.enterText(find.byKey(runTitleFieldKey), '');
await tester.tap(find.byKey(runTitleSaveKey));
await tester.pumpAndSettle();
expect(gateway.calls.single.fields, {'run_id': 7, 'title': ''});
expect(find.text(refusal), findsOneWidget);
expect(find.byKey(runTitleErrorKey), findsOneWidget);
expect(_materialFieldText(tester), '');
expect(find.byType(AlertDialog), findsOneWidget);
expect(changed, isEmpty);
expect(
tester.widget<Text>(find.byKey(titleHostTitleKey)).data,
'Nightly build',
);
expect(
tester.widget<FilledButton>(find.byKey(runTitleSaveKey)).onPressed,
isNotNull,
);
});
testWidgets('the prompt is seeded from the stored title, never the prompt', (
tester,
) async {
final gateway = FakeTitleGateway(
(type, fields) async => {'run_detail': titledRun()},
);
final changed = <JsonMap>[];
await tester.pumpWidget(
titleApp(
TitleHost(
gateway: gateway,
initial: titledRun(
title: 'Stored title',
prompt: 'prompt fallback must not appear',
),
changed: changed,
),
),
);
await tester.tap(find.byKey(runTitleActionKey));
await tester.pumpAndSettle();
expect(_materialFieldText(tester), 'Stored title');
expect(find.text('prompt fallback must not appear'), findsNothing);
await tester.tap(find.byKey(runTitleCancelKey));
await tester.pumpAndSettle();
await tester.pumpWidget(
titleApp(
TitleHost(
gateway: gateway,
initial: titledRun(title: null, prompt: 'prompt is not a title'),
changed: changed,
),
),
);
await tester.tap(find.byKey(runTitleActionKey));
await tester.pumpAndSettle();
expect(_materialFieldText(tester), '');
expect(find.text('prompt is not a title'), findsNothing);
await tester.tap(find.byKey(runTitleCancelKey));
await tester.pumpAndSettle();
expect(gateway.calls, isEmpty);
expect(changed, isEmpty);
});
testWidgets('a malformed run has no rename entry point', (tester) async {
final gateway = FakeTitleGateway(
(type, fields) async => {'run_detail': titledRun()},
);
await tester.pumpWidget(
titleApp(
TitleHost(
gateway: gateway,
initial: {'title': 'No id'},
changed: <JsonMap>[],
),
),
);
expect(find.byKey(runTitleActionKey), findsNothing);
expect(gateway.calls, isEmpty);
expect(runTitleId({'title': 'No id'}), isNull);
expect(storedRunTitle({'title': 'Kept'}), 'Kept');
expect(storedRunTitle({}), '');
});
}