mirror of
https://github.com/we-promise/sure.git
synced 2026-07-20 08:45:22 +00:00
feat(mobile): add SureTextField primitive and migrate the proxy-headers editor (#2378)
Adds SureTextField, the form-control primitive following SureButton in the mobile design-system sequence: a TextFormField wrapper that builds a complete, brightness-aware InputDecoration from the active SureColors palette (filled bg-container, borderSecondary hairline -> borderPrimary on focus, destructive error border, textSubdued placeholder, radiusLg corners) with a DS-style label rendered above the field and associated to it for screen readers (Material labelText parity via ExcludeSemantics + Semantics(label:)). Migrates the custom proxy-headers editor off raw TextFormField as proof. Filter chips and a segmented control will follow as separate PRs. Part of #2235.
This commit is contained in:
49
mobile/test/widgets/custom_proxy_headers_editor_test.dart
Normal file
49
mobile/test/widgets/custom_proxy_headers_editor_test.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:sure_mobile/models/custom_proxy_header.dart';
|
||||
import 'package:sure_mobile/theme/sure_theme.dart';
|
||||
import 'package:sure_mobile/widgets/custom_proxy_headers_editor.dart';
|
||||
import 'package:sure_mobile/widgets/sure_text_field.dart';
|
||||
|
||||
// Proof that migrating the editor's fields to SureTextField preserved behavior:
|
||||
// the fields still render, onChanged still fires, and validators still run.
|
||||
void main() {
|
||||
Future<void> pump(WidgetTester tester, Widget child) {
|
||||
return tester.pumpWidget(
|
||||
MaterialApp(theme: SureTheme.light, home: Scaffold(body: child)),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('renders SureTextField rows for each header', (tester) async {
|
||||
await pump(
|
||||
tester,
|
||||
CustomProxyHeadersEditor(
|
||||
initialHeaders: [CustomProxyHeader(name: 'X-Token', value: 'abc')],
|
||||
onChanged: (_) {},
|
||||
),
|
||||
);
|
||||
// Name + value field per header row.
|
||||
expect(find.byType(SureTextField), findsNWidgets(2));
|
||||
expect(find.text('Header name'), findsOneWidget);
|
||||
expect(find.text('Header value'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('editing a field fires onChanged with the parsed headers',
|
||||
(tester) async {
|
||||
List<CustomProxyHeader>? latest;
|
||||
await pump(
|
||||
tester,
|
||||
CustomProxyHeadersEditor(
|
||||
initialHeaders: [CustomProxyHeader(name: 'X-Token', value: 'abc')],
|
||||
onChanged: (headers) => latest = headers,
|
||||
),
|
||||
);
|
||||
|
||||
await tester.enterText(find.byType(TextField).first, 'X-Renamed');
|
||||
await tester.pump();
|
||||
|
||||
expect(latest, isNotNull);
|
||||
expect(latest!.single.name, 'X-Renamed');
|
||||
expect(latest!.single.value, 'abc');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user