Show definition and run warnings in app summaries
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
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/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, {
|
||||
bool cupertino = false,
|
||||
String source = '# stage build',
|
||||
}) {
|
||||
final body = Column(
|
||||
children: [
|
||||
const Text('Pipeline source remains available'),
|
||||
PipelineDefinitionValidation(gateway: gateway, source: source),
|
||||
],
|
||||
);
|
||||
return cupertino
|
||||
? CupertinoApp(
|
||||
home: CupertinoPageScaffold(child: SafeArea(child: body)),
|
||||
)
|
||||
: MaterialApp(home: Scaffold(body: body));
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final cupertino in [false, true]) {
|
||||
testWidgets(
|
||||
'definition warnings stay visible on ${cupertino ? 'Cupertino' : 'Material'}',
|
||||
(tester) async {
|
||||
final gateway = _Gateway()
|
||||
..answer = () async => {
|
||||
'type': 'validated',
|
||||
'warnings': ['Review prompt exceeds 2000 bytes.', '', 42],
|
||||
};
|
||||
await tester.pumpWidget(_host(gateway, cupertino: cupertino));
|
||||
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));
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'run_detail_graph_support.dart';
|
||||
|
||||
void main() {
|
||||
for (final platform in RunDetailTestPlatform.values) {
|
||||
testWidgets(
|
||||
'${platform.name} recorded run warnings are visible and selectable',
|
||||
(tester) async {
|
||||
final run = graphRunFixture()
|
||||
..['warnings'] = [
|
||||
'build visit 1: final result required one repair follow-up.',
|
||||
'',
|
||||
{'not': 'a warning'},
|
||||
];
|
||||
await pumpRunDetail(tester, platform, run: run);
|
||||
expect(find.text('Warnings'), findsOneWidget);
|
||||
expect(
|
||||
find.text(
|
||||
'build visit 1: final result required one repair follow-up.',
|
||||
),
|
||||
findsOneWidget,
|
||||
);
|
||||
expect(find.textContaining('not: a warning'), findsNothing);
|
||||
expect(tester.takeException(), isNull);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'${platform.name} an unwarned run has no empty warnings section',
|
||||
(tester) async {
|
||||
await pumpRunDetail(tester, platform, run: graphRunFixture());
|
||||
expect(find.text('Warnings'), findsNothing);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user