Skip to content

Commit

Permalink
FR-18979: Added switch_tenant_test.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-minaiev-frontegg committed Dec 12, 2024
1 parent 7567345 commit 7fd60cd
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 11 deletions.
80 changes: 80 additions & 0 deletions example/integration_test/src/switch_tenant_test.dart
Original file line number Diff line number Diff line change
@@ -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();
},
);
}
30 changes: 19 additions & 11 deletions example/lib/tenants_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions example/lib/user_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ class _UserPageState extends State<UserPage> {
},
items: const [
BottomNavigationBarItem(
key: ValueKey("ProfileTab"),
icon: Icon(Icons.person),
label: "Profile",
),
BottomNavigationBarItem(
key: ValueKey("TenantTab"),
icon: Icon(Icons.notifications),
label: "Tenant",
),
Expand Down

0 comments on commit 7fd60cd

Please sign in to comment.