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

@@ -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);
});
});
}

View File

@@ -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);
});
});
}