fix: issue-372, issue-227, issue-406

This commit is contained in:
misha
2026-09-02 09:32:14 +03:00
parent 10af279d87
commit c6ea1d414d
34 changed files with 1623 additions and 387 deletions

View File

@@ -1,10 +1,12 @@
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/my_finance/presentation/pages/card_settings.dart';
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
import 'package:eatvio_app/features/notifications/presentation/widgets/notification_widget.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:go_router/go_router.dart';
void main() {
group('NotificationWidget', () {
@@ -21,13 +23,13 @@ void main() {
supportedLocales: const [Locale('ru'), Locale('en')],
locale: const Locale('ru'),
theme: ThemeHelper().themeData(),
home: Scaffold(
body: NotificationWidget(notification: notification),
),
home: Scaffold(body: NotificationWidget(notification: notification)),
);
}
testWidgets('displays PlanSubscriptionStartedToAuthorNotification', (tester) async {
testWidgets('displays PlanSubscriptionStartedToAuthorNotification', (
tester,
) async {
final notification = PlanSubscriptionStartedToAuthorNotification(
type: NotificationType.planSubscriptionStartedToAuthor,
planName: 'Test Plan',
@@ -47,7 +49,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays PlanSubscriptionCanceledToAuthorNotification', (tester) async {
testWidgets('displays PlanSubscriptionCanceledToAuthorNotification', (
tester,
) async {
final notification = PlanSubscriptionCanceledToAuthorNotification(
type: NotificationType.planSubscriptionCanceledToAuthor,
planName: 'Test Plan',
@@ -66,7 +70,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ChosenPlanStartedToClientNotification', (tester) async {
testWidgets('displays ChosenPlanStartedToClientNotification', (
tester,
) async {
final notification = ChosenPlanStartedToClientNotification(
type: NotificationType.chosenPlanStartedToClient,
planName: 'Test Plan',
@@ -83,7 +89,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ChosenPlanTomorrowReminderToClientNotification', (tester) async {
testWidgets('displays ChosenPlanTomorrowReminderToClientNotification', (
tester,
) async {
final notification = ChosenPlanTomorrowReminderToClientNotification(
type: NotificationType.chosenPlanTomorrowReminderToClient,
planName: 'Test Plan',
@@ -131,7 +139,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays PersonalizedDietIsDefinedNotification', (tester) async {
testWidgets('displays PersonalizedDietIsDefinedNotification', (
tester,
) async {
final notification = PersonalizedDietIsDefinedNotification(
type: NotificationType.personalizedDietIsDefined,
isRead: false,
@@ -144,7 +154,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ChosenPlanFinishedToClientNotification', (tester) async {
testWidgets('displays ChosenPlanFinishedToClientNotification', (
tester,
) async {
final notification = ChosenPlanFinishedToClientNotification(
type: NotificationType.chosenPlanFinishedToClient,
planName: 'Test Plan',
@@ -163,7 +175,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays PlanSubscriptionCanceledToCustomerNotification', (tester) async {
testWidgets('displays PlanSubscriptionCanceledToCustomerNotification', (
tester,
) async {
final notification = PlanSubscriptionCanceledToCustomerNotification(
type: NotificationType.planSubscriptionCanceledToCustomer,
planName: 'Test Plan',
@@ -182,7 +196,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ChosenPlanStartedToConsultantNotification', (tester) async {
testWidgets('displays ChosenPlanStartedToConsultantNotification', (
tester,
) async {
final notification = ChosenPlanStartedToConsultantNotification(
type: NotificationType.chosenPlanStartedToConsultant,
planName: 'Test Plan',
@@ -201,7 +217,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ChosenPlanTomorrowReminderToConsultantNotification', (tester) async {
testWidgets('displays ChosenPlanTomorrowReminderToConsultantNotification', (
tester,
) async {
final notification = ChosenPlanTomorrowReminderToConsultantNotification(
type: NotificationType.chosenPlanTomorrowReminderToConsultant,
planName: 'Test Plan',
@@ -217,7 +235,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays PlanSubscriptionPaidToAuthorNotification', (tester) async {
testWidgets('displays PlanSubscriptionPaidToAuthorNotification', (
tester,
) async {
final notification = PlanSubscriptionPaidToAuthorNotification(
type: NotificationType.planSubscriptionPaidToAuthor,
planName: 'Test Plan',
@@ -236,24 +256,86 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ChosenPlanFinishedToConsultantNotification with button', (tester) async {
final notification = ChosenPlanFinishedToConsultantNotification(
type: NotificationType.chosenPlanFinishedToConsultant,
planName: 'Test Plan',
customerName: 'Test Customer',
planId: 1,
chosenPlanId: 1,
clientPhotoPath: '',
clientId: 0,
isRead: false,
createdAt: testDate,
);
testWidgets(
'displays ChosenPlanFinishedToConsultantNotification with button',
(tester) async {
final notification = ChosenPlanFinishedToConsultantNotification(
type: NotificationType.chosenPlanFinishedToConsultant,
planName: 'Test Plan',
customerName: 'Test Customer',
planId: 1,
chosenPlanId: 1,
clientPhotoPath: '',
clientId: 0,
isRead: false,
createdAt: testDate,
);
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
expect(find.byType(NotificationWidget), findsOneWidget);
});
expect(find.byType(NotificationWidget), findsOneWidget);
expect(find.text('Получить выплату'), findsOneWidget);
},
);
testWidgets(
'collect charge from finished notification uses chosenPlanId, not planId',
(tester) async {
int? capturedChosenPlanId;
final notification = ChosenPlanFinishedToConsultantNotification(
type: NotificationType.chosenPlanFinishedToConsultant,
planName: 'Test Plan',
customerName: 'Test Customer',
planId: 99,
chosenPlanId: 42,
clientPhotoPath: '',
clientId: 0,
isRead: false,
createdAt: testDate,
);
final router = GoRouter(
routes: [
GoRoute(
path: '/',
builder: (context, state) => Scaffold(
body: NotificationWidget(notification: notification),
),
),
GoRoute(
path: CardSettingsScreen.path,
builder: (context, state) {
capturedChosenPlanId = state.extra as int?;
return const Scaffold(body: Text('card-settings'));
},
),
],
);
await tester.pumpWidget(
MaterialApp.router(
localizationsDelegates: const [
S.delegate,
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [Locale('ru'), Locale('en')],
locale: const Locale('ru'),
theme: ThemeHelper().themeData(),
routerConfig: router,
),
);
await tester.pumpAndSettle();
await tester.tap(find.text('Получить выплату'));
await tester.pumpAndSettle();
expect(find.text('card-settings'), findsOneWidget);
expect(capturedChosenPlanId, 42);
},
);
testWidgets('displays ChosenPlanLastDayFinishedForUser', (tester) async {
final notification = ChosenPlanLastDayFinishedForUser(
@@ -587,7 +669,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays PersonalDietCreationNeededNotification', (tester) async {
testWidgets('displays PersonalDietCreationNeededNotification', (
tester,
) async {
final notification = PersonalDietCreationNeededNotification(
type: NotificationType.personalDietCreationNeeded,
userName: 'Test Client',
@@ -603,7 +687,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ChosenPlanClientLastDayFinishedNotification', (tester) async {
testWidgets('displays ChosenPlanClientLastDayFinishedNotification', (
tester,
) async {
final notification = ChosenPlanClientLastDayFinishedNotification(
type: NotificationType.chosenPlanClientLastDayFinished,
planName: 'Test Plan',
@@ -620,7 +706,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ChosenPlanClientLastDayStartedNotification', (tester) async {
testWidgets('displays ChosenPlanClientLastDayStartedNotification', (
tester,
) async {
final notification = ChosenPlanClientLastDayStartedNotification(
type: NotificationType.chosenPlanClientLastDayStarted,
planName: 'Test Plan',
@@ -653,47 +741,58 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ClientStartPlanSubscriptionToSubscriberNotification', (tester) async {
final notification = ClientStartPlanSubscriptionToSubscriberNotification(
type: NotificationType.clientStartPlanSubscriptionToSubscriber,
planName: 'Test Plan',
planId: 1,
authorName: '',
authorId: 0,
authorPhotoPath: '',
chatUrl: '',
chatId: '',
startDate: '',
isRead: false,
createdAt: testDate,
);
testWidgets(
'displays ClientStartPlanSubscriptionToSubscriberNotification',
(tester) async {
final notification =
ClientStartPlanSubscriptionToSubscriberNotification(
type: NotificationType.clientStartPlanSubscriptionToSubscriber,
planName: 'Test Plan',
planId: 1,
authorName: '',
authorId: 0,
authorPhotoPath: '',
chatUrl: '',
chatId: '',
startDate: '',
isRead: false,
createdAt: testDate,
);
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
expect(find.byType(NotificationWidget), findsOneWidget);
});
expect(find.byType(NotificationWidget), findsOneWidget);
},
);
testWidgets('displays ConsultantConfirmPlanSubscriptionToSubscriberNotification', (tester) async {
final notification = ConsultantConfirmPlanSubscriptionToSubscriberNotification(
type: NotificationType.consultantConfirmPlanSubscriptionToSubscriber,
planName: 'Test Plan',
planId: 1,
consultantName: 'Test Consultant',
authorId: 0,
authorPhotoPath: '',
chatUrl: '',
isRead: false,
createdAt: testDate,
);
testWidgets(
'displays ConsultantConfirmPlanSubscriptionToSubscriberNotification',
(tester) async {
final notification =
ConsultantConfirmPlanSubscriptionToSubscriberNotification(
type: NotificationType
.consultantConfirmPlanSubscriptionToSubscriber,
planName: 'Test Plan',
planId: 1,
consultantName: 'Test Consultant',
authorId: 0,
authorPhotoPath: '',
chatUrl: '',
isRead: false,
createdAt: testDate,
);
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
expect(find.byType(NotificationWidget), findsOneWidget);
});
expect(find.byType(NotificationWidget), findsOneWidget);
},
);
testWidgets('displays ClientPaidPlanSubscriptionToAuthorNotification', (tester) async {
testWidgets('displays ClientPaidPlanSubscriptionToAuthorNotification', (
tester,
) async {
final notification = ClientPaidPlanSubscriptionToAuthorNotification(
type: NotificationType.clientPaidPlanSubscriptionToAuthor,
planName: 'Test Plan',
@@ -712,7 +811,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ConsultantLeftDiaryCommentNotification', (tester) async {
testWidgets('displays ConsultantLeftDiaryCommentNotification', (
tester,
) async {
final notification = ConsultantLeftDiaryCommentNotification(
type: NotificationType.consultantLeftDiaryComment,
chosenPlanId: 1,
@@ -731,26 +832,32 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ConsultantConfirmPlanSubscriptionToAuthorNotification', (tester) async {
final notification = ConsultantConfirmPlanSubscriptionToAuthorNotification(
type: NotificationType.consultantConfirmPlanSubscriptionToAuthor,
planName: 'Test Plan',
planId: 1,
clientName: 'Test Consultant',
userId: 0,
userPhotoPath: '',
chatUrl: '',
isRead: false,
createdAt: testDate,
);
testWidgets(
'displays ConsultantConfirmPlanSubscriptionToAuthorNotification',
(tester) async {
final notification =
ConsultantConfirmPlanSubscriptionToAuthorNotification(
type: NotificationType.consultantConfirmPlanSubscriptionToAuthor,
planName: 'Test Plan',
planId: 1,
clientName: 'Test Consultant',
userId: 0,
userPhotoPath: '',
chatUrl: '',
isRead: false,
createdAt: testDate,
);
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
expect(find.byType(NotificationWidget), findsOneWidget);
});
expect(find.byType(NotificationWidget), findsOneWidget);
},
);
testWidgets('displays ClientPaidPlanSubscriptionToSubscriberNotification', (tester) async {
testWidgets('displays ClientPaidPlanSubscriptionToSubscriberNotification', (
tester,
) async {
final notification = ClientPaidPlanSubscriptionToSubscriberNotification(
type: NotificationType.clientPaidPlanSubscriptionToSubscriber,
planName: 'Test Plan',
@@ -769,7 +876,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ClientStartPlanSubscriptionToAuthorNotification', (tester) async {
testWidgets('displays ClientStartPlanSubscriptionToAuthorNotification', (
tester,
) async {
final notification = ClientStartPlanSubscriptionToAuthorNotification(
type: NotificationType.clientStartPlanSubscriptionToAuthor,
planName: 'Test Plan',
@@ -789,7 +898,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ClientCancelPlanSubscriptionToAuthorNotification', (tester) async {
testWidgets('displays ClientCancelPlanSubscriptionToAuthorNotification', (
tester,
) async {
final notification = ClientCancelPlanSubscriptionToAuthorNotification(
type: NotificationType.clientCancelPlanSubscriptionToAuthor,
planName: 'Test Plan',
@@ -808,26 +919,32 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ClientCancelPlanSubscriptionToSubscriberNotification', (tester) async {
final notification = ClientCancelPlanSubscriptionToSubscriberNotification(
type: NotificationType.clientCancelPlanSubscriptionToSubscriber,
planName: 'Test Plan',
planId: 1,
authorName: '',
authorId: 0,
authorPhotoPath: '',
chatUrl: '',
isRead: false,
createdAt: testDate,
);
testWidgets(
'displays ClientCancelPlanSubscriptionToSubscriberNotification',
(tester) async {
final notification =
ClientCancelPlanSubscriptionToSubscriberNotification(
type: NotificationType.clientCancelPlanSubscriptionToSubscriber,
planName: 'Test Plan',
planId: 1,
authorName: '',
authorId: 0,
authorPhotoPath: '',
chatUrl: '',
isRead: false,
createdAt: testDate,
);
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
expect(find.byType(NotificationWidget), findsOneWidget);
});
expect(find.byType(NotificationWidget), findsOneWidget);
},
);
testWidgets('displays UserDailyReportCompletedNotification', (tester) async {
testWidgets('displays UserDailyReportCompletedNotification', (
tester,
) async {
final notification = UserDailyReportCompletedNotification(
type: NotificationType.userDailyReportCompleted,
chosenPlanId: 1,
@@ -924,7 +1041,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ConsultantRequestStartedNotification', (tester) async {
testWidgets('displays ConsultantRequestStartedNotification', (
tester,
) async {
final notification = ConsultantRequestStartedNotification(
type: NotificationType.consultantRequestStarted,
consultantName: 'Test Consultant',
@@ -938,7 +1057,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ClientCloseComplaintSuccessNotification', (tester) async {
testWidgets('displays ClientCloseComplaintSuccessNotification', (
tester,
) async {
final notification = ClientCloseComplaintSuccessNotification(
type: NotificationType.clientCloseComplaintSuccess,
planName: 'Test Plan',
@@ -1032,7 +1153,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays ProductStatusUpdatedForAuthorNotification', (tester) async {
testWidgets('displays ProductStatusUpdatedForAuthorNotification', (
tester,
) async {
final notification = ProductStatusUpdatedForAuthorNotification(
type: NotificationType.productStatusUpdatedForAuthor,
productName: 'Test Product',
@@ -1065,7 +1188,9 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays PersonalDietIsDefinedToCustomerNotification', (tester) async {
testWidgets('displays PersonalDietIsDefinedToCustomerNotification', (
tester,
) async {
final notification = PersonalDietIsDefinedToCustomerNotification(
type: NotificationType.personalDietIsDefinedToCustomer,
isRead: false,
@@ -1128,35 +1253,3 @@ void main() {
});
});
}