fix(diary): tests

This commit is contained in:
mso7nueh
2026-04-30 05:55:25 +03:00
parent 9ef9a7289c
commit 86324c9897
12 changed files with 319 additions and 89 deletions

View File

@@ -1,5 +1,8 @@
import 'dart:io';
import 'package:eatvio_app/core/app_initializer.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:shared_preferences/shared_preferences.dart';
@@ -52,6 +55,62 @@ FIREBASE_IOS_BUNDLE_ID=com.test.app
SharedPreferences.setMockInitialValues({});
// Reset service locator before each test
await sl.reset();
// Мокируем нативные каналы, которые не работают в тестовом окружении
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('plugins.flutter.io/path_provider'),
(MethodCall call) async {
if (call.method == 'getTemporaryDirectory' ||
call.method == 'getApplicationDocumentsDirectory' ||
call.method == 'getApplicationSupportDirectory') {
return Directory.systemTemp.path;
}
return null;
},
);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('dev.fluttercommunity.plus/connectivity'),
(MethodCall call) async {
if (call.method == 'check') {
return ['wifi']; // Эмулируем наличие WiFi
}
return null;
},
);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('plugins.flutter.io/path_provider_macos'),
(MethodCall call) async {
if (call.method == 'getTemporaryDirectory' ||
call.method == 'getApplicationDocumentsDirectory' ||
call.method == 'getApplicationSupportDirectory') {
return Directory.systemTemp.path;
}
return null;
},
);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('plugins.flutter.io/path_provider'),
null,
);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('dev.fluttercommunity.plus/connectivity'),
null,
);
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(
const MethodChannel('plugins.flutter.io/path_provider_macos'),
null,
);
});
test('is a class', () {