Files
IKAR/test/app_lock_layer_test.dart
T
sevenhill 0508b70732
Build Android (FCM) / build-android-fcm (push) Canceled after 0s
Build Android / build-android (push) Canceled after 0s
Build iOS / build-ios (push) Canceled after 0s
Build Linux / build-linux (push) Canceled after 0s
Build macOS / build-macos (push) Canceled after 0s
Build Windows / build-windows (push) Canceled after 0s
Native crypto / native-crypto (push) Canceled after 0s
Release (main) / android (oneme) (push) Canceled after 0s
Release (main) / android (qlyra) (push) Canceled after 0s
Release (main) / windows (push) Canceled after 0s
Release (main) / linux (push) Canceled after 0s
Release (main) / macos (push) Canceled after 0s
Release (main) / ios (push) Canceled after 0s
Tests / test (push) Canceled after 0s
Release (main) / release (push) Canceled after 0s
Release IKAR 1.0.8: fix incoming calls, cancellation and call history
2026-10-08 21:34:15 +03:00

91 lines
3.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:ikar/core/security/app_lock.dart';
import 'package:ikar/frontend/screens/lock/app_lock_layer.dart';
import 'package:ikar/frontend/screens/lock/passcode_pad.dart';
import 'package:ikar/l10n/app_localizations.dart';
import 'package:shared_preferences/shared_preferences.dart';
Future<void> _pumpApp(WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
locale: const Locale('ru'),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
builder: (context, child) => AppLockLayer(child: child!),
home: const Scaffold(body: Center(child: Text('synthetic chats'))),
),
);
}
Future<void> _enter(WidgetTester tester, String pin) async {
for (final digit in pin.split('')) {
await tester.tap(find.text(digit));
await tester.pump();
}
// Wait for password verification, which can take longer under build load.
for (var attempt = 0; attempt < 100; attempt++) {
final keypad = find.byType(PasscodeKeypad);
if (keypad.evaluate().isEmpty ||
tester.widget<PasscodeKeypad>(keypad).enabled) {
break;
}
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 50)),
);
await tester.pump();
}
await tester.pumpAndSettle();
}
void main() {
final lock = AppLock.instance;
setUp(() async {
SharedPreferences.setMockInitialValues({});
FlutterSecureStorage.setMockInitialValues({});
await lock.load();
});
tearDown(() async {
await lock.disable();
});
testWidgets('cold start hides chats on the very first locked frame', (
tester,
) async {
SharedPreferences.setMockInitialValues({'app_lock_enabled': true});
await tester.runAsync(lock.load);
await _pumpApp(tester);
expect(find.text('Введите код-пароль'), findsOneWidget);
expect(find.text('synthetic chats'), findsNothing);
expect(find.text('synthetic chats', skipOffstage: false), findsOneWidget);
expect(lock.locked.value, isTrue);
});
testWidgets('locking covers the app and the passcode opens it again', (
tester,
) async {
await tester.runAsync(() => lock.setPin('1357'));
await _pumpApp(tester);
expect(find.text('Введите код-пароль'), findsNothing);
lock.lock(origin: const Rect.fromLTWH(300, 20, 24, 24));
await tester.pumpAndSettle();
expect(find.text('Введите код-пароль'), findsOneWidget);
expect(find.text('synthetic chats'), findsNothing);
expect(find.text('synthetic chats', skipOffstage: false), findsOneWidget);
await _enter(tester, '1111');
expect(lock.locked.value, isTrue);
expect(find.textContaining('Осталось попыток: 4'), findsOneWidget);
await _enter(tester, '1357');
expect(lock.locked.value, isFalse);
expect(find.text('Введите код-пароль'), findsNothing);
expect(find.text('synthetic chats'), findsOneWidget);
});
}