98 lines
3.4 KiB
Dart
98 lines
3.4 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:ikar/backend/api.dart';
|
|
import 'package:ikar/core/push/fkm_controller.dart';
|
|
import 'package:ikar/core/storage/app_database.dart';
|
|
import 'package:ikar/frontend/screens/profile/notifications_screen.dart';
|
|
import 'package:ikar/frontend/widgets/connection_status.dart';
|
|
import 'package:ikar/l10n/app_localizations.dart';
|
|
import 'package:ikar/l10n/app_localizations_ru.dart';
|
|
import 'package:ikar/main.dart' as app;
|
|
import 'package:path_provider_platform_interface/path_provider_platform_interface.dart';
|
|
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class _Paths extends PathProviderPlatform with MockPlatformInterfaceMixin {
|
|
_Paths(this.path);
|
|
final String path;
|
|
@override
|
|
Future<String?> getApplicationSupportPath() async => path;
|
|
}
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
setUp(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
debugForceOffline.value = false;
|
|
});
|
|
tearDown(() => debugForceOffline.value = false);
|
|
|
|
test(
|
|
'FKM cannot be enabled and a previous enabled state is cleared',
|
|
() async {
|
|
final api = Api();
|
|
addTearDown(api.dispose);
|
|
final fkm = FkmController.instance;
|
|
fkm.enabled.value = true;
|
|
await fkm.init(api);
|
|
expect(fkm.enabled.value, isFalse);
|
|
expect(fkm.isSupported, isFalse);
|
|
expect(await fkm.setEnabled(true), isFalse);
|
|
expect(fkm.enabled.value, isFalse);
|
|
expect(await fkm.setEnabled(false), isTrue);
|
|
},
|
|
);
|
|
|
|
test(
|
|
'all disconnected states say Соединение... and online restores the title',
|
|
() {
|
|
final l10n = AppLocalizationsRu();
|
|
for (final state in [
|
|
SessionState.disconnected,
|
|
SessionState.connecting,
|
|
SessionState.connected,
|
|
]) {
|
|
expect(connectionStatusLabel(l10n, state), 'Соединение...');
|
|
}
|
|
expect(connectionStatusLabel(l10n, SessionState.online), isNull);
|
|
debugForceOffline.value = true;
|
|
expect(connectionStatusLabel(l10n, SessionState.online), 'Соединение...');
|
|
},
|
|
);
|
|
|
|
testWidgets('notification menu has no FKM section or enable switch', (
|
|
tester,
|
|
) async {
|
|
final directory = Directory.systemTemp.createTempSync(
|
|
'ikar_notification_ui',
|
|
);
|
|
PathProviderPlatform.instance = _Paths(directory.path);
|
|
addTearDown(() async {
|
|
await AppDatabase.close();
|
|
directory.deleteSync(recursive: true);
|
|
});
|
|
await AppDatabase.init();
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
locale: const Locale('ru'),
|
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
|
supportedLocales: AppLocalizations.supportedLocales,
|
|
home: const NotificationsScreen(),
|
|
),
|
|
);
|
|
await tester.runAsync(
|
|
() => Future<void>.delayed(const Duration(milliseconds: 100)),
|
|
);
|
|
await tester.pump(const Duration(milliseconds: 300));
|
|
expect(find.text('FKM'), findsNothing);
|
|
expect(find.text('Включить уведомления'), findsNothing);
|
|
expect(find.text('Все уведомления'), findsOneWidget);
|
|
expect(find.text('Соединение...'), findsOneWidget);
|
|
expect(find.text('Ожидание сети...'), findsNothing);
|
|
await tester.pumpWidget(const SizedBox.shrink());
|
|
await app.api.dispose();
|
|
});
|
|
}
|