syn with upstream (#985)

Co-authored-by: misha <mikhail_zakharov_15482356@mail.ru>
Co-authored-by: misha <misha@noreply.localhost>
Reviewed-on: eatvio/eatvio_app#985
This commit is contained in:
2026-05-27 18:37:17 +00:00
parent 5d86b7c71b
commit 204a55917a
66 changed files with 3976 additions and 105 deletions

View File

@@ -110,5 +110,92 @@ void main() {
final event = SentryEvent(throwable: const SocketException('x'));
expect(ErrorReportPolicy.allowSentryEvent(event, hint), false);
});
test('allows event when throwable is null', () {
expect(ErrorReportPolicy.allowSentryEvent(SentryEvent(), hint), true);
});
test('delegates non-Dio throwable to shouldReport', () {
final event = SentryEvent(throwable: StateError('x'));
expect(ErrorReportPolicy.allowSentryEvent(event, hint), true);
});
test('drops cancelled Dio from SDK', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.cancel,
);
expect(ErrorReportPolicy.allowSentryEvent(SentryEvent(throwable: e), hint), false);
});
test('drops sendTimeout Dio from SDK', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.sendTimeout,
);
expect(ErrorReportPolicy.allowSentryEvent(SentryEvent(throwable: e), hint), false);
});
test('drops receiveTimeout Dio from SDK', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.receiveTimeout,
);
expect(ErrorReportPolicy.allowSentryEvent(SentryEvent(throwable: e), hint), false);
});
test('allows badResponse Dio from SDK when statusCode is missing', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.badResponse,
);
expect(ErrorReportPolicy.allowSentryEvent(SentryEvent(throwable: e), hint), true);
});
});
group('ErrorReportPolicy.shouldReport extra Dio branches', () {
test('returns true for Dio unknown when inner error is not SocketException', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.unknown,
error: 'not a socket',
);
expect(ErrorReportPolicy.shouldReport(e), true);
});
test('returns false for Dio unknown when inner error is SocketException', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.unknown,
error: const SocketException('offline'),
);
expect(ErrorReportPolicy.shouldReport(e), false);
});
test('returns true for badCertificate when inner error is not SocketException', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.badCertificate,
error: 'cert problem',
);
expect(ErrorReportPolicy.shouldReport(e), true);
});
test('returns false for badCertificate when inner error is SocketException', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.badCertificate,
error: const SocketException('bad'),
);
expect(ErrorReportPolicy.shouldReport(e), false);
});
test('returns true for badResponse without HTTP status', () {
final e = DioException(
requestOptions: RequestOptions(path: '/x'),
type: DioExceptionType.badResponse,
);
expect(ErrorReportPolicy.shouldReport(e), true);
});
});
}

View File

@@ -0,0 +1,36 @@
import 'package:eatvio_app/core/error_reporting/error_reporter.dart';
import 'package:eatvio_app/core/error_reporting/no_op_error_reporter.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('NoOpErrorReporter', () {
test('is an ErrorReporter', () {
const reporter = NoOpErrorReporter();
expect(reporter, isA<ErrorReporter>());
});
test('report completes silently with all parameters', () async {
const reporter = NoOpErrorReporter();
await reporter.report(
StateError('boom'),
StackTrace.current,
origin: 'unit',
extras: <String, Object?>{'a': 1, 'b': null},
);
});
test('report completes silently without optional parameters', () async {
const reporter = NoOpErrorReporter();
await reporter.report(Exception('x'), null);
});
test('multiple sequential reports do not throw', () async {
const reporter = NoOpErrorReporter();
for (var i = 0; i < 5; i++) {
await reporter.report('error $i', StackTrace.empty, origin: 'loop');
}
});
});
}

View File

@@ -0,0 +1,55 @@
import 'package:eatvio_app/core/error_reporting/error_reporter.dart';
import 'package:eatvio_app/core/error_reporting/report_from.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:flutter_test/flutter_test.dart';
class _RecordingReporter implements ErrorReporter {
Object? lastError;
StackTrace? lastStack;
String? lastOrigin;
@override
Future<void> report(
Object error,
StackTrace? stackTrace, {
String? origin,
Map<String, Object?>? extras,
}) async {
lastError = error;
lastStack = stackTrace;
lastOrigin = origin;
}
}
class _OriginMarker {}
void main() {
late _RecordingReporter reporter;
setUp(() async {
await sl.reset();
reporter = _RecordingReporter();
sl.registerSingleton<ErrorReporter>(reporter);
});
tearDown(() async {
await sl.reset();
});
test('reportFrom forwards to registered ErrorReporter with origin from context runtimeType', () async {
final err = StateError('bad');
final st = StackTrace.current;
await reportFrom(err, st, _OriginMarker());
expect(reporter.lastError, same(err));
expect(reporter.lastStack, st);
expect(reporter.lastOrigin, '_OriginMarker');
});
test('reportFrom completes when ErrorReporter is not registered (NoOp path)', () async {
await sl.reset();
await reportFrom(Exception('x'), null, Object());
});
}

View File

@@ -0,0 +1,39 @@
import 'package:eatvio_app/core/error_reporting/sentry_error_reporter.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('SentryErrorReporter', () {
test('report returns immediately when ErrorReportPolicy filters the error', () async {
final reporter = SentryErrorReporter();
await reporter.report(
'user-facing string',
StackTrace.empty,
origin: 'unit',
);
// Does not throw; policy drops String errors before Sentry.
});
test('report accepts non-filtered exception with origin and extras', () async {
final reporter = SentryErrorReporter();
await reporter.report(
StateError('boom'),
StackTrace.current,
origin: 'cubit',
extras: <String, Object?>{
'id': 42,
'nullable': null,
},
);
});
test('report accepts non-filtered exception without optional metadata', () async {
final reporter = SentryErrorReporter();
await reporter.report(
ArgumentError('bad'),
StackTrace.empty,
);
});
});
}

View File

@@ -5,24 +5,64 @@ import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/custom_popup.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
class _FakeAssetBundle extends CachingAssetBundle {
_FakeAssetBundle(this.assets);
final Map<String, String> assets;
@override
Future<String> loadString(String key, {bool cache = true}) async {
final value = assets[key];
if (value == null) {
throw FlutterError('Asset not found: $key');
}
return value;
}
@override
Future<ByteData> load(String key) async {
final value = assets[key];
if (value == null) {
throw FlutterError('Asset not found: $key');
}
final bytes = Uint8List.fromList(value.codeUnits);
return ByteData.sublistView(bytes);
}
}
void main() {
group('CustomPopup smoke', () {
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
const fakeSvg = '''
<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10" viewBox="0 0 10 10">
<rect width="10" height="10" fill="red"/>
</svg>
''';
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
});
final fakeBundle = _FakeAssetBundle({
'assets/icons/copy2.svg': fakeSvg,
'assets/icons/share2.svg': fakeSvg,
'assets/icons/edit_paint.svg': fakeSvg,
'assets/icons/red_trash.svg': fakeSvg,
'assets/icons/complain.svg': fakeSvg,
});
Widget wrap(Widget child) {
return MaterialApp(
setUpAll(() async {
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
});
setUp(() async {
await sl.reset();
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
});
Widget wrap(Widget child) {
return DefaultAssetBundle(
bundle: fakeBundle,
child: MaterialApp(
theme: ThemeHelper().themeData(),
localizationsDelegates: const [
S.delegate,
@@ -31,87 +71,117 @@ void main() {
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: S.delegate.supportedLocales,
home: Scaffold(body: child),
);
}
home: Scaffold(body: Center(child: child)),
),
);
}
testWidgets('renders custom popup for author', (tester) async {
await tester.pumpWidget(wrap(const CustomPopup(isAuthor: true, path: 'test/path', userSlug: 'test-user')));
await tester.pump();
expect(find.byType(CustomPopup), findsOneWidget);
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
});
testWidgets('CustomPopup for author shows edit and delete actions for posts', (tester) async {
await tester.pumpWidget(
wrap(
const CustomPopup(
isAuthor: true,
complainedContentType: ComplainedContent.posts,
path: 'posts/1',
id: 1,
userSlug: 'author',
),
),
);
testWidgets('renders custom popup for non-author', (tester) async {
await tester.pumpWidget(
wrap(const CustomPopup(isAuthor: false, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.posts)),
);
await tester.pump();
expect(find.byType(CustomPopup), findsOneWidget);
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
});
await tester.tap(find.byIcon(Icons.more_horiz_rounded));
await tester.pumpAndSettle();
testWidgets('renders custom popup for non-author with recipe', (tester) async {
await tester.pumpWidget(
wrap(const CustomPopup(isAuthor: false, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.recipe)),
);
await tester.pump();
expect(find.byType(CustomPopup), findsOneWidget);
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
});
testWidgets('renders custom popup for non-author with diet', (tester) async {
await tester.pumpWidget(
wrap(const CustomPopup(isAuthor: false, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.diet)),
);
await tester.pump();
expect(find.byType(CustomPopup), findsOneWidget);
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
});
testWidgets('renders custom popup for non-author with plan', (tester) async {
await tester.pumpWidget(
wrap(const CustomPopup(isAuthor: false, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.plan)),
);
await tester.pump();
expect(find.byType(CustomPopup), findsOneWidget);
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
});
testWidgets('renders custom popup for author with posts', (tester) async {
await tester.pumpWidget(
wrap(const CustomPopup(isAuthor: true, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.posts)),
);
await tester.pump();
expect(find.byType(CustomPopup), findsOneWidget);
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
});
testWidgets('renders custom popup for author with recipe', (tester) async {
await tester.pumpWidget(
wrap(const CustomPopup(isAuthor: true, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.recipe, slug: 'test-recipe')),
);
await tester.pump();
expect(find.byType(CustomPopup), findsOneWidget);
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
});
testWidgets('renders custom popup for author with diet', (tester) async {
await tester.pumpWidget(
wrap(const CustomPopup(isAuthor: true, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.diet, id: 1)),
);
await tester.pump();
expect(find.byType(CustomPopup), findsOneWidget);
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
});
testWidgets('renders custom popup for author with plan', (tester) async {
await tester.pumpWidget(
wrap(const CustomPopup(isAuthor: true, path: 'test/path', userSlug: 'test-user', complainedContentType: ComplainedContent.plan, slug: 'test-plan')),
);
await tester.pump();
expect(find.byType(CustomPopup), findsOneWidget);
expect(find.byIcon(Icons.more_horiz_rounded), findsOneWidget);
});
expect(find.text('Скопировать ссылку'), findsOneWidget);
expect(find.text('Поделиться'), findsOneWidget);
expect(find.text('Редактировать'), findsOneWidget);
expect(find.text('Удалить'), findsOneWidget);
});
testWidgets('CustomPopup for non-author shows complain and block actions', (tester) async {
await tester.pumpWidget(
wrap(
const CustomPopup(
isAuthor: false,
complainedContentType: ComplainedContent.recipe,
path: 'recipes/slug',
slug: 'slug',
userSlug: 'user-2',
),
),
);
await tester.tap(find.byIcon(Icons.more_horiz_rounded));
await tester.pumpAndSettle();
expect(find.text('Скопировать ссылку'), findsOneWidget);
expect(find.text('Поделиться'), findsOneWidget);
expect(find.text('Пожаловаться'), findsOneWidget);
expect(find.text('Заблокировать автора'), findsOneWidget);
});
testWidgets('CustomPopup for author recipe does not show edit action', (tester) async {
await tester.pumpWidget(
wrap(
const CustomPopup(
isAuthor: true,
complainedContentType: ComplainedContent.recipe,
path: 'recipes/slug',
slug: 'slug',
userSlug: 'author',
),
),
);
await tester.tap(find.byIcon(Icons.more_horiz_rounded));
await tester.pumpAndSettle();
expect(find.text('Скопировать ссылку'), findsOneWidget);
expect(find.text('Поделиться'), findsOneWidget);
expect(find.text('Редактировать'), findsNothing);
expect(find.text('Удалить'), findsOneWidget);
});
testWidgets('CustomPopup for author plan does not show edit action', (tester) async {
await tester.pumpWidget(
wrap(
const CustomPopup(
isAuthor: true,
complainedContentType: ComplainedContent.plan,
path: 'plans/slug',
slug: 'slug',
userSlug: 'author',
),
),
);
await tester.tap(find.byIcon(Icons.more_horiz_rounded));
await tester.pumpAndSettle();
expect(find.text('Редактировать'), findsNothing);
expect(find.text('Удалить'), findsOneWidget);
});
testWidgets('CustomPopup for non-author without complained type still renders static actions', (tester) async {
await tester.pumpWidget(
wrap(
const CustomPopup(
isAuthor: false,
complainedContentType: null,
path: 'posts/slug',
slug: 'slug',
userSlug: 'user-2',
),
),
);
await tester.tap(find.byIcon(Icons.more_horiz_rounded));
await tester.pumpAndSettle();
expect(find.text('Скопировать ссылку'), findsOneWidget);
expect(find.text('Поделиться'), findsOneWidget);
expect(find.text('Пожаловаться'), findsOneWidget);
expect(find.text('Заблокировать автора'), findsOneWidget);
});
}