fix: issue-1141

This commit is contained in:
misha
2026-11-18 14:38:15 +03:00
parent 87d383152d
commit b05d3b891b
14 changed files with 3983 additions and 2592 deletions

View File

@@ -12,6 +12,12 @@ import 'package:eatvio_app/features/chat/presentation/bloc/chat_room_cubit/chat_
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_cubit.dart';
import 'package:eatvio_app/features/chat/presentation/bloc/chats_cubit/chats_state.dart';
import 'package:eatvio_app/features/chat/presentation/pages/chat_screen.dart';
import 'package:eatvio_app/features/chat/presentation/widgets/video_call_chat_message_widget.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';
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:material_ui/material_ui.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
@@ -55,13 +61,57 @@ void main() {
final fakeBundle = _FakeAssetBundle({
'assets/icons/error_icon.svg': fakeSvg,
'assets/icons/video_call/vc_control_enter.svg': fakeSvg,
});
const plan = 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,
);
ChosenPlanModel chosenPlan(ChosenPlanStateEnum state) {
return ChosenPlanModel(
id: 7,
optionType: 'options1',
startDate: DateTime(2025, 1, 1),
chosenPlanState: state,
chatId: '1',
consultantId: 2,
plan: plan,
);
}
Widget wrap(Widget child, ChatsCubit chatsCubit) {
return DefaultAssetBundle(
bundle: fakeBundle,
child: MaterialApp(
theme: ThemeHelper().themeData(),
locale: const Locale('ru'),
localizationsDelegates: const [
S.delegate,
...GlobalMaterialLocalizations.delegates,
],
supportedLocales: S.delegate.supportedLocales,
home: BlocProvider<ChatsCubit>.value(value: chatsCubit, child: child),
),
);
@@ -202,9 +252,133 @@ void main() {
expect(find.text('sending...'), findsOneWidget);
expect(find.text('tap to retry'), findsOneWidget);
expect(find.text('file.pdf'), findsOneWidget);
expect(find.byIcon(Icons.videocam_rounded), findsNothing);
VisibilityDetectorController.instance.notifyNow();
await tester.pump();
});
Future<void> pumpLoadedChat(
WidgetTester tester, {
ChosenPlanModel? plan,
List<ChatMessageModel> messages = const [],
}) async {
final chatRoomCubit = MockChatRoomCubit();
final chatsCubit = MockChatsCubit();
const chatRoom = ChatRoomModel(
id: '1',
chatRoomSettings: ChatRoomSettingsModel(name: 'room', state: 'active'),
users: Users(
sender: ChatUserModel(
id: 1,
name: 'Me',
slug: 'me',
profilePhotoUrl: null,
),
receiver: ChatUserModel(
id: 2,
name: 'User Two',
slug: 'user-two',
profilePhotoUrl: null,
),
),
chosenPlanId: 7,
chosenPlan: null,
);
final state = ChatRoomState.loaded(
chatRoom: chatRoom.copyWith(chosenPlan: plan),
chatMessages: messages,
hasCard: false,
isTyping: false,
isLoading: false,
);
when(chatRoomCubit.state).thenReturn(state);
when(
chatRoomCubit.stream,
).thenAnswer((_) => const Stream<ChatRoomState>.empty());
when(chatRoomCubit.close()).thenAnswer((_) async => Future<void>.value());
when(
chatRoomCubit.initChat(
any,
sendInitialMessage: anyNamed('sendInitialMessage'),
orderId: anyNamed('orderId'),
),
).thenAnswer((_) async => 'uuid');
when(chatRoomCubit.setTimer()).thenReturn(null);
when(chatRoomCubit.refreshChat()).thenAnswer((_) async {});
if (sl.isRegistered<ChatRoomCubit>()) {
sl.unregister<ChatRoomCubit>();
}
sl.registerFactory<ChatRoomCubit>(() => chatRoomCubit);
when(chatsCubit.state).thenReturn(ChatsState());
when(chatsCubit.stream).thenAnswer((_) => const Stream.empty());
when(chatsCubit.close()).thenAnswer((_) async => Future<void>.value());
await tester.pumpWidget(
wrap(
const ChatScreen(uuid: 'uuid', sendInitialMessage: false),
chatsCubit,
),
);
await tester.pump();
await tester.pump(const Duration(milliseconds: 200));
}
ChatMessageModel incomingCallMessage() {
return ChatMessageModel(
id: 9,
data: 'Видеозвонок',
mediaData: const [],
authorId: 2,
updatedAt: DateTime(2025, 1, 2, 11),
isRead: true,
isCurrentUserAuthor: false,
roomId: '1',
type: ChatMessageType.videoCallStarted,
messageState: MessageState.sent,
uuid: 'call',
);
}
testWidgets('shows the call button for an active consultation', (
tester,
) async {
await pumpLoadedChat(
tester,
plan: chosenPlan(ChosenPlanStateEnum.stateInProgress),
messages: [incomingCallMessage()],
);
expect(find.byIcon(Icons.videocam_rounded), findsOneWidget);
expect(find.byType(VideoCallChatMessageWidget), findsOneWidget);
});
testWidgets('hides the call button for a finished consultation', (
tester,
) async {
await pumpLoadedChat(
tester,
plan: chosenPlan(ChosenPlanStateEnum.stateDone),
messages: [incomingCallMessage()],
);
expect(find.byIcon(Icons.videocam_rounded), findsNothing);
expect(find.byType(VideoCallChatMessageWidget), findsNothing);
expect(find.text('Видеозвонок'), findsOneWidget);
});
testWidgets('hides the call button for a canceled consultation', (
tester,
) async {
await pumpLoadedChat(
tester,
plan: chosenPlan(ChosenPlanStateEnum.stateCanceledByTheInitiator),
);
expect(find.byIcon(Icons.videocam_rounded), findsNothing);
});
});
}