diff --git a/example/integration_test/src/switch_tenant_test.dart b/example/integration_test/src/switch_tenant_test.dart new file mode 100644 index 0000000..3891684 --- /dev/null +++ b/example/integration_test/src/switch_tenant_test.dart @@ -0,0 +1,80 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:frontegg_flutter_example/main.dart'; +import 'package:patrol/patrol.dart'; + +void main() { + late final String email; + late final String password; + late final String tenantId1; + late final String tenantId2; + + late final String tenantName1; + late final String tenantName2; + + patrolSetUp(() { + email = const String.fromEnvironment('LOGIN_EMAIL'); + password = const String.fromEnvironment('LOGIN_PASSWORD'); + + tenantId1 = const String.fromEnvironment('TENANT_ID_1'); + tenantId2 = const String.fromEnvironment('TENANT_ID_2'); + + tenantName1 = const String.fromEnvironment('TENANT_NAME_1'); + tenantName2 = const String.fromEnvironment('TENANT_NAME_2'); + }); + + patrolTest( + 'Success tenant switch', + ($) async { + await $.pumpWidget(const MyApp()); + await $.pumpAndSettle(); + + await $.tap(find.byKey(const ValueKey("LoginButton"))); + await Future.delayed(const Duration(seconds: 5)); + + await $.native.enterTextByIndex( + email, + index: 0, + keyboardBehavior: KeyboardBehavior.alternative, + timeout: const Duration(seconds: 15), + ); + + await $.native.tap(Selector(text: "Continue")); + + await $.native.enterTextByIndex( + password, + index: 1, + keyboardBehavior: KeyboardBehavior.alternative, + timeout: const Duration(seconds: 15), + ); + + await $.native.tap(Selector(text: "Sign in")); + + await $.waitUntilVisible( + find.text("Logout"), + timeout: const Duration(seconds: 15), + ); + + // Switch to Tenant Tab + await $.tap(find.byKey(const ValueKey("TenantTab"))); + await $.pumpAndSettle(); + + //switch tenant 2 + await $.tap(find.byKey(ValueKey(tenantId2))); + await $.pumpAndSettle(); + await $.waitUntilVisible(find.textContaining("$tenantName2 (active)", findRichText: true)); + + //switch tenant 1 + await $.tap(find.byKey(ValueKey(tenantId1))); + await $.pumpAndSettle(); + await $.waitUntilVisible(find.textContaining("$tenantName1 (active)", findRichText: true)); + + // Logout + await $.tap(find.byKey(const ValueKey("ProfileTab"))); + await $.pumpAndSettle(); + + await $.tap(find.byKey(const ValueKey("LogoutButton"))); + await $.pumpAndSettle(); + }, + ); +} diff --git a/example/lib/tenants_tab.dart b/example/lib/tenants_tab.dart index 919fc43..afdf882 100644 --- a/example/lib/tenants_tab.dart +++ b/example/lib/tenants_tab.dart @@ -26,19 +26,27 @@ class TenantsTab extends StatelessWidget { (e) { final isActive = user.activeTenant.tenantId == e.tenantId; return ListTile( - title: Row( - children: [ - Text(e.name), - if (isActive) const SizedBox(width: 10), - if (isActive) - const Text( - "(active)", - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w300, + key: ValueKey(e.tenantId), + title: RichText( + text: TextSpan( + children: [ + TextSpan( + text: e.name, + style: const TextStyle( + color: Colors.black, ), ), - ], + if (isActive) + const TextSpan( + text: " (active)", + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w300, + color: Colors.black, + ), + ), + ], + ), ), onTap: () { frontegg.switchTenant(e.tenantId); diff --git a/example/lib/user_page.dart b/example/lib/user_page.dart index cb6df37..96d984d 100644 --- a/example/lib/user_page.dart +++ b/example/lib/user_page.dart @@ -43,10 +43,12 @@ class _UserPageState extends State { }, items: const [ BottomNavigationBarItem( + key: ValueKey("ProfileTab"), icon: Icon(Icons.person), label: "Profile", ), BottomNavigationBarItem( + key: ValueKey("TenantTab"), icon: Icon(Icons.notifications), label: "Tenant", ),