1db273894c
Keep the Material-only template implementation and narrow its tests to the runtime path. Retain public Cupertino parameters for compatibility while removing unreachable hosts, widgets, and test variants.
109 lines
3.6 KiB
Dart
109 lines
3.6 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/core/transport/connection_state.dart';
|
|
import 'package:pipelines_app/features/templates/ui/template_create_wording.dart';
|
|
|
|
import 'template_create_test_support.dart';
|
|
|
|
void main() {
|
|
testWidgets('a submit refusal keeps the prompt and the typed name', (
|
|
tester,
|
|
) async {
|
|
const refusal = 'a pipeline named "Release" already exists';
|
|
final gateway = FakeTemplateCreateGateway((type, fields) async {
|
|
if (type == 'validate') return {'graph': {}};
|
|
throw const ProtocolError(refusal);
|
|
});
|
|
final created = <JsonMap>[];
|
|
await tester.pumpWidget(
|
|
templateCreateApp(
|
|
TemplateCreateHost(gateway: gateway, onCreated: created.add),
|
|
),
|
|
);
|
|
|
|
await tester.tap(find.byKey(templateCreateOpenKey));
|
|
await tester.pumpAndSettle();
|
|
await tester.enterText(find.byKey(templateCreateNameKey), 'Release');
|
|
await tester.pump();
|
|
await tester.tap(find.byKey(templateCreateConfirmKey));
|
|
await tester.pumpAndSettle();
|
|
|
|
expect(gateway.calls.map((call) => call.type), ['validate', 'submit']);
|
|
expect(find.text(refusal), findsOneWidget);
|
|
expect(materialTemplateName(tester), 'Release');
|
|
expect(created, isEmpty);
|
|
expect(find.byType(AlertDialog), findsOneWidget);
|
|
expect(find.text('Cancel'), findsOneWidget);
|
|
expect(
|
|
tester.widget<TextField>(find.byKey(templateCreateNameKey)).enabled,
|
|
isTrue,
|
|
);
|
|
});
|
|
|
|
testWidgets('a pending validate guards a double submit', (tester) async {
|
|
final validate = Completer<JsonMap>();
|
|
final submit = Completer<JsonMap>();
|
|
var validates = 0;
|
|
final gateway = FakeTemplateCreateGateway((type, fields) {
|
|
if (type == 'validate') {
|
|
validates++;
|
|
return validate.future;
|
|
}
|
|
return submit.future;
|
|
});
|
|
final created = <JsonMap>[];
|
|
await tester.pumpWidget(
|
|
templateCreateApp(
|
|
TemplateCreateHost(gateway: gateway, onCreated: created.add),
|
|
),
|
|
);
|
|
|
|
await tester.tap(find.byKey(templateCreateOpenKey));
|
|
await tester.pumpAndSettle();
|
|
await tester.enterText(find.byKey(templateCreateNameKey), 'Only once');
|
|
await tester.pump();
|
|
await tester.tap(find.byKey(templateCreateConfirmKey));
|
|
await tester.tap(find.byKey(templateCreateConfirmKey));
|
|
await tester.pump();
|
|
expect(validates, 1);
|
|
expect(gateway.calls.where((call) => call.type == 'submit'), isEmpty);
|
|
expect(find.text(templateCreateSendingLabel), findsOneWidget);
|
|
// In flight the prompt cannot be dismissed or edited.
|
|
expect(
|
|
tester.widget<TextField>(find.byKey(templateCreateNameKey)).enabled,
|
|
isFalse,
|
|
);
|
|
expect(
|
|
tester.widget<TextButton>(find.byKey(templateCreateCancelKey)).onPressed,
|
|
isNull,
|
|
);
|
|
await tester.binding.handlePopRoute();
|
|
await tester.pump();
|
|
expect(find.byType(AlertDialog), findsOneWidget);
|
|
|
|
validate.complete({'graph': {}});
|
|
await tester.pump();
|
|
await tester.pump();
|
|
await tester.tap(find.byKey(templateCreateConfirmKey));
|
|
await tester.pump();
|
|
expect(gateway.calls.where((call) => call.type == 'submit'), hasLength(1));
|
|
expect(
|
|
gateway.calls.where((call) => call.type == 'validate'),
|
|
hasLength(1),
|
|
);
|
|
|
|
submit.complete({
|
|
'detail': {'id': 2, 'name': 'Only once'},
|
|
});
|
|
await tester.pumpAndSettle();
|
|
expect(created.single, {'id': 2, 'name': 'Only once'});
|
|
expect(
|
|
find.text('Created "Only once". It is in the Pipelines list.'),
|
|
findsOneWidget,
|
|
);
|
|
});
|
|
}
|