feat(test): updated tests to increase tests coverage

This commit is contained in:
misha
2026-05-06 14:12:34 +03:00
parent fe243965e3
commit 54c27c28cd
10 changed files with 930 additions and 9 deletions

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

@@ -12,5 +12,28 @@ void main() {
);
// 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,6 +5,7 @@ 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_dotenv/flutter_dotenv.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
@@ -49,6 +50,10 @@ void main() {
'assets/icons/complain.svg': fakeSvg,
});
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'));
@@ -114,4 +119,69 @@ void main() {
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);
});
}