Files
pipelines/app/test/features/pipelines/pipeline_definition_warnings_test.dart
T
alan d1b05217c9 Remove Cupertino pipeline branches
Keep the pipeline feature on its existing Material path because the app runs under MaterialApp and never selects Cupertino hosts. Preserve public cupertino parameters and required Cupertino icon values for later cleanup and shared controls.
2026-11-11 04:53:12 +00:00

116 lines
4.1 KiB
Dart

import 'dart:async';
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/pipelines/widgets/pipeline_definition_validation.dart';
class _Gateway implements ApiGateway {
final calls = <JsonMap>[];
Future<JsonMap> Function() answer = () async => {'type': 'validated'};
@override
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
expect(type, 'validate');
calls.add(fields);
return answer();
}
@override
Stream<JsonMap> get frames => const Stream.empty();
}
Widget _host(_Gateway gateway, {String source = '# stage build'}) {
final body = Column(
children: [
const Text('Pipeline source remains available'),
PipelineDefinitionValidation(gateway: gateway, source: source),
],
);
return MaterialApp(home: Scaffold(body: body));
}
void main() {
testWidgets('definition warnings stay visible', (tester) async {
final gateway = _Gateway()
..answer = () async => {
'type': 'validated',
'warnings': ['Review prompt exceeds 2000 bytes.', '', 42],
};
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.text('Definition warnings'), findsOneWidget);
expect(find.text('Review prompt exceeds 2000 bytes.'), findsOneWidget);
expect(find.text('42'), findsNothing);
expect(gateway.calls.single, {'source': '# stage build'});
expect(tester.takeException(), isNull);
});
testWidgets(
'loading validation never hides detail and a source is checked once',
(tester) async {
final response = Completer<JsonMap>();
final gateway = _Gateway()..answer = () => response.future;
await tester.pumpWidget(_host(gateway));
expect(find.text('Pipeline source remains available'), findsOneWidget);
expect(find.text('Checking definition…'), findsOneWidget);
response.complete({'type': 'validated'});
await tester.pumpAndSettle();
expect(find.text('Definition warnings'), findsNothing);
await tester.pumpWidget(const SizedBox.shrink());
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(gateway.calls, hasLength(1));
await tester.pumpWidget(_host(gateway, source: '# stage newer'));
await tester.pumpAndSettle();
expect(gateway.calls, hasLength(2));
},
);
testWidgets(
'historical validation errors keep both errors and warnings visible',
(tester) async {
final gateway = _Gateway()
..answer = () async => {
'type': 'error',
'error': 'stage build requires checks',
'warnings': ['Review repeats runner instructions.'],
};
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.text('Pipeline source remains available'), findsOneWidget);
expect(find.text('stage build requires checks'), findsOneWidget);
expect(find.text('Review repeats runner instructions.'), findsOneWidget);
},
);
testWidgets('missing recorded source sends no validation request', (
tester,
) async {
final gateway = _Gateway();
await tester.pumpWidget(_host(gateway, source: ' '));
await tester.pumpAndSettle();
expect(gateway.calls, isEmpty);
expect(find.text('Checking definition…'), findsNothing);
});
testWidgets('transport failure is visible and can be retried', (
tester,
) async {
final gateway = _Gateway()
..answer = () async => throw StateError('offline');
await tester.pumpWidget(_host(gateway));
await tester.pumpAndSettle();
expect(find.textContaining('Could not check definition:'), findsOneWidget);
gateway.answer = () async => {
'type': 'validated',
'warnings': ['Use a bounded review loop.'],
};
await tester.tap(find.text('Retry validation'));
await tester.pumpAndSettle();
expect(find.text('Use a bounded review loop.'), findsOneWidget);
expect(find.text('Retry validation'), findsNothing);
expect(gateway.calls, hasLength(2));
});
}