From a219069ce331834cbcafc25d4f94f6f27d418986 Mon Sep 17 00:00:00 2001 From: Udhay-Adithya Date: Sat, 19 Jul 2025 13:42:27 +0530 Subject: [PATCH] test: update auth field tests --- .../auth/api_key_auth_fields.dart | 13 +- lib/widgets/field_auth.dart | 4 +- .../auth/api_key_auth_fields_test.dart | 228 ++++++++++++------ .../auth/basic_auth_fields_test.dart | 148 +++++++----- .../auth/bearer_auth_fields_test.dart | 158 +++++++----- .../auth/digest_auth_fields_test.dart | 221 ++++++++++------- .../auth/jwt_auth_fields_test.dart | 130 +++++----- 7 files changed, 571 insertions(+), 331 deletions(-) diff --git a/lib/screens/common_widgets/auth/api_key_auth_fields.dart b/lib/screens/common_widgets/auth/api_key_auth_fields.dart index 895735e7..b9b1c1fe 100644 --- a/lib/screens/common_widgets/auth/api_key_auth_fields.dart +++ b/lib/screens/common_widgets/auth/api_key_auth_fields.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; @@ -29,7 +31,12 @@ class _ApiKeyAuthFieldsState extends State { super.initState(); final apiAuth = widget.authData?.apikey; _key = apiAuth?.key ?? ''; - _name = apiAuth?.name ?? kApiKeyHeaderName; + log(apiAuth?.name ?? "By default name is empty"); + _name = (apiAuth?.name != null && apiAuth!.name.isNotEmpty) + ? apiAuth.name + : kApiKeyHeaderName; + + log(_name); _addKeyTo = apiAuth?.location ?? kAddToDefaultLocation; } @@ -68,7 +75,7 @@ class _ApiKeyAuthFieldsState extends State { EnvAuthField( readOnly: widget.readOnly, hintText: kHintTextFieldName, - initialValue: widget.authData?.apikey?.name, + initialValue: _name, onChanged: (value) { _name = value; _updateApiKeyAuth(); @@ -80,7 +87,7 @@ class _ApiKeyAuthFieldsState extends State { title: kLabelApiKey, hintText: kHintTextKey, isObscureText: true, - initialValue: widget.authData?.apikey?.key, + initialValue: _key, onChanged: (value) { _key = value; _updateApiKeyAuth(); diff --git a/lib/widgets/field_auth.dart b/lib/widgets/field_auth.dart index ccccd30e..33ebff21 100644 --- a/lib/widgets/field_auth.dart +++ b/lib/widgets/field_auth.dart @@ -21,7 +21,7 @@ class EnvAuthField extends StatefulWidget { this.readOnly = false, this.isObscureText = false, this.infoText, - this.initialValue}); + required this.initialValue}); @override State createState() => _AuthFieldState(); @@ -59,7 +59,7 @@ class _AuthFieldState extends State { EnvironmentTriggerField( keyId: "auth-${widget.title ?? widget.hintText}-${Random.secure()}", onChanged: widget.onChanged, - initialValue: widget.initialValue, + initialValue: widget.initialValue ?? "", readOnly: widget.readOnly, // TODO: Needs some new implementation // obscureText: widget.isObscureText, diff --git a/test/screens/common_widgets/auth/api_key_auth_fields_test.dart b/test/screens/common_widgets/auth/api_key_auth_fields_test.dart index 1e60cbd6..b5fec061 100644 --- a/test/screens/common_widgets/auth/api_key_auth_fields_test.dart +++ b/test/screens/common_widgets/auth/api_key_auth_fields_test.dart @@ -2,7 +2,9 @@ import 'package:apidash/screens/common_widgets/auth/api_key_auth_fields.dart'; import 'package:apidash/widgets/widgets.dart'; import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; +import 'package:extended_text_field/extended_text_field.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_portal/flutter_portal.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -23,11 +25,15 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), @@ -35,7 +41,7 @@ void main() { expect(find.text('Add to'), findsOneWidget); expect(find.byType(ADPopupMenu), findsOneWidget); - expect(find.byType(AuthTextField), findsNWidgets(2)); + expect(find.byType(EnvAuthField), findsNWidgets(2)); expect(find.text('Header'), findsOneWidget); }); @@ -43,20 +49,38 @@ void main() { 'updates auth data when authData is null and API key value is changed', (WidgetTester tester) async { await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: null, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: null, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), ); - // Find the key field (second AuthTextField) - final keyField = find.byType(AuthTextField).last; - await tester.tap(keyField); - await tester.enterText(keyField, 'new-api-key'); + // Wait for the widget to settle + await tester.pumpAndSettle(); + + // Find EnvAuthField widgets + final authFields = find.byType(EnvAuthField); + expect(authFields, findsNWidgets(2)); + + // Find ExtendedTextField widgets within the EnvAuthField widgets + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(2)); + + // Use testTextInput to directly input text + final lastField = textFields.last; + await tester.tap(lastField); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('new-api-key'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -77,11 +101,15 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), @@ -89,7 +117,7 @@ void main() { expect(find.text('Add to'), findsOneWidget); expect(find.text('Header'), findsOneWidget); - expect(find.byType(AuthTextField), findsNWidgets(2)); + expect(find.byType(EnvAuthField), findsNWidgets(2)); }); testWidgets('renders with query params location', @@ -104,11 +132,15 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), @@ -130,11 +162,15 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), @@ -166,20 +202,33 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), ); - // Find the name field (first AuthTextField) - final nameField = find.byType(AuthTextField).first; - await tester.tap(nameField); - await tester.enterText(nameField, 'Authorization'); + // Wait for the widget to settle + await tester.pumpAndSettle(); + + // Find ExtendedTextField widgets + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(2)); + + // Tap and enter text in the name field (should be the first text field) + await tester.tap(textFields.first); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('Authorization'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -200,20 +249,37 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), ); - // Find the key field (second AuthTextField) - final keyField = find.byType(AuthTextField).last; - await tester.tap(keyField); - await tester.enterText(keyField, 'new-api-key'); + // Wait for the widget to settle + await tester.pumpAndSettle(); + + // Find EnvAuthField widgets + final textFields = find.byType(EnvAuthField); + expect(textFields, findsNWidgets(2)); + + // Find the underlying ExtendedTextField widgets + final extendedTextFields = find.byType(ExtendedTextField); + expect(extendedTextFields, findsAtLeastNWidgets(2)); + + // Tap and enter text in the key field (should be the last text field) + await tester.tap(extendedTextFields.last); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('new-api-key'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -233,21 +299,25 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, - readOnly: true, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + readOnly: true, + ), + ), ), ), ), ); - // Verify that AuthTextField widgets are rendered - expect(find.byType(AuthTextField), findsNWidgets(2)); + // Verify that EnvAuthField widgets are rendered + expect(find.byType(EnvAuthField), findsNWidgets(2)); - // The readOnly property should be passed to AuthTextField widgets + // The readOnly property should be passed to EnvAuthField widgets // This is verified by the widget structure itself }); @@ -255,11 +325,15 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), @@ -267,28 +341,40 @@ void main() { expect(find.text('Add to'), findsOneWidget); // Check for the existence of the auth text fields - expect(find.byType(AuthTextField), findsNWidgets(2)); + expect(find.byType(EnvAuthField), findsNWidgets(2)); }); testWidgets('initializes with correct default values', (WidgetTester tester) async { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: ApiKeyAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: ApiKeyAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), ); + // Wait for the widget to settle + await tester.pumpAndSettle(); + // Default location should be header expect(find.text('Header'), findsOneWidget); - // Default name should be 'x-api-key' in the text field - expect(find.text('x-api-key'), findsOneWidget); + // Check for the existence of text fields with default values + final textFields = find.byType(EnvAuthField); + expect(textFields, findsNWidgets(2)); + + // Verify the first text field (name) has the default value in its controller + final nameTextField = tester.widget(textFields.first); + expect(nameTextField.initialValue, 'x-api-key'); }); }); } diff --git a/test/screens/common_widgets/auth/basic_auth_fields_test.dart b/test/screens/common_widgets/auth/basic_auth_fields_test.dart index 8a5d8814..2ea848bb 100644 --- a/test/screens/common_widgets/auth/basic_auth_fields_test.dart +++ b/test/screens/common_widgets/auth/basic_auth_fields_test.dart @@ -1,7 +1,9 @@ import 'package:apidash/screens/common_widgets/auth/basic_auth_fields.dart'; import 'package:apidash/widgets/widgets.dart'; import 'package:apidash_core/apidash_core.dart'; +import 'package:extended_text_field/extended_text_field.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_portal/flutter_portal.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -22,17 +24,19 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BasicAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BasicAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsNWidgets(2)); + expect(find.byType(EnvAuthField), findsNWidgets(2)); expect(find.text('Username'), findsNWidgets(2)); expect(find.text('Password'), findsNWidgets(2)); }); @@ -48,17 +52,19 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BasicAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BasicAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsNWidgets(2)); + expect(find.byType(EnvAuthField), findsNWidgets(2)); expect(find.text('Username'), findsExactly(2)); expect(find.text('Password'), findsExactly(2)); }); @@ -74,20 +80,28 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BasicAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BasicAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - // Find the username field (first AuthTextField) - final usernameField = find.byType(AuthTextField).first; + // Find the username field (first ExtendedTextField) + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(2)); + + final usernameField = textFields.first; await tester.tap(usernameField); - await tester.enterText(usernameField, 'newuser'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('newuser'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -108,20 +122,28 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BasicAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BasicAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - // Find the password field (second AuthTextField) - final passwordField = find.byType(AuthTextField).last; + // Find the password field (second ExtendedTextField) + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(2)); + + final passwordField = textFields.last; await tester.tap(passwordField); - await tester.enterText(passwordField, 'newpass'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('newpass'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -141,21 +163,23 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BasicAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, - readOnly: true, + Portal( + child: MaterialApp( + home: Scaffold( + body: BasicAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + readOnly: true, + ), ), ), ), ); - // Verify that AuthTextField widgets are rendered - expect(find.byType(AuthTextField), findsNWidgets(2)); + // Verify that EnvAuthField widgets are rendered + expect(find.byType(EnvAuthField), findsNWidgets(2)); - // The readOnly property should be passed to AuthTextField widgets + // The readOnly property should be passed to EnvAuthField widgets // This is verified by the widget structure itself }); @@ -163,17 +187,19 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BasicAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BasicAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsNWidgets(2)); + expect(find.byType(EnvAuthField), findsNWidgets(2)); }); testWidgets('handles empty auth data gracefully', @@ -187,17 +213,19 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BasicAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BasicAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsNWidgets(2)); + expect(find.byType(EnvAuthField), findsNWidgets(2)); }); testWidgets('creates proper AuthModel on field changes', @@ -205,20 +233,28 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BasicAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BasicAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); // Enter username - final usernameField = find.byType(AuthTextField).first; + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(2)); + + final usernameField = textFields.first; await tester.tap(usernameField); - await tester.enterText(usernameField, 'testuser'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('testuser'); await tester.pumpAndSettle(); // Verify that updateAuth was called with correct structure diff --git a/test/screens/common_widgets/auth/bearer_auth_fields_test.dart b/test/screens/common_widgets/auth/bearer_auth_fields_test.dart index c8dc1336..c4c040b0 100644 --- a/test/screens/common_widgets/auth/bearer_auth_fields_test.dart +++ b/test/screens/common_widgets/auth/bearer_auth_fields_test.dart @@ -1,7 +1,9 @@ import 'package:apidash/screens/common_widgets/auth/bearer_auth_fields.dart'; import 'package:apidash/widgets/widgets.dart'; import 'package:apidash_core/apidash_core.dart'; +import 'package:extended_text_field/extended_text_field.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_portal/flutter_portal.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -22,17 +24,19 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BearerAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BearerAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsOneWidget); + expect(find.byType(EnvAuthField), findsOneWidget); expect(find.text('Token'), findsNWidgets(2)); }); @@ -46,17 +50,19 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BearerAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BearerAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsOneWidget); + expect(find.byType(EnvAuthField), findsOneWidget); expect(find.text('Token'), findsNWidgets(2)); }); @@ -70,20 +76,28 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BearerAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BearerAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); // Find the token field - final tokenField = find.byType(AuthTextField); + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(1)); + + final tokenField = textFields.first; await tester.tap(tokenField); - await tester.enterText(tokenField, 'new-bearer-token'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('new-bearer-token'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -102,21 +116,23 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BearerAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, - readOnly: true, + Portal( + child: MaterialApp( + home: Scaffold( + body: BearerAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + readOnly: true, + ), ), ), ), ); - // Verify that AuthTextField widget is rendered - expect(find.byType(AuthTextField), findsOneWidget); + // Verify that EnvAuthField widget is rendered + expect(find.byType(EnvAuthField), findsOneWidget); - // The readOnly property should be passed to AuthTextField widget + // The readOnly property should be passed to EnvAuthField widget // This is verified by the widget structure itself }); @@ -124,17 +140,19 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BearerAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BearerAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsOneWidget); + expect(find.byType(EnvAuthField), findsOneWidget); }); testWidgets('handles empty auth data gracefully', @@ -147,17 +165,19 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BearerAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BearerAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsOneWidget); + expect(find.byType(EnvAuthField), findsOneWidget); }); testWidgets('creates proper AuthModel on token change', @@ -165,20 +185,28 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BearerAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BearerAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); // Enter token - final tokenField = find.byType(AuthTextField); + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(1)); + + final tokenField = textFields.first; await tester.tap(tokenField); - await tester.enterText(tokenField, 'test-bearer-token'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('test-bearer-token'); await tester.pumpAndSettle(); // Verify that updateAuth was called with correct structure @@ -193,18 +221,20 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BearerAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BearerAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); // The token field should be empty initially - expect(find.byType(AuthTextField), findsOneWidget); + expect(find.byType(EnvAuthField), findsOneWidget); }); testWidgets('trims whitespace from token input', @@ -212,20 +242,28 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: BearerAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: BearerAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); // Enter token with whitespace - final tokenField = find.byType(AuthTextField); + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(1)); + + final tokenField = textFields.first; await tester.tap(tokenField); - await tester.enterText(tokenField, ' test-token '); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText(' test-token '); await tester.pumpAndSettle(); // Verify that updateAuth was called with trimmed token diff --git a/test/screens/common_widgets/auth/digest_auth_fields_test.dart b/test/screens/common_widgets/auth/digest_auth_fields_test.dart index 2eb26a04..7cdaf617 100644 --- a/test/screens/common_widgets/auth/digest_auth_fields_test.dart +++ b/test/screens/common_widgets/auth/digest_auth_fields_test.dart @@ -2,7 +2,9 @@ import 'package:apidash/screens/common_widgets/auth/digest_auth_fields.dart'; import 'package:apidash/widgets/widgets.dart'; import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/widgets/widgets.dart'; +import 'package:extended_text_field/extended_text_field.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_portal/flutter_portal.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -23,19 +25,21 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsNWidgets(6)); + expect(find.byType(EnvAuthField), findsNWidgets(6)); expect(find.byType(ADPopupMenu), findsOneWidget); - // Check for field labels (each AuthTextField creates a Text widget for label) + // Check for field labels (each EnvAuthField creates a Text widget for label) expect(find.text('Username'), findsNWidgets(2)); expect(find.text('Password'), findsNWidgets(2)); expect(find.text('Realm'), findsNWidgets(2)); @@ -61,17 +65,19 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsNWidgets(6)); + expect(find.byType(EnvAuthField), findsNWidgets(6)); expect(find.byType(ADPopupMenu), findsOneWidget); expect(find.text('MD5'), findsOneWidget); }); @@ -92,20 +98,28 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - // Find the username field (first AuthTextField) - final usernameField = find.byType(AuthTextField).first; + // Find the username field (first ExtendedTextField) + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(6)); + + final usernameField = textFields.first; await tester.tap(usernameField); - await tester.enterText(usernameField, 'newuser'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('newuser'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -131,20 +145,28 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - // Find the password field (second AuthTextField) - final passwordField = find.byType(AuthTextField).at(1); + // Find the password field (second ExtendedTextField) + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(6)); + + final passwordField = textFields.at(1); await tester.tap(passwordField); - await tester.enterText(passwordField, 'newpass'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('newpass'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -170,11 +192,13 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -210,20 +234,28 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - // Find the realm field (third AuthTextField) - final realmField = find.byType(AuthTextField).at(2); + // Find the realm field (third ExtendedTextField) + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(6)); + + final realmField = textFields.at(2); await tester.tap(realmField); - await tester.enterText(realmField, 'newrealm'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('newrealm'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -247,46 +279,51 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, - readOnly: true, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + readOnly: true, + ), ), ), ), ); - final usernameFieldFinder = find.byType(AuthTextField).first; + final usernameFieldFinder = find.byType(ExtendedTextField).first; - // Try to enter text - await tester.enterText(usernameFieldFinder, 'testuser'); - await tester.pumpAndSettle(); + // Verify the field is readOnly + final usernameField = + tester.widget(usernameFieldFinder); + expect(usernameField.readOnly, isTrue); // Ensure updateAuth was not called expect(capturedAuthUpdates, isEmpty); // Check the field still shows original value - final textField = tester.widget(usernameFieldFinder); - expect(textField.controller.text, equals('user')); + final textField = tester.widget(usernameFieldFinder); + expect(textField.controller?.text, equals('user')); }); testWidgets('displays correct hint texts', (WidgetTester tester) async { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); - expect(find.byType(AuthTextField), findsNWidgets(6)); + expect(find.byType(EnvAuthField), findsNWidgets(6)); expect(find.byType(ADPopupMenu), findsOneWidget); expect(find.text('Algorithm'), findsOneWidget); }); @@ -296,11 +333,13 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -311,7 +350,7 @@ void main() { // Default QOP should be 'auth' - but this is in the TextFormField value, not visible text // We need to check the controller value instead - expect(find.byType(AuthTextField), findsNWidgets(6)); + expect(find.byType(EnvAuthField), findsNWidgets(6)); }); testWidgets('creates proper AuthModel on field changes', @@ -319,20 +358,22 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); // Enter username - final usernameField = find.byType(AuthTextField).first; + final usernameField = find.byType(ExtendedTextField).first; await tester.tap(usernameField); - await tester.enterText(usernameField, 'testuser'); + tester.testTextInput.enterText('testuser'); await tester.pumpAndSettle(); // Verify that updateAuth was called with correct structure @@ -348,11 +389,13 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -380,20 +423,28 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: DigestAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: DigestAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); // Enter username with whitespace - final usernameField = find.byType(AuthTextField).first; + final textFields = find.byType(ExtendedTextField); + expect(textFields, findsAtLeastNWidgets(6)); + + final usernameField = textFields.first; await tester.tap(usernameField); - await tester.enterText(usernameField, ' testuser '); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText(' testuser '); await tester.pumpAndSettle(); // Verify that updateAuth was called with trimmed values diff --git a/test/screens/common_widgets/auth/jwt_auth_fields_test.dart b/test/screens/common_widgets/auth/jwt_auth_fields_test.dart index ff02166b..83a67e33 100644 --- a/test/screens/common_widgets/auth/jwt_auth_fields_test.dart +++ b/test/screens/common_widgets/auth/jwt_auth_fields_test.dart @@ -2,8 +2,10 @@ import 'package:apidash/screens/common_widgets/auth/jwt_auth_fields.dart'; import 'package:apidash/widgets/widgets.dart'; import 'package:apidash_core/apidash_core.dart'; import 'package:apidash_design_system/apidash_design_system.dart'; +import 'package:extended_text_field/extended_text_field.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter_portal/flutter_portal.dart'; void main() { group('JwtAuthFields Widget Tests', () { @@ -23,11 +25,13 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -59,11 +63,13 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -93,11 +99,13 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -105,7 +113,7 @@ void main() { expect(find.text('Secret Key'), findsExactly(2)); expect(find.text('Secret is Base64 encoded'), findsOneWidget); - expect(find.byType(AuthTextField), findsOneWidget); + expect(find.byType(EnvAuthField), findsOneWidget); expect(find.byType(CheckboxListTile), findsOneWidget); }); @@ -127,11 +135,13 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -160,11 +170,13 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -202,11 +214,13 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -244,20 +258,22 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ); // Find the secret field - final secretField = find.byType(AuthTextField).first; + final secretField = find.byType(ExtendedTextField).first; await tester.tap(secretField); - await tester.enterText(secretField, 'new-secret'); + tester.testTextInput.enterText('new-secret'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -284,11 +300,13 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -297,7 +315,7 @@ void main() { // Find the payload field (TextField) final payloadField = find.byType(TextField).last; await tester.tap(payloadField); - await tester.enterText(payloadField, '{"sub": "1234567890"}'); + tester.testTextInput.enterText('{"sub": "1234567890"}'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -324,11 +342,13 @@ void main() { ); await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -349,11 +369,13 @@ void main() { mockAuthData = null; await tester.pumpWidget( - MaterialApp( - home: Scaffold( - body: JwtAuthFields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + Portal( + child: MaterialApp( + home: Scaffold( + body: JwtAuthFields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ),