From 1dece554822863ab9fd8cf11866dad4e8cbb0a18 Mon Sep 17 00:00:00 2001 From: Udhay-Adithya Date: Thu, 7 Aug 2025 12:46:56 +0530 Subject: [PATCH] test: update oauth1 and oauth2 tests for EnvAuthField --- test/models/history_models.dart | 4 +- .../auth/oauth1_fields_test.dart | 273 +++++---- .../auth/oauth2_fields_test.dart | 546 +++++++++++------- test/utils/pre_post_script_utils_test.dart | 2 - 4 files changed, 518 insertions(+), 307 deletions(-) diff --git a/test/models/history_models.dart b/test/models/history_models.dart index 6de41dc1..d12af357 100644 --- a/test/models/history_models.dart +++ b/test/models/history_models.dart @@ -66,7 +66,9 @@ final Map historyRequestModelJson1 = { 'bearer': null, 'basic': null, 'jwt': null, - 'digest': null + 'digest': null, + 'oauth1': null, + 'oauth2': null } }; diff --git a/test/screens/common_widgets/auth/oauth1_fields_test.dart b/test/screens/common_widgets/auth/oauth1_fields_test.dart index 1136f1ad..4a61e318 100644 --- a/test/screens/common_widgets/auth/oauth1_fields_test.dart +++ b/test/screens/common_widgets/auth/oauth1_fields_test.dart @@ -1,10 +1,12 @@ import 'package:apidash/screens/common_widgets/auth/oauth1_fields.dart'; -import 'package:apidash/widgets/field_auth.dart'; +import 'package:apidash/screens/common_widgets/common_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_riverpod/flutter_riverpod.dart'; +import 'package:flutter_portal/flutter_portal.dart'; import 'package:apidash/providers/settings_providers.dart'; import 'package:apidash/providers/collection_providers.dart'; import 'package:apidash/models/models.dart'; @@ -38,12 +40,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -51,7 +55,7 @@ void main() { ), ); - expect(find.byType(AuthTextField), findsNWidgets(9)); + expect(find.byType(EnvAuthField), findsNWidgets(9)); expect(find.byType(ADPopupMenu), findsOneWidget); expect(find.text('Signature Method'), findsOneWidget); }); @@ -86,12 +90,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -99,7 +105,7 @@ void main() { ), ); - expect(find.byType(AuthTextField), findsNWidgets(9)); + expect(find.byType(EnvAuthField), findsNWidgets(9)); expect(find.byType(ADPopupMenu), findsOneWidget); }); @@ -126,12 +132,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -139,10 +147,18 @@ void main() { ), ); - // Find the consumer key field (first AuthTextField) - final consumerKeyField = find.byType(AuthTextField).first; + // Find the consumer key field using find.descendant + expect(find.byType(EnvAuthField), findsNWidgets(9)); + + final consumerKeyField = find.descendant( + of: find.byType(EnvAuthField).first, + matching: find.byType(ExtendedTextField), + ); await tester.tap(consumerKeyField); - await tester.enterText(consumerKeyField, 'new_consumer_key'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('new_consumer_key'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -175,12 +191,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -188,10 +206,18 @@ void main() { ), ); - // Find the consumer secret field (second AuthTextField) - final consumerSecretField = find.byType(AuthTextField).at(1); + // Find the consumer secret field using find.descendant + expect(find.byType(EnvAuthField), findsNWidgets(9)); + + final consumerSecretField = find.descendant( + of: find.byType(EnvAuthField).at(1), + matching: find.byType(ExtendedTextField), + ); await tester.tap(consumerSecretField); - await tester.enterText(consumerSecretField, 'new_consumer_secret'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('new_consumer_secret'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -224,12 +250,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -279,12 +307,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -292,10 +322,18 @@ void main() { ), ); - // Find the access token field (3rd AuthTextField, after consumer key, secret, and before signature method dropdown) - final accessTokenField = find.byType(AuthTextField).at(2); + // Find the access token field using find.descendant + expect(find.byType(EnvAuthField), findsNWidgets(9)); + + final accessTokenField = find.descendant( + of: find.byType(EnvAuthField).at(2), + matching: find.byType(ExtendedTextField), + ); await tester.tap(accessTokenField); - await tester.enterText(accessTokenField, 'new_access_token'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('new_access_token'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -327,13 +365,15 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, - readOnly: true, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + readOnly: true, + ), ), ), ), @@ -341,11 +381,11 @@ void main() { ), ); - // Verify that AuthTextField widgets are rendered - expect(find.byType(AuthTextField), findsNWidgets(9)); + // Verify that EnvAuthField widgets are rendered + expect(find.byType(EnvAuthField), findsNWidgets(9)); expect(find.byType(ADPopupMenu), findsOneWidget); - // 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 }); @@ -374,12 +414,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -387,7 +429,7 @@ void main() { ), ); - expect(find.byType(AuthTextField), findsNWidgets(9)); + expect(find.byType(EnvAuthField), findsNWidgets(9)); expect(find.byType(ADPopupMenu), findsOneWidget); }); @@ -406,12 +448,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -419,10 +463,18 @@ void main() { ), ); - // Enter consumer key - final consumerKeyField = find.byType(AuthTextField).first; + // Enter consumer key using find.descendant + expect(find.byType(EnvAuthField), findsNWidgets(9)); + + final consumerKeyField = find.descendant( + of: find.byType(EnvAuthField).first, + matching: find.byType(ExtendedTextField), + ); await tester.tap(consumerKeyField); - await tester.enterText(consumerKeyField, 'test_consumer_key'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('test_consumer_key'); await tester.pumpAndSettle(); // Verify that updateAuth was called with correct structure @@ -445,12 +497,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -458,7 +512,7 @@ void main() { ), ); - expect(find.byType(AuthTextField), findsNWidgets(9)); + expect(find.byType(EnvAuthField), findsNWidgets(9)); expect(find.text('Signature Method'), findsOneWidget); }); @@ -487,12 +541,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -500,10 +556,18 @@ void main() { ), ); - // Find the token secret field (4th AuthTextField) - final tokenSecretField = find.byType(AuthTextField).at(3); + // Find the token secret field using find.descendant + expect(find.byType(EnvAuthField), findsNWidgets(9)); + + final tokenSecretField = find.descendant( + of: find.byType(EnvAuthField).at(3), + matching: find.byType(ExtendedTextField), + ); await tester.tap(tokenSecretField); - await tester.enterText(tokenSecretField, 'new_token_secret'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('new_token_secret'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -537,12 +601,14 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: SingleChildScrollView( - child: OAuth1Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth1Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -550,11 +616,18 @@ void main() { ), ); - // Find the callback URL field (5th AuthTextField) - final callbackUrlField = find.byType(AuthTextField).at(4); + // Find the callback URL field using find.descendant + expect(find.byType(EnvAuthField), findsNWidgets(9)); + + final callbackUrlField = find.descendant( + of: find.byType(EnvAuthField).at(4), + matching: find.byType(ExtendedTextField), + ); await tester.tap(callbackUrlField); - await tester.enterText( - callbackUrlField, 'http://api.apidash.dev/callback'); + await tester.pumpAndSettle(); + + // Use tester.testTextInput to enter text directly + tester.testTextInput.enterText('http://api.apidash.dev/callback'); await tester.pumpAndSettle(); // Verify that updateAuth was called diff --git a/test/screens/common_widgets/auth/oauth2_fields_test.dart b/test/screens/common_widgets/auth/oauth2_fields_test.dart index ed3bbf45..0c54a4aa 100644 --- a/test/screens/common_widgets/auth/oauth2_fields_test.dart +++ b/test/screens/common_widgets/auth/oauth2_fields_test.dart @@ -2,10 +2,12 @@ import 'package:apidash/providers/settings_providers.dart'; import 'package:apidash/providers/collection_providers.dart'; import 'package:apidash/models/models.dart'; import 'package:apidash/screens/common_widgets/auth/oauth2_field.dart'; -import 'package:apidash/widgets/widgets.dart'; +import 'package:apidash/screens/common_widgets/common_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_riverpod/flutter_riverpod.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -38,20 +40,23 @@ void main() { ), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); expect(find.byType(ADPopupMenu), findsOneWidget); expect(find.text('Grant Type'), findsOneWidget); - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); // Note: ADTextButton might not be visible in all configurations }); @@ -86,19 +91,22 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); expect(find.byType(ADPopupMenu), findsOneWidget); - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); }); testWidgets('updates auth data when grant type changes', @@ -126,10 +134,12 @@ void main() { selectedRequestModelProvider.overrideWith((ref) => null), ], child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + home: Portal( + child: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -177,21 +187,27 @@ void main() { selectedRequestModelProvider.overrideWith((ref) => null), ], child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + home: Portal( + child: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Find the authorization URL field and update it - final authUrlField = find.byType(AuthTextField).first; + // Find the authorization URL field using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + final authUrlField = find.descendant( + of: find.byType(EnvAuthField).first, + matching: find.byType(ExtendedTextField), + ); await tester.tap(authUrlField); - await tester.enterText( - authUrlField, 'https://new.auth.apidash.dev/authorize'); + tester.testTextInput.enterText('https://new.auth.apidash.dev/authorize'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -227,21 +243,27 @@ void main() { selectedRequestModelProvider.overrideWith((ref) => null), ], child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + home: Portal( + child: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Find the access token URL field and update it - final accessTokenUrlField = find.byType(AuthTextField).at(1); + // Find the access token URL field using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + final accessTokenUrlField = find.descendant( + of: find.byType(EnvAuthField).at(1), + matching: find.byType(ExtendedTextField), + ); await tester.tap(accessTokenUrlField); - await tester.enterText( - accessTokenUrlField, 'https://new.auth.apidash.dev/token'); + tester.testTextInput.enterText('https://new.auth.apidash.dev/token'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -277,20 +299,27 @@ void main() { selectedRequestModelProvider.overrideWith((ref) => null), ], child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + home: Portal( + child: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Find the client ID field and update it - final clientIdField = find.byType(AuthTextField).at(2); + // Find the client ID field using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + final clientIdField = find.descendant( + of: find.byType(EnvAuthField).at(2), + matching: find.byType(ExtendedTextField), + ); await tester.tap(clientIdField); - await tester.enterText(clientIdField, 'new_client_id'); + tester.testTextInput.enterText('new_client_id'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -325,20 +354,27 @@ void main() { selectedRequestModelProvider.overrideWith((ref) => null), ], child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + home: Portal( + child: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Find the client secret field and update it - final clientSecretField = find.byType(AuthTextField).at(3); + // Find the client secret field using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + final clientSecretField = find.descendant( + of: find.byType(EnvAuthField).at(3), + matching: find.byType(ExtendedTextField), + ); await tester.tap(clientSecretField); - await tester.enterText(clientSecretField, 'new_client_secret'); + tester.testTextInput.enterText('new_client_secret'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -372,11 +408,13 @@ void main() { selectedRequestModelProvider.overrideWith((ref) => null), ], child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, - readOnly: true, + home: Portal( + child: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + readOnly: true, + ), ), ), ), @@ -385,9 +423,9 @@ void main() { // Verify that widgets are rendered expect(find.byType(ADPopupMenu), findsOneWidget); - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); - // The readOnly property should be passed to AuthTextField widgets + // The readOnly property should be passed to ExtendedTextField widgets // This is verified by the widget structure itself }); @@ -416,10 +454,12 @@ void main() { selectedRequestModelProvider.overrideWith((ref) => null), ], child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + home: Portal( + child: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -427,7 +467,7 @@ void main() { ); expect(find.byType(ADPopupMenu), findsOneWidget); - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); }); testWidgets( @@ -446,20 +486,27 @@ void main() { selectedRequestModelProvider.overrideWith((ref) => null), ], child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + home: Portal( + child: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Enter client ID - final clientIdField = find.byType(AuthTextField).at(2); + // Enter client ID using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + final clientIdField = find.descendant( + of: find.byType(EnvAuthField).at(2), + matching: find.byType(ExtendedTextField), + ); await tester.tap(clientIdField); - await tester.enterText(clientIdField, 'test_client_id'); + tester.testTextInput.enterText('test_client_id'); await tester.pumpAndSettle(); // Verify that updateAuth was called with correct structure @@ -483,10 +530,12 @@ void main() { selectedRequestModelProvider.overrideWith((ref) => null), ], child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + home: Portal( + child: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -495,7 +544,7 @@ void main() { expect(find.byType(ADPopupMenu), findsOneWidget); expect(find.text('Grant Type'), findsOneWidget); - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); }); testWidgets('shows different fields based on grant type', @@ -524,11 +573,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -536,7 +587,7 @@ void main() { ); // For resource owner password grant type, username and password fields should be visible - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); }); testWidgets('updates auth data when username changes', @@ -565,21 +616,28 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Find the username field and update it - final usernameField = find.byType(AuthTextField).first; + // Find the username field using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + final usernameField = find.descendant( + of: find.byType(EnvAuthField).first, + matching: find.byType(ExtendedTextField), + ); await tester.tap(usernameField); - await tester.enterText(usernameField, 'new_user'); + tester.testTextInput.enterText('new_user'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -614,21 +672,32 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Find the scope field by its text field - // Since field ordering may vary, let's try to find it by clearing first - await tester.enterText( - find.byType(AuthTextField).last, 'read write admin'); + // Find the scope field using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + // For authorization code grant, the scope field should be available + // Use the 5th EnvAuthField for scope + final scopeField = find.descendant( + of: find.byType(EnvAuthField).at(4), + matching: find.byType(ExtendedTextField), + ); + await tester.tap(scopeField); + await tester.pumpAndSettle(); + + tester.testTextInput.enterText('read write admin'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -662,11 +731,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -719,11 +790,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -732,7 +805,7 @@ void main() { // Client credentials should show fewer fields expect(find.byType(ADPopupMenu), findsOneWidget); - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); // Should not show code challenge method dropdown for client credentials expect(find.byType(ADPopupMenu), findsNothing); @@ -764,11 +837,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -812,21 +887,28 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Enter client ID to trigger _updateOAuth2 with null workspace path - final clientIdField = find.byType(AuthTextField).at(2); + // Enter client ID to trigger _updateOAuth2 with null workspace path using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + final clientIdField = find.descendant( + of: find.byType(EnvAuthField).at(2), + matching: find.byType(ExtendedTextField), + ); await tester.tap(clientIdField); - await tester.enterText(clientIdField, 'test_client_id'); + tester.testTextInput.enterText('test_client_id'); await tester.pumpAndSettle(); // Verify that updateAuth was called even with null workspace path @@ -857,11 +939,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -901,11 +985,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -958,21 +1044,28 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Find the password field (should be the second field for this grant type) - final passwordField = find.byType(AuthTextField).at(1); + // Find the password field using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + final passwordField = find.descendant( + of: find.byType(EnvAuthField).at(1), + matching: find.byType(ExtendedTextField), + ); await tester.tap(passwordField); - await tester.enterText(passwordField, 'new_password'); + tester.testTextInput.enterText('new_password'); await tester.pumpAndSettle(); // Verify that updateAuth was called @@ -1006,11 +1099,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -1019,7 +1114,7 @@ void main() { // Verify widget is rendered (this tests the HTTP response listener setup) expect(find.byType(OAuth2Fields), findsOneWidget); - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); }); testWidgets('tests state and redirect URL field updates', @@ -1047,32 +1142,38 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), ), ); - // Find all auth text fields - final textFields = find.byType(AuthTextField); - expect(textFields.evaluate().length, greaterThanOrEqualTo(5)); - - // Update one of the text fields (be safe about the index) - if (textFields.evaluate().length > 3) { - await tester.enterText(textFields.at(3), 'new_value'); + // Find all auth text fields using find.descendant + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + // Update one of the text fields using find.descendant (be safe about the index) + final authFields = find.byType(EnvAuthField); + if (authFields.evaluate().length > 3) { + final fieldToUpdate = find.descendant( + of: authFields.at(3), + matching: find.byType(ExtendedTextField), + ); + await tester.tap(fieldToUpdate); + tester.testTextInput.enterText('new_value'); await tester.pumpAndSettle(); expect(capturedAuthUpdates.length, greaterThan(0)); } }); - testWidgets('tests token field updates', - (WidgetTester tester) async { + testWidgets('tests token field updates', (WidgetTester tester) async { mockAuthData = const AuthModel( type: APIAuthType.oauth2, oauth2: AuthOAuth2Model( @@ -1097,33 +1198,57 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: SingleChildScrollView( + child: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), + ), ), ), ), ), ); - final textFields = find.byType(AuthTextField); - - // Update refresh token field - await tester.enterText(textFields.last.evaluate().length > 7 ? textFields.at(7) : textFields.last, 'new_refresh'); + expect(find.byType(EnvAuthField), findsAtLeastNWidgets(5)); + + // Try to tap on an accessible field using find.descendant (not the last one since it might be off-screen) + final fieldToUpdate = find.descendant( + of: find.byType(EnvAuthField).at(2), + matching: find.byType(ExtendedTextField), + ); + await tester.tap(fieldToUpdate); + await tester.pumpAndSettle(); + + tester.testTextInput.enterText('new_value'); await tester.pumpAndSettle(); expect(capturedAuthUpdates.length, greaterThan(0)); - // Update identity token field - await tester.enterText(textFields.last.evaluate().length > 8 ? textFields.at(8) : textFields.last, 'new_identity'); + // Update identity token field using find.descendant + final authFields = find.byType(EnvAuthField); + final identityTokenField = find.descendant( + of: authFields.evaluate().length > 8 + ? authFields.at(8) + : authFields.last, + matching: find.byType(ExtendedTextField), + ); + await tester.tap(identityTokenField); + tester.testTextInput.enterText('new_identity'); await tester.pumpAndSettle(); expect(capturedAuthUpdates.length, greaterThan(1)); - // Update access token field - await tester.enterText(textFields.last, 'new_access'); + // Update access token field using find.descendant + final accessTokenField = find.descendant( + of: authFields.last, + matching: find.byType(ExtendedTextField), + ); + await tester.tap(accessTokenField); + tester.testTextInput.enterText('new_access'); await tester.pumpAndSettle(); expect(capturedAuthUpdates.length, greaterThan(2)); @@ -1156,11 +1281,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -1170,10 +1297,10 @@ void main() { // Debug: Look for all buttons and text widgets final allButtons = find.byType(ADTextButton); print('Found ${allButtons.evaluate().length} ADTextButton widgets'); - + final allText = find.byType(Text); print('Found ${allText.evaluate().length} Text widgets'); - + // Try finding the button widget itself if (allButtons.evaluate().isNotEmpty) { await tester.tap(allButtons.first); @@ -1208,11 +1335,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -1221,7 +1350,7 @@ void main() { // Widget should render normally even with empty credentials file path expect(find.byType(OAuth2Fields), findsOneWidget); - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); }); testWidgets('tests clear credentials with null or empty file path', @@ -1251,11 +1380,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -1297,11 +1428,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -1310,10 +1443,11 @@ void main() { // Test that widget handles missing credential files gracefully expect(find.byType(OAuth2Fields), findsOneWidget); - expect(find.byType(AuthTextField), findsAtLeastNWidgets(5)); + expect(find.byType(ExtendedTextField), findsAtLeastNWidgets(5)); }); - testWidgets('tests _getExpirationText with different token expiration states', + testWidgets( + 'tests _getExpirationText with different token expiration states', (WidgetTester tester) async { // Test with no token expiration mockAuthData = const AuthModel( @@ -1338,11 +1472,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), @@ -1377,11 +1513,13 @@ void main() { )), selectedRequestModelProvider.overrideWith((ref) => null), ], - child: MaterialApp( - home: Scaffold( - body: OAuth2Fields( - authData: mockAuthData, - updateAuth: mockUpdateAuth, + child: Portal( + child: MaterialApp( + home: Scaffold( + body: OAuth2Fields( + authData: mockAuthData, + updateAuth: mockUpdateAuth, + ), ), ), ), diff --git a/test/utils/pre_post_script_utils_test.dart b/test/utils/pre_post_script_utils_test.dart index ddd8369f..174d6aa7 100644 --- a/test/utils/pre_post_script_utils_test.dart +++ b/test/utils/pre_post_script_utils_test.dart @@ -1257,10 +1257,8 @@ void main() { group('Pre-request Script - Request Modification Tests', () { test('should modify headers correctly', () async { - List? capturedValues; void mockUpdateEnv( EnvironmentModel envModel, List values) { - capturedValues = values; } final result = await handlePreRequestScript(