forked from eatvio/eatvio_app
fix: issue-372, issue-227, issue-406
This commit is contained in:
36
test/core/utils/inline_svg_css_test.dart
Normal file
36
test/core/utils/inline_svg_css_test.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'package:eatvio_app/core/utils/inline_svg_css.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('inlineSvgCss', () {
|
||||
test(
|
||||
'inlines class fills from a style block so flutter_svg can paint colors',
|
||||
() {
|
||||
const svg = '''
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 40 40">
|
||||
<style type="text/css">
|
||||
.st0{fill:#FFD200;}
|
||||
.st1{fill:#FFFFFF;}
|
||||
</style>
|
||||
<circle class="st0" cx="20" cy="20" r="18"/>
|
||||
<path class="st1" d="M10 20h20"/>
|
||||
</svg>
|
||||
''';
|
||||
|
||||
final result = inlineSvgCss(svg);
|
||||
|
||||
expect(result, isNot(contains('<style')));
|
||||
expect(result, contains('fill="#FFD200"'));
|
||||
expect(result, contains('fill="#FFFFFF"'));
|
||||
expect(result, isNot(contains('class="st0"')));
|
||||
},
|
||||
);
|
||||
|
||||
test('keeps SVG without style blocks unchanged', () {
|
||||
const svg =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg"><circle fill="#00AA00" cx="10" cy="10" r="5"/></svg>';
|
||||
|
||||
expect(inlineSvgCss(svg), svg);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -128,6 +128,15 @@ void main() {
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('does not add extra space above the title field', (tester) async {
|
||||
await tester.pumpWidget(createTestWidget());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final titleTop = tester.getTopLeft(find.text('Заголовок')).dy;
|
||||
final scrollTop = tester.getTopLeft(find.byType(SingleChildScrollView)).dy;
|
||||
expect(titleTop - scrollTop, 16);
|
||||
});
|
||||
|
||||
testWidgets('pre-fills form fields when editing existing blog post', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/widgets/about_order_button.dart';
|
||||
import 'package:eatvio_app/features/chat/presentation/widgets/message_action_bottom_sheet.dart';
|
||||
@@ -8,6 +7,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class _FakeAssetBundle extends CachingAssetBundle {
|
||||
_FakeAssetBundle(this.assets);
|
||||
@@ -66,7 +66,9 @@ void main() {
|
||||
|
||||
testWidgets('AboutOrderButton renders and taps', (tester) async {
|
||||
var tapped = false;
|
||||
await tester.pumpWidget(wrap(AboutOrderButton(onTap: () => tapped = true)));
|
||||
await tester.pumpWidget(
|
||||
wrap(AboutOrderButton(onTap: () => tapped = true)),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(AboutOrderButton), findsOneWidget);
|
||||
await tester.tap(find.byType(AboutOrderButton));
|
||||
@@ -75,24 +77,44 @@ void main() {
|
||||
});
|
||||
|
||||
testWidgets('MessageActionsBottomSheet renders', (tester) async {
|
||||
await tester.pumpWidget(wrap(MessageActionsBottomSheet(resend: () {}, delete: () {})));
|
||||
await tester.pumpWidget(
|
||||
wrap(MessageActionsBottomSheet(resend: () {}, delete: () {})),
|
||||
);
|
||||
await tester.pump();
|
||||
expect(find.byType(MessageActionsBottomSheet), findsOneWidget);
|
||||
expect(find.text(S.current.resend), findsOneWidget);
|
||||
expect(find.text(S.current.delete), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('NotificationBanner renders for multiple banner types', (tester) async {
|
||||
testWidgets('NotificationBanner renders for multiple banner types', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
wrap(
|
||||
const SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
NotificationBanner(bannerType: BannerType.date, hasPersonalDiet: false),
|
||||
NotificationBanner(
|
||||
bannerType: BannerType.date,
|
||||
hasPersonalDiet: false,
|
||||
),
|
||||
NotificationBanner(bannerType: BannerType.card),
|
||||
NotificationBanner(bannerType: BannerType.collectCharge, planName: 'Plan', planPrice: 100, chosenPlanId: 1),
|
||||
NotificationBanner(bannerType: BannerType.finishPlan, planName: 'Plan', planPrice: 100, chosenPlanId: 1),
|
||||
NotificationBanner(bannerType: BannerType.setPersonalDiet, hasPersonalDiet: true),
|
||||
NotificationBanner(
|
||||
bannerType: BannerType.collectCharge,
|
||||
planName: 'Plan',
|
||||
planPrice: 100,
|
||||
chosenPlanId: 1,
|
||||
),
|
||||
NotificationBanner(
|
||||
bannerType: BannerType.finishPlan,
|
||||
planName: 'Plan',
|
||||
planPrice: 100,
|
||||
chosenPlanId: 1,
|
||||
),
|
||||
NotificationBanner(
|
||||
bannerType: BannerType.setPersonalDiet,
|
||||
hasPersonalDiet: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -101,5 +123,54 @@ void main() {
|
||||
await tester.pump();
|
||||
expect(find.byType(NotificationBanner), findsWidgets);
|
||||
});
|
||||
|
||||
testWidgets('collect charge banner opens card settings with chosenPlanId', (
|
||||
tester,
|
||||
) async {
|
||||
final router = GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => const Scaffold(
|
||||
body: NotificationBanner(
|
||||
bannerType: BannerType.collectCharge,
|
||||
planName: 'Plan',
|
||||
planPrice: 100,
|
||||
chosenPlanId: 17,
|
||||
),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/card-settings-screen',
|
||||
builder: (context, state) =>
|
||||
Scaffold(body: Text('chosenPlanId:${state.extra}')),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
DefaultAssetBundle(
|
||||
bundle: bundle,
|
||||
child: MaterialApp.router(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
routerConfig: router,
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Получить выплату'), findsOneWidget);
|
||||
await tester.tap(find.text('Получить выплату'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('chosenPlanId:17'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,12 +16,18 @@ import 'package:network_image_mock/network_image_mock.dart';
|
||||
void main() {
|
||||
group('ConsultationCardWidget smoke', () {
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
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'));
|
||||
sl.registerLazySingleton<AppConfig>(
|
||||
() =>
|
||||
AppConfig(buildType: AppBuildType.tests)
|
||||
..setBaseUrl('http://localhost'),
|
||||
);
|
||||
});
|
||||
|
||||
final mockConsultation = ConsultationModel(
|
||||
@@ -39,9 +45,21 @@ void main() {
|
||||
endDate: DateTime(2025, 1, 8),
|
||||
consultantId: 1,
|
||||
diaries: [
|
||||
DiaryModel(id: 1, state: DiaryStateEnum.finished, date: DateTime(2025, 1, 1)),
|
||||
DiaryModel(id: 2, state: DiaryStateEnum.commented, date: DateTime(2025, 1, 2)),
|
||||
DiaryModel(id: 3, state: DiaryStateEnum.init, date: DateTime(2025, 1, 3)),
|
||||
DiaryModel(
|
||||
id: 1,
|
||||
state: DiaryStateEnum.finished,
|
||||
date: DateTime(2025, 1, 1),
|
||||
),
|
||||
DiaryModel(
|
||||
id: 2,
|
||||
state: DiaryStateEnum.commented,
|
||||
date: DateTime(2025, 1, 2),
|
||||
),
|
||||
DiaryModel(
|
||||
id: 3,
|
||||
state: DiaryStateEnum.init,
|
||||
date: DateTime(2025, 1, 3),
|
||||
),
|
||||
],
|
||||
personalDietId: null,
|
||||
);
|
||||
@@ -63,18 +81,25 @@ void main() {
|
||||
GoRoute(
|
||||
path: '/profile-screen',
|
||||
name: 'profileScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Profile')),
|
||||
builder: (context, state) =>
|
||||
const Scaffold(body: Text('Profile')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/user-details-screen',
|
||||
name: 'userDetailsScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('User Details')),
|
||||
builder: (context, state) =>
|
||||
const Scaffold(body: Text('User Details')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/diary-screen',
|
||||
name: 'diaryScreen',
|
||||
builder: (context, state) => const Scaffold(body: Text('Diary')),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/card-settings-screen',
|
||||
builder: (context, state) =>
|
||||
Scaffold(body: Text('chosenPlanId:${state.extra}')),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -82,7 +107,9 @@ void main() {
|
||||
|
||||
testWidgets('renders consultation card with user info', (tester) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(wrap(ConsultationCardWidget(consultationsModel: mockConsultation)));
|
||||
await tester.pumpWidget(
|
||||
wrap(ConsultationCardWidget(consultationsModel: mockConsultation)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('John Doe'), findsOneWidget);
|
||||
@@ -92,12 +119,49 @@ void main() {
|
||||
|
||||
testWidgets('renders diary days', (tester) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(wrap(ConsultationCardWidget(consultationsModel: mockConsultation)));
|
||||
await tester.pumpWidget(
|
||||
wrap(ConsultationCardWidget(consultationsModel: mockConsultation)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
|
||||
expect(find.byType(InkWell), findsWidgets);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('hides collect charge when consultation is in progress', (
|
||||
tester,
|
||||
) async {
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(
|
||||
wrap(ConsultationCardWidget(consultationsModel: mockConsultation)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Получить выплату'), findsNothing);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'shows collect charge and opens card settings with chosen plan id when done',
|
||||
(tester) async {
|
||||
final doneConsultation = mockConsultation.copyWith(
|
||||
chosenPlanState: ChosenPlanStateEnum.stateDone,
|
||||
);
|
||||
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(
|
||||
wrap(ConsultationCardWidget(consultationsModel: doneConsultation)),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Получить выплату'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Получить выплату'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('chosenPlanId:1'), findsOneWidget);
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -52,5 +52,14 @@ void main() {
|
||||
expect(posts[2].videoEmbedUrl, contains('rutube.ru/play/embed'));
|
||||
expect(posts[2].author.isEntitySubscribedByMe, isNull);
|
||||
});
|
||||
|
||||
test('treats API placeholder cover as missing image', () {
|
||||
expect(PostFeedMapper.resolveMediaUrl('images/element-image-placeholder.svg'), isEmpty);
|
||||
expect(PostFeedMapper.hasRenderableImage('images/element-image-placeholder.svg'), isFalse);
|
||||
expect(
|
||||
PostFeedMapper.hasVisibleMedia(image: '', images: const [], videoEmbedUrl: null),
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -85,4 +85,27 @@ void main() {
|
||||
expect(image.fit, BoxFit.fitWidth);
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('empty cover does not reserve media height', (tester) async {
|
||||
await tester.pumpWidget(wrap(media(images: const [], imageUrl: '')));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CachedNetworkImage), findsNothing);
|
||||
expect(tester.getSize(find.byType(BlogPostMediaContent)).height, 0);
|
||||
});
|
||||
|
||||
testWidgets('placeholder cover does not reserve media height', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
wrap(
|
||||
media(
|
||||
images: const [],
|
||||
imageUrl: 'images/element-image-placeholder.svg',
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(CachedNetworkImage), findsNothing);
|
||||
expect(tester.getSize(find.byType(BlogPostMediaContent)).height, 0);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -7,8 +7,10 @@ import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/order_info/cubit/order_info_cubit.dart';
|
||||
import 'package:eatvio_app/features/order_info/presentation/info_by_order_screen.dart';
|
||||
import 'package:eatvio_app/features/order_info/presentation/widgets/collect_charge_banner.dart';
|
||||
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
|
||||
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
|
||||
import 'package:eatvio_app/features/profile/models/profile_model.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -29,15 +31,24 @@ void main() {
|
||||
late OrderInfoCubit orderInfoCubit;
|
||||
|
||||
setUpAll(() async {
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
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'));
|
||||
sl.registerLazySingleton<AppConfig>(
|
||||
() =>
|
||||
AppConfig(buildType: AppBuildType.tests)
|
||||
..setBaseUrl('http://localhost'),
|
||||
);
|
||||
mockChatRepository = MockChatRepository();
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
orderInfoCubit = OrderInfoCubit(chatRepository: mockChatRepository, profileRepository: mockProfileRepository);
|
||||
orderInfoCubit = OrderInfoCubit(
|
||||
chatRepository: mockChatRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
);
|
||||
sl.registerLazySingleton<OrderInfoCubit>(() => orderInfoCubit);
|
||||
});
|
||||
|
||||
@@ -45,7 +56,11 @@ void main() {
|
||||
orderInfoCubit.close();
|
||||
});
|
||||
|
||||
Widget createTestWidget({required int planId, bool? successfulPayment, String? customerSlug}) {
|
||||
Widget createTestWidget({
|
||||
required int planId,
|
||||
bool? successfulPayment,
|
||||
String? customerSlug,
|
||||
}) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
@@ -55,12 +70,20 @@ void main() {
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: InfoByOrderScreen(planId: planId, successfulPayment: successfulPayment, customerSlug: customerSlug),
|
||||
home: InfoByOrderScreen(
|
||||
planId: planId,
|
||||
successfulPayment: successfulPayment,
|
||||
customerSlug: customerSlug,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('displays screen with loading state initially', (WidgetTester tester) async {
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id'))).thenThrow(Exception('Not implemented'));
|
||||
testWidgets('displays screen with loading state initially', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
when(
|
||||
mockChatRepository.getChosenPlan(id: anyNamed('id')),
|
||||
).thenThrow(Exception('Not implemented'));
|
||||
|
||||
await tester.pumpWidget(createTestWidget(planId: 1));
|
||||
await tester.pump();
|
||||
@@ -69,8 +92,12 @@ void main() {
|
||||
expect(find.byType(Scaffold), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('calls getChosenPlan when screen is created', (WidgetTester tester) async {
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id'))).thenThrow(Exception('Not implemented'));
|
||||
testWidgets('calls getChosenPlan when screen is created', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
when(
|
||||
mockChatRepository.getChosenPlan(id: anyNamed('id')),
|
||||
).thenThrow(Exception('Not implemented'));
|
||||
|
||||
await tester.pumpWidget(createTestWidget(planId: 123));
|
||||
await tester.pump();
|
||||
@@ -78,18 +105,28 @@ void main() {
|
||||
verify(mockChatRepository.getChosenPlan(id: 123)).called(1);
|
||||
});
|
||||
|
||||
testWidgets('calls getChosenPlan when customerSlug is provided', (WidgetTester tester) async {
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id'))).thenThrow(Exception('Not implemented'));
|
||||
testWidgets('calls getChosenPlan when customerSlug is provided', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
when(
|
||||
mockChatRepository.getChosenPlan(id: anyNamed('id')),
|
||||
).thenThrow(Exception('Not implemented'));
|
||||
|
||||
await tester.pumpWidget(createTestWidget(planId: 123, customerSlug: 'test-user'));
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(planId: 123, customerSlug: 'test-user'),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
verify(mockChatRepository.getChosenPlan(id: 123)).called(1);
|
||||
// Note: getProfileBySlug is only called if getChosenPlan succeeds
|
||||
});
|
||||
|
||||
testWidgets('displays screen with back button', (WidgetTester tester) async {
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id'))).thenThrow(Exception('Not implemented'));
|
||||
testWidgets('displays screen with back button', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
when(
|
||||
mockChatRepository.getChosenPlan(id: anyNamed('id')),
|
||||
).thenThrow(Exception('Not implemented'));
|
||||
|
||||
await tester.pumpWidget(createTestWidget(planId: 1));
|
||||
await tester.pump();
|
||||
@@ -98,7 +135,9 @@ void main() {
|
||||
expect(find.byIcon(Icons.arrow_back), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays screen with loaded plan', (WidgetTester tester) async {
|
||||
testWidgets('displays screen with loaded plan', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final chosenPlan = ChosenPlanModel(
|
||||
id: 1,
|
||||
optionType: 'options1',
|
||||
@@ -113,10 +152,20 @@ void main() {
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
|
||||
type: PlanType(
|
||||
fit: true,
|
||||
slim: false,
|
||||
behavior: false,
|
||||
wellness: false,
|
||||
),
|
||||
details: 'Test details',
|
||||
packetsCount: 3,
|
||||
author: Author(authorSlug: 'author', authorName: 'Author Name', authorProfileIcon: 'https://example.com/icon.jpg', authorIsMe: false),
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
@@ -127,7 +176,9 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id'))).thenAnswer((_) async => chosenPlan);
|
||||
when(
|
||||
mockChatRepository.getChosenPlan(id: anyNamed('id')),
|
||||
).thenAnswer((_) async => chosenPlan);
|
||||
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(createTestWidget(planId: 1));
|
||||
@@ -137,7 +188,9 @@ void main() {
|
||||
expect(find.byType(InfoByOrderScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('displays screen with successful payment', (WidgetTester tester) async {
|
||||
testWidgets('displays screen with successful payment', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
final chosenPlan = ChosenPlanModel(
|
||||
id: 1,
|
||||
optionType: 'options1',
|
||||
@@ -152,10 +205,20 @@ void main() {
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
|
||||
type: PlanType(
|
||||
fit: true,
|
||||
slim: false,
|
||||
behavior: false,
|
||||
wellness: false,
|
||||
),
|
||||
details: 'Test details',
|
||||
packetsCount: 3,
|
||||
author: Author(authorSlug: 'author', authorName: 'Author Name', authorProfileIcon: 'https://example.com/icon.jpg', authorIsMe: false),
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
@@ -166,14 +229,114 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
when(mockChatRepository.getChosenPlan(id: anyNamed('id'))).thenAnswer((_) async => chosenPlan);
|
||||
when(
|
||||
mockChatRepository.getChosenPlan(id: anyNamed('id')),
|
||||
).thenAnswer((_) async => chosenPlan);
|
||||
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(createTestWidget(planId: 1, successfulPayment: true));
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(planId: 1, successfulPayment: true),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
expect(find.byType(InfoByOrderScreen), findsOneWidget);
|
||||
});
|
||||
|
||||
ChosenPlanModel donePlan() {
|
||||
return ChosenPlanModel(
|
||||
id: 1,
|
||||
optionType: 'options1',
|
||||
startDate: DateTime(2024, 1, 1),
|
||||
chosenPlanState: ChosenPlanStateEnum.stateDone,
|
||||
chatId: 'chat-1',
|
||||
consultantId: 1,
|
||||
plan: const PlanModel(
|
||||
id: 1,
|
||||
slug: 'test-plan',
|
||||
name: 'Test Plan',
|
||||
image: 'https://example.com/image.jpg',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(
|
||||
fit: true,
|
||||
slim: false,
|
||||
behavior: false,
|
||||
wellness: false,
|
||||
),
|
||||
details: 'Test details',
|
||||
packetsCount: 3,
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author Name',
|
||||
authorProfileIcon: 'https://example.com/icon.jpg',
|
||||
authorIsMe: false,
|
||||
),
|
||||
totalLikes: 10,
|
||||
totalViews: 100,
|
||||
totalComments: 5,
|
||||
isFavorite: false,
|
||||
minPriceOfOptions: 1000,
|
||||
maxPriceOfOptions: 2000,
|
||||
wasLikedByMe: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'shows collect charge banner for consultant when plan is done',
|
||||
(WidgetTester tester) async {
|
||||
const profile = ProfileModel(
|
||||
id: 2,
|
||||
name: 'Customer',
|
||||
email: 'customer@example.com',
|
||||
phoneConfirmationState: 'confirmed',
|
||||
isPublicProfile: true,
|
||||
isBlockedByMe: false,
|
||||
isBlockedByAuthor: false,
|
||||
isBlockedByUser: false,
|
||||
isEntitySubscribedByMe: false,
|
||||
slug: 'test-user',
|
||||
profilePhotoUrl: '/test.jpg',
|
||||
roles: ['user'],
|
||||
badges: [],
|
||||
subscriptions: [],
|
||||
subscribers: [],
|
||||
);
|
||||
|
||||
when(
|
||||
mockChatRepository.getChosenPlan(id: anyNamed('id')),
|
||||
).thenAnswer((_) async => donePlan());
|
||||
when(
|
||||
mockProfileRepository.getProfileBySlug('test-user'),
|
||||
).thenAnswer((_) async => profile);
|
||||
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(planId: 1, customerSlug: 'test-user'),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
expect(find.byType(CollectChargeBanner), findsOneWidget);
|
||||
expect(find.text('Получить выплату'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('hides collect charge banner for client when plan is done', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
when(
|
||||
mockChatRepository.getChosenPlan(id: anyNamed('id')),
|
||||
).thenAnswer((_) async => donePlan());
|
||||
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(createTestWidget(planId: 1));
|
||||
await tester.pumpAndSettle();
|
||||
});
|
||||
|
||||
expect(find.byType(CollectChargeBanner), findsNothing);
|
||||
expect(find.text('Получить выплату'), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/features/order_info/presentation/widgets/collect_charge_banner.dart';
|
||||
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
|
||||
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart' show PlanModel, PlanType;
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart' show Author;
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart'
|
||||
show PlanModel, PlanType;
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart'
|
||||
show Author;
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
@@ -20,8 +22,14 @@ void main() {
|
||||
group('CollectChargeBanner', () {
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
dotenv.loadFromString(
|
||||
envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost',
|
||||
);
|
||||
sl.registerLazySingleton<AppConfig>(
|
||||
() =>
|
||||
AppConfig(buildType: AppBuildType.tests)
|
||||
..setBaseUrl('http://localhost'),
|
||||
);
|
||||
});
|
||||
|
||||
Widget createTestWidget(Widget child) {
|
||||
@@ -42,12 +50,76 @@ void main() {
|
||||
child: Scaffold(body: SingleChildScrollView(child: child)),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/card-settings-screen',
|
||||
builder: (context, state) =>
|
||||
Scaffold(body: Text('chosenPlanId:${state.extra}')),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('should display collect charge banner with plan name and price', (WidgetTester tester) async {
|
||||
testWidgets(
|
||||
'should display collect charge banner with plan name and price',
|
||||
(WidgetTester tester) async {
|
||||
// Arrange
|
||||
final chosenPlan = ChosenPlanModel(
|
||||
id: 1,
|
||||
optionType: 'standard',
|
||||
startDate: DateTime.now(),
|
||||
chosenPlanState: ChosenPlanStateEnum.stateDone,
|
||||
chatId: 'chat-1',
|
||||
consultantId: 1,
|
||||
plan: const PlanModel(
|
||||
id: 1,
|
||||
slug: 'test-plan',
|
||||
name: 'Test Plan',
|
||||
image: 'test.jpg',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(
|
||||
fit: true,
|
||||
slim: false,
|
||||
behavior: false,
|
||||
wellness: false,
|
||||
),
|
||||
details: 'Test details',
|
||||
packetsCount: 1,
|
||||
author: Author(
|
||||
authorSlug: '',
|
||||
authorName: '',
|
||||
authorProfileIcon: '',
|
||||
authorIsMe: false,
|
||||
),
|
||||
totalLikes: 0,
|
||||
totalViews: 0,
|
||||
totalComments: 0,
|
||||
isFavorite: false,
|
||||
minPriceOfOptions: 100.0,
|
||||
maxPriceOfOptions: 500.0,
|
||||
wasLikedByMe: false,
|
||||
),
|
||||
);
|
||||
const price = 1000.0;
|
||||
final widget = CollectChargeBanner(
|
||||
chosenPlan: chosenPlan,
|
||||
price: price,
|
||||
);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(CollectChargeBanner), findsOneWidget);
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('should have button that navigates to card settings', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
// Arrange
|
||||
final chosenPlan = ChosenPlanModel(
|
||||
id: 1,
|
||||
@@ -63,10 +135,20 @@ void main() {
|
||||
image: 'test.jpg',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
|
||||
type: PlanType(
|
||||
fit: true,
|
||||
slim: false,
|
||||
behavior: false,
|
||||
wellness: false,
|
||||
),
|
||||
details: 'Test details',
|
||||
packetsCount: 1,
|
||||
author: Author(authorSlug: '', authorName: '', authorProfileIcon: '', authorIsMe: false),
|
||||
author: Author(
|
||||
authorSlug: '',
|
||||
authorName: '',
|
||||
authorProfileIcon: '',
|
||||
authorIsMe: false,
|
||||
),
|
||||
totalLikes: 0,
|
||||
totalViews: 0,
|
||||
totalComments: 0,
|
||||
@@ -83,50 +165,10 @@ void main() {
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert
|
||||
expect(find.byType(CollectChargeBanner), findsOneWidget);
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
});
|
||||
await tester.tap(find.byType(CustomOutlinedButton));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
testWidgets('should have button that navigates to card settings', (WidgetTester tester) async {
|
||||
// Arrange
|
||||
final chosenPlan = ChosenPlanModel(
|
||||
id: 1,
|
||||
optionType: 'standard',
|
||||
startDate: DateTime.now(),
|
||||
chosenPlanState: ChosenPlanStateEnum.stateDone,
|
||||
chatId: 'chat-1',
|
||||
consultantId: 1,
|
||||
plan: const PlanModel(
|
||||
id: 1,
|
||||
slug: 'test-plan',
|
||||
name: 'Test Plan',
|
||||
image: 'test.jpg',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(fit: true, slim: false, behavior: false, wellness: false),
|
||||
details: 'Test details',
|
||||
packetsCount: 1,
|
||||
author: Author(authorSlug: '', authorName: '', authorProfileIcon: '', authorIsMe: false),
|
||||
totalLikes: 0,
|
||||
totalViews: 0,
|
||||
totalComments: 0,
|
||||
isFavorite: false,
|
||||
minPriceOfOptions: 100.0,
|
||||
maxPriceOfOptions: 500.0,
|
||||
wasLikedByMe: false,
|
||||
),
|
||||
);
|
||||
const price = 1000.0;
|
||||
final widget = CollectChargeBanner(chosenPlan: chosenPlan, price: price);
|
||||
|
||||
// Act
|
||||
await tester.pumpWidget(createTestWidget(widget));
|
||||
await tester.pump();
|
||||
|
||||
// Assert - проверяем, что кнопка существует
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
expect(find.text('chosenPlanId:1'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
|
||||
@@ -6,22 +7,36 @@ import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_cubit.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_state.dart';
|
||||
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/models/chosen_diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'about_plan_cubit_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<PlanRepository>()])
|
||||
@GenerateNiceMocks([MockSpec<PlanRepository>(), MockSpec<ProfileRepository>(), MockSpec<DietRepository>()])
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
group('AboutPlanCubit', () {
|
||||
AboutPlanCubit? aboutPlanCubit;
|
||||
late MockPlanRepository mockPlanRepository;
|
||||
late MockProfileRepository mockProfileRepository;
|
||||
late MockDietRepository mockDietRepository;
|
||||
|
||||
AboutPlanCubit createCubit() {
|
||||
return AboutPlanCubit(
|
||||
planRepository: mockPlanRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
dietRepository: mockDietRepository,
|
||||
);
|
||||
}
|
||||
|
||||
setUp(() {
|
||||
mockPlanRepository = MockPlanRepository();
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
mockDietRepository = MockDietRepository();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
@@ -32,7 +47,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('начальное состояние - initial', () {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
expect(aboutPlanCubit!.state, isA<AboutPlanState>());
|
||||
expect(aboutPlanCubit!.state.isLoading, isFalse);
|
||||
@@ -40,7 +55,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('getPlan - успешная загрузка плана', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -79,7 +94,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('getPlanWithLoading - устанавливает loading состояние', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -117,7 +132,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('choseOption - изменяет выбранную опцию', () {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
aboutPlanCubit!.choseOption(2);
|
||||
|
||||
@@ -125,7 +140,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('likePlan - лайк плана', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -166,7 +181,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('getPlan - обработка ошибки', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
when(mockPlanRepository.getPlan('test-plan')).thenThrow(Exception('Ошибка загрузки'));
|
||||
|
||||
@@ -177,7 +192,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('getPlanWithLoading - обработка ошибки', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
when(mockPlanRepository.getPlan('test-plan')).thenThrow(Exception('Ошибка загрузки'));
|
||||
|
||||
@@ -188,7 +203,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('likePlan - убирает лайк если уже лайкнуто', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -231,7 +246,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('addToFavorite - добавляет план в избранное', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -273,7 +288,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('removeFromFavorite - удаляет план из избранного', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -315,7 +330,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('chosePlan - успешно выбирает план', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -368,7 +383,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('chosePlan - возвращает ошибку hasPlan при 400 статусе', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -415,7 +430,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('likePlan - лайк плана с index', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -458,7 +473,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('likePlan - убирает лайк с index', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -501,7 +516,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('likePlan - обрабатывает ошибку', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -542,7 +557,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('likePlan - не делает ничего если план не загружен', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
await aboutPlanCubit!.likePlan(index: null, slug: 'test-plan');
|
||||
|
||||
@@ -551,7 +566,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('addToFavorite - добавляет план в избранное с index', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -592,7 +607,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('addToFavorite - обрабатывает ошибку', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -632,7 +647,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('addToFavorite - не делает ничего если план не загружен', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
await aboutPlanCubit!.addToFavorite(slug: 'test-plan', index: null);
|
||||
|
||||
@@ -641,7 +656,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('removeFromFavorite - удаляет план из избранного с index', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -682,7 +697,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('removeFromFavorite - обрабатывает ошибку', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -722,7 +737,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('removeFromFavorite - не делает ничего если план не загружен', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
await aboutPlanCubit!.removeFromFavorite(slug: 'test-plan', index: null);
|
||||
|
||||
@@ -731,7 +746,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('chosePlan - выбирает план с optionIndex 1', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -784,7 +799,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('chosePlan - выбирает план с optionIndex 2', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -837,7 +852,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('chosePlan - возвращает пустой результат когда slug == null', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
final result = await aboutPlanCubit!.chosePlan();
|
||||
|
||||
@@ -847,7 +862,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('chosePlan - обрабатывает DioException с другим статусом', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -894,7 +909,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('chosePlan - обрабатывает общее исключение', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -936,7 +951,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('getPlanWithLoading - устанавливает isLoading в true перед загрузкой', () async {
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
aboutPlanCubit = createCubit();
|
||||
|
||||
const testPlan = PlanModel(
|
||||
id: 1,
|
||||
@@ -977,5 +992,76 @@ void main() {
|
||||
await future;
|
||||
expect(aboutPlanCubit!.state.isLoading, isFalse);
|
||||
});
|
||||
|
||||
test('getActivePublicDiet - возвращает активную публичную диету', () async {
|
||||
aboutPlanCubit = createCubit();
|
||||
final publicDiet = ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 0,
|
||||
state: 'started',
|
||||
startDate: DateTime(2024, 1, 1),
|
||||
dietId: 10,
|
||||
);
|
||||
when(mockProfileRepository.getChosenDiets()).thenAnswer((_) async => [publicDiet]);
|
||||
|
||||
final result = await aboutPlanCubit!.getActivePublicDiet();
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.dietId, 10);
|
||||
expect(result.chosenPlanId, 0);
|
||||
});
|
||||
|
||||
test('getActivePublicDiet - игнорирует диету, привязанную к плану', () async {
|
||||
aboutPlanCubit = createCubit();
|
||||
final personalDiet = ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 5,
|
||||
state: 'started',
|
||||
startDate: DateTime(2024, 1, 1),
|
||||
dietId: 10,
|
||||
);
|
||||
when(mockProfileRepository.getChosenDiets()).thenAnswer((_) async => [personalDiet]);
|
||||
|
||||
final result = await aboutPlanCubit!.getActivePublicDiet();
|
||||
|
||||
expect(result, isNull);
|
||||
});
|
||||
|
||||
test('getActivePublicDiet - возвращает null если нет выбранных диет', () async {
|
||||
aboutPlanCubit = createCubit();
|
||||
when(mockProfileRepository.getChosenDiets()).thenAnswer((_) async => []);
|
||||
|
||||
final result = await aboutPlanCubit!.getActivePublicDiet();
|
||||
|
||||
expect(result, isNull);
|
||||
});
|
||||
|
||||
test('getActivePublicDiet - возвращает null при ошибке', () async {
|
||||
aboutPlanCubit = createCubit();
|
||||
when(mockProfileRepository.getChosenDiets()).thenThrow(Exception('error'));
|
||||
|
||||
final result = await aboutPlanCubit!.getActivePublicDiet();
|
||||
|
||||
expect(result, isNull);
|
||||
});
|
||||
|
||||
test('cancelPublicDiet - успешно отменяет диету', () async {
|
||||
aboutPlanCubit = createCubit();
|
||||
when(mockDietRepository.cancelDiet(10)).thenAnswer((_) async {});
|
||||
|
||||
final result = await aboutPlanCubit!.cancelPublicDiet(10);
|
||||
|
||||
expect(result, isTrue);
|
||||
verify(mockDietRepository.cancelDiet(10)).called(1);
|
||||
});
|
||||
|
||||
test('cancelPublicDiet - возвращает false при ошибке', () async {
|
||||
aboutPlanCubit = createCubit();
|
||||
when(mockDietRepository.cancelDiet(10)).thenThrow(Exception('error'));
|
||||
|
||||
final result = await aboutPlanCubit!.cancelPublicDiet(10);
|
||||
|
||||
expect(result, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit
|
||||
import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_cubit.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_state.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/pages/about_plan_screen.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/widgets/confirm_start_plan_bottom_sheet.dart';
|
||||
import 'package:eatvio_app/features/profile/models/chosen_diets_pagination_model.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -301,5 +303,82 @@ void main() {
|
||||
expect(find.byType(AboutPlanScreen), findsOneWidget);
|
||||
expect(find.text('Test Plan'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('order with public diet shows start plan confirmation', (tester) async {
|
||||
final planCubit = MockAboutPlanCubit();
|
||||
final feedCubit = MockFeedCubit();
|
||||
final commentsCubit = MockCommentsCubit();
|
||||
const state = AboutPlanState(isLoading: false, planModel: testPlan, chosenOptionIndex: 0, error: null);
|
||||
final publicDiet = ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 0,
|
||||
state: 'started',
|
||||
startDate: DateTime(2024, 1, 1),
|
||||
dietId: 10,
|
||||
);
|
||||
|
||||
when(planCubit.state).thenReturn(state);
|
||||
when(planCubit.stream).thenAnswer((_) => const Stream<AboutPlanState>.empty());
|
||||
when(planCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(planCubit.getActivePublicDiet()).thenAnswer((_) async => publicDiet);
|
||||
when(feedCubit.viewPlan(any)).thenAnswer((_) async => Future<void>.value());
|
||||
when(feedCubit.stream).thenAnswer((_) => const Stream.empty());
|
||||
when(feedCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(commentsCubit.state).thenReturn(const CommentsState());
|
||||
when(commentsCubit.stream).thenAnswer((_) => const Stream<CommentsState>.empty());
|
||||
when(commentsCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(commentsCubit.getComments(any, any, any)).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
registerMocks(planCubit, commentsCubit);
|
||||
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(wrap(planCubit, feedCubit, commentsCubit, const AboutPlanScreen(slug: 'test', navigateToComments: false, index: null, highlightedCommentId: null)));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
await tester.tap(find.text('Заказать'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(ConfirmStartPlanBottomSheet), findsOneWidget);
|
||||
expect(find.text('Вы уверены, что хотите начать прохождение плана?'), findsOneWidget);
|
||||
verifyNever(planCubit.chosePlan());
|
||||
});
|
||||
|
||||
testWidgets('order without public diet calls chosePlan', (tester) async {
|
||||
final planCubit = MockAboutPlanCubit();
|
||||
final feedCubit = MockFeedCubit();
|
||||
final commentsCubit = MockCommentsCubit();
|
||||
const state = AboutPlanState(isLoading: false, planModel: testPlan, chosenOptionIndex: 0, error: null);
|
||||
|
||||
when(planCubit.state).thenReturn(state);
|
||||
when(planCubit.stream).thenAnswer((_) => const Stream<AboutPlanState>.empty());
|
||||
when(planCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(planCubit.getActivePublicDiet()).thenAnswer((_) async => null);
|
||||
when(planCubit.chosePlan()).thenAnswer((_) async => (null, ''));
|
||||
when(feedCubit.viewPlan(any)).thenAnswer((_) async => Future<void>.value());
|
||||
when(feedCubit.stream).thenAnswer((_) => const Stream.empty());
|
||||
when(feedCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(commentsCubit.state).thenReturn(const CommentsState());
|
||||
when(commentsCubit.stream).thenAnswer((_) => const Stream<CommentsState>.empty());
|
||||
when(commentsCubit.close()).thenAnswer((_) async => Future<void>.value());
|
||||
when(commentsCubit.getComments(any, any, any)).thenAnswer((_) async => Future<void>.value());
|
||||
|
||||
registerMocks(planCubit, commentsCubit);
|
||||
|
||||
await mockNetworkImagesFor(() async {
|
||||
await tester.pumpWidget(wrap(planCubit, feedCubit, commentsCubit, const AboutPlanScreen(slug: 'test', navigateToComments: false, index: null, highlightedCommentId: null)));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
});
|
||||
|
||||
await tester.tap(find.text('Заказать'));
|
||||
await tester.pump();
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(ConfirmStartPlanBottomSheet), findsNothing);
|
||||
verify(planCubit.chosePlan()).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/widgets/confirm_start_plan_bottom_sheet.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ConfirmStartPlanBottomSheet', () {
|
||||
Widget createTestWidget(Widget child) {
|
||||
return MaterialApp(
|
||||
theme: ThemeHelper().themeData(),
|
||||
localizationsDelegates: const [
|
||||
S.delegate,
|
||||
GlobalMaterialLocalizations.delegate,
|
||||
GlobalWidgetsLocalizations.delegate,
|
||||
GlobalCupertinoLocalizations.delegate,
|
||||
],
|
||||
supportedLocales: const [Locale('ru')],
|
||||
home: Scaffold(body: child),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets('показывает текст подтверждения начала плана', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
ConfirmStartPlanBottomSheet(onConfirm: () async {}),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
expect(find.text('Вы уверены, что хотите начать прохождение плана?'), findsOneWidget);
|
||||
expect(find.byType(CustomOutlinedButton), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('по нажатию подтверждения вызывает onConfirm', (tester) async {
|
||||
var confirmed = false;
|
||||
await tester.pumpWidget(
|
||||
createTestWidget(
|
||||
ConfirmStartPlanBottomSheet(
|
||||
onConfirm: () async {
|
||||
confirmed = true;
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
|
||||
await tester.tap(find.byType(CustomOutlinedButton));
|
||||
await tester.pump();
|
||||
|
||||
expect(confirmed, isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -3,10 +3,12 @@ import 'package:eatvio_app/core/app_initializer.dart';
|
||||
import 'package:eatvio_app/core/locator_service.dart';
|
||||
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
||||
import 'package:eatvio_app/core/widgets/animated_option_button.dart';
|
||||
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_cubit.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/cubit/about_plan_state.dart';
|
||||
import 'package:eatvio_app/features/plans/presentation/widgets/options_tab.dart';
|
||||
import 'package:eatvio_app/features/plans/repositories/plan_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:eatvio_app/generated/l10n.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
@@ -18,17 +20,25 @@ import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
import 'widgets_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<PlanRepository>()])
|
||||
@GenerateNiceMocks([MockSpec<PlanRepository>(), MockSpec<ProfileRepository>(), MockSpec<DietRepository>()])
|
||||
void main() {
|
||||
group('Plans Widgets Tests', () {
|
||||
late MockPlanRepository mockPlanRepository;
|
||||
late MockProfileRepository mockProfileRepository;
|
||||
late MockDietRepository mockDietRepository;
|
||||
late AboutPlanCubit aboutPlanCubit;
|
||||
|
||||
setUp(() async {
|
||||
await sl.reset();
|
||||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost');
|
||||
mockPlanRepository = MockPlanRepository();
|
||||
aboutPlanCubit = AboutPlanCubit(planRepository: mockPlanRepository);
|
||||
mockProfileRepository = MockProfileRepository();
|
||||
mockDietRepository = MockDietRepository();
|
||||
aboutPlanCubit = AboutPlanCubit(
|
||||
planRepository: mockPlanRepository,
|
||||
profileRepository: mockProfileRepository,
|
||||
dietRepository: mockDietRepository,
|
||||
);
|
||||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||||
});
|
||||
|
||||
|
||||
@@ -100,6 +100,22 @@ void main() {
|
||||
expect(model.dietId, 5);
|
||||
});
|
||||
|
||||
test('creates ChosenDietModel from JSON with null chosen_plan_id as public diet', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'chosen_plan_id': null,
|
||||
'state': 'started',
|
||||
'start_date': '2023-01-01T00:00:00Z',
|
||||
'diet': {'id': 5},
|
||||
};
|
||||
|
||||
final model = ChosenDietModel.fromJson(json);
|
||||
|
||||
expect(model.chosenDietID, 1);
|
||||
expect(model.chosenPlanId, 0);
|
||||
expect(model.dietId, 5);
|
||||
});
|
||||
|
||||
test('creates ChosenDietModel with null dietId', () {
|
||||
final model = ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
import 'package:eatvio_app/features/profile/presentation/widgets/expandable_page_view.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ExpandablePageView', () {
|
||||
testWidgets(
|
||||
'sizes itself to a child taller than the old fixed 781 height',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: ExpandablePageView(
|
||||
itemCount: 1,
|
||||
itemBuilder: _tallPlanCard,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Питание для диабетиков'), findsOneWidget);
|
||||
expect(find.text('Показать ещё'), findsOneWidget);
|
||||
|
||||
final viewSize = tester.getSize(find.byType(ExpandablePageView));
|
||||
expect(viewSize.height, greaterThan(781));
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('does not overflow a vertical Column inside a bounded parent', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SizedBox(
|
||||
height: 781,
|
||||
width: 402,
|
||||
child: SingleChildScrollView(
|
||||
child: ExpandablePageView(
|
||||
itemCount: 1,
|
||||
itemBuilder: _tallPlanCard,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(tester.takeException(), isNull);
|
||||
expect(find.text('Показать ещё'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Widget _tallPlanCard(BuildContext context, int index) {
|
||||
return const Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(width: 402, height: 426),
|
||||
SizedBox(height: 12),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text('Питание для диабетиков'),
|
||||
),
|
||||
SizedBox(height: 12),
|
||||
SizedBox(width: 370, height: 156),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 16, top: 8),
|
||||
child: Text('Показать ещё'),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
SizedBox(height: 72),
|
||||
SizedBox(height: 16),
|
||||
SizedBox(height: 32),
|
||||
SizedBox(height: 12),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -257,6 +257,8 @@ void main() {
|
||||
|
||||
expect(find.byType(BlogPostMediaContent), findsOneWidget);
|
||||
expect(find.textContaining('Галерея и видео'), findsWidgets);
|
||||
expect(find.byType(CircleAvatar), findsNothing);
|
||||
expect(find.text(post.author.authorName), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('renders gallery-only media content', (tester) async {
|
||||
|
||||
Reference in New Issue
Block a user