yubioath-flutter/integration_test/test_util.dart

62 lines
1.7 KiB
Dart
Raw Normal View History

2022-05-12 16:35:14 +03:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
2022-05-12 16:35:14 +03:00
import 'package:yubico_authenticator/android/init.dart' as android;
import 'package:yubico_authenticator/app/views/device_button.dart';
2022-05-12 16:35:14 +03:00
import 'package:yubico_authenticator/core/state.dart';
import 'package:yubico_authenticator/desktop/init.dart' as desktop;
import 'android/util.dart';
2022-05-12 16:35:14 +03:00
Future<Widget> getAuthenticatorApp() async => isDesktop
? await desktop.initialize([])
: isAndroid
? await android.initialize()
: throw UnimplementedError('Platform not supported');
2022-09-12 07:34:49 +03:00
const shortestWaitMs = 10;
const shortWaitMs = 50;
const longWaitMs = 200;
const veryLongWaitS = 10; // seconds
extension AppWidgetTester on WidgetTester {
Future<void> shortestWait() async {
await pump(const Duration(milliseconds: shortestWaitMs));
}
Future<void> shortWait() async {
await pump(const Duration(milliseconds: shortWaitMs));
}
Future<void> longWait() async {
await pump(const Duration(milliseconds: longWaitMs));
}
Future<void> veryLongWait() async {
await pump(const Duration(seconds: veryLongWaitS));
}
/// Taps the device button
Future<void> tapDeviceButton() async {
await tap(find.byType(DeviceButton).hitTestable());
await pump(const Duration(milliseconds: 500));
}
Future<void> startUp([Map<dynamic, dynamic>? startUpParams]) async {
if (isAndroid) {
return AndroidTestUtils.startUp(this, startUpParams);
} else {
2022-09-12 08:01:10 +03:00
/// desktop
return await pumpWidget(
await getAuthenticatorApp(), const Duration(milliseconds: 2000));
}
}
2022-09-12 07:34:49 +03:00
void testLog(bool quiet, String message) {
if (!quiet) {
printToConsole(message);
}
}
}