flutter-freaccess-hub/integration_test/locals_test.dart

168 lines
5.0 KiB
Dart

part of 'app_test.dart';
class LocalsTest {
static Future setLocal() async {
patrolWidgetTest(
'Selecionar um local disponível', //
(PatrolTester tester) async {
$ = tester;
await _logged();
await $.pumpWidget(const App());
await $.pumpAndSettle();
final Finder profileFinder =
find.byKey(const Key('AsyncLocalProfileComponentWidget_InkWell'));
expect(profileFinder, findsOneWidget);
await $.tap(profileFinder);
await $.pump(const Duration(seconds: 1));
final Finder bottomSheetFinder =
find.byType(BottomArrowLinkedLocalsComponentWidget);
expect(bottomSheetFinder, findsOneWidget);
await $.pump(const Duration(seconds: 1));
final Finder listViewFinder = find.descendant(
of: bottomSheetFinder,
matching: find.byType(ListView),
);
expect(listViewFinder, findsOneWidget);
await $.pump(const Duration(seconds: 1));
final Finder entriesFinder = find.descendant(
of: listViewFinder,
matching: find.byType(CardItemTemplateComponentWidget),
);
expect(entriesFinder, findsWidgets);
if (entriesFinder.evaluate().isNotEmpty) {
await $.tap(entriesFinder.first);
await $.pumpAndSettle();
}
await Future.delayed(const Duration(milliseconds: 500));
return;
},
);
}
static Future unlinkLocal() async {
patrolWidgetTest('Desvincular do local selecionado', //
(PatrolTester tester) async {
$ = tester;
await _logged();
await $.pumpWidget(const App());
await $.pumpAndSettle();
await $.pump(const Duration(seconds: 1));
final Finder gridView = find.byType(GridView);
final Finder entries = find.descendant(
of: gridView,
matching: find.byType(ButtonMenuItem),
);
await $.pumpAndSettle();
expect(entries, findsWidgets);
final Finder settings = find.descendant(
of: gridView,
matching: find.byIcon(Icons.settings),
);
expect(settings, findsOneWidget);
await $.tap(settings);
await $.pumpAndSettle();
final Finder unlinkButton = find.byIcon(Symbols.digital_out_of_home);
expect(unlinkButton, findsOneWidget);
await $.tap(unlinkButton);
await $.pumpAndSettle();
await $.tap(find.text('Sim'));
await $.pump();
await $.pump(const Duration(seconds: 1));
await $.pump();
final Finder bottomSheetFinder =
find.byType(BottomArrowLinkedLocalsComponentWidget);
await $.pump(const Duration(seconds: 1));
expect(bottomSheetFinder, findsOneWidget);
await $.pump(const Duration(seconds: 1));
await $.pump(const Duration(seconds: 1));
final Finder listViewFinder = find.descendant(
of: bottomSheetFinder,
matching: find.byType(ListView),
);
expect(listViewFinder, findsOneWidget);
await $.pump(const Duration(seconds: 1));
final Finder entriesFinder = find.descendant(
of: listViewFinder,
matching: find.byType(CardItemTemplateComponentWidget),
);
expect(entriesFinder, findsWidgets);
await Future.delayed(const Duration(milliseconds: 500));
return;
});
patrolWidgetTest(
'Desvincular de um local já desvinculado', //
(PatrolTester tester) async {
$ = tester;
await $.pumpWidget(const App());
try {
await $.pumpAndSettle(
// const Duration(seconds: 2),
// EnginePhase.sendSemanticsUpdate,
// const Duration(seconds: 2),
);
throw Exception('Local está vinculado');
} catch (e) {
await Future.delayed(const Duration(milliseconds: 500));
return;
}
},
);
}
static Future attachLocal() async {
patrolWidgetTest(
'Selecionar um local disponível', //
(PatrolTester tester) async {
$ = tester;
await _logged();
await $.pumpWidget(const App());
late Map<String, String> credentials;
final PatrolFinder throwsException = $('');
var name = ff.randomString(7, 7, true, true, true);
var email = '$name@example.com';
var password = '12345678';
credentials = {
'nameTextFormField': name,
'emailTextFormField': email,
'passwordTextFormField': password
};
await $.pumpWidget(const App());
await _navigateToSignUp($);
await _auth(credentials, $, throwsException);
credentials = {
'emailTextFormField': email,
'passwordTextFormField': password
};
await _auth(credentials, $, throwsException);
await $.pumpAndSettle();
await StorageHelper() //
.set(ProfileStorageKey.clientUUID.key, '7');
await $.pumpAndSettle();
await Future.delayed(const Duration(milliseconds: 500));
return;
},
);
}
}