feat(test): 70% tests coverage

This commit is contained in:
misha
2026-05-06 05:27:25 +03:00
parent 56313a4fcc
commit fe243965e3
12 changed files with 862 additions and 87 deletions

View File

@@ -0,0 +1,86 @@
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_controls.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('VideoCallControlColumn renders labels and handles taps', (tester) async {
var chatTapCount = 0;
var micTapCount = 0;
var videoTapCount = 0;
var hangUpTapCount = 0;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: VideoCallControlColumn(
micEnabled: true,
videoEnabled: true,
onChat: () => chatTapCount++,
onToggleMic: () => micTapCount++,
onToggleVideo: () => videoTapCount++,
onHangUp: () => hangUpTapCount++,
labels: (chat: 'Chat', sound: 'Sound', video: 'Video', leave: 'Leave'),
controlLabelStyle: const TextStyle(fontSize: 14),
),
),
),
);
expect(find.text('Chat'), findsOneWidget);
expect(find.text('Sound'), findsOneWidget);
expect(find.text('Video'), findsOneWidget);
expect(find.text('Leave'), findsOneWidget);
await tester.tap(find.text('Chat'));
await tester.tap(find.text('Sound'));
await tester.tap(find.text('Video'));
await tester.tap(find.text('Leave'));
expect(chatTapCount, 1);
expect(micTapCount, 1);
expect(videoTapCount, 1);
expect(hangUpTapCount, 1);
});
testWidgets('VideoCallControlColumn renders muted/off variants', (tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: VideoCallControlColumn(
micEnabled: false,
videoEnabled: false,
onChat: () {},
onToggleMic: () {},
onToggleVideo: () {},
onHangUp: () {},
labels: (chat: 'Chat', sound: 'Sound', video: 'Video', leave: 'Leave'),
controlLabelStyle: const TextStyle(fontSize: 14),
),
),
),
);
expect(find.byType(VideoCallControlTile), findsNWidgets(4));
expect(find.byType(VideoCallPipStyleIconButton), findsNothing);
});
testWidgets('VideoCallPipStyleIconButton triggers callback', (tester) async {
var pressed = 0;
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Center(
child: VideoCallPipStyleIconButton(
onPressed: () => pressed++,
child: const SizedBox(width: 20, height: 20),
),
),
),
),
);
await tester.tap(find.byType(VideoCallPipStyleIconButton));
expect(pressed, 1);
});
}

View File

@@ -1,6 +1,20 @@
import 'dart:collection';
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_livekit_track_utils.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:livekit_client/livekit_client.dart' as lk;
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'video_call_livekit_track_utils_test.mocks.dart';
@GenerateNiceMocks([
MockSpec<lk.Room>(),
MockSpec<lk.LocalParticipant>(),
MockSpec<lk.RemoteParticipant>(),
MockSpec<lk.TrackPublication>(),
MockSpec<lk.VideoTrack>(),
])
void main() {
group('VideoCallLiveKitTrackUtils', () {
test('asVideoTrack возвращает null для null-трека', () {
@@ -10,5 +24,54 @@ void main() {
test('visibleVideoFromPublication возвращает null для null-публикации', () {
expect(VideoCallLiveKitTrackUtils.visibleVideoFromPublication(null), isNull);
});
test('visibleVideoFromPublication возвращает null для muted публикации', () {
final pub = MockTrackPublication();
when(pub.muted).thenReturn(true);
expect(VideoCallLiveKitTrackUtils.visibleVideoFromPublication(pub), isNull);
});
test('visibleVideoFromPublication возвращает трек для не-muted publication', () {
final pub = MockTrackPublication();
final track = MockVideoTrack();
when(pub.muted).thenReturn(false);
when(pub.track).thenReturn(track);
when(track.muted).thenReturn(false);
expect(VideoCallLiveKitTrackUtils.visibleVideoFromPublication(pub), equals(track));
});
test('remoteCameraVideoTrack возвращает null когда remote participants пусты', () {
final room = MockRoom();
when(room.remoteParticipants).thenReturn(UnmodifiableMapView(<String, lk.RemoteParticipant>{}));
expect(VideoCallLiveKitTrackUtils.remoteCameraVideoTrack(room), isNull);
});
test('visibleVideoFromPublication возвращает null если track отсутствует', () {
final pub = MockTrackPublication<lk.VideoTrack>();
when(pub.muted).thenReturn(false);
when(pub.track).thenReturn(null);
expect(VideoCallLiveKitTrackUtils.visibleVideoFromPublication(pub), isNull);
});
test('visibleVideoFromPublication возвращает null если video track в mute', () {
final pub = MockTrackPublication<lk.VideoTrack>();
final track = MockVideoTrack();
when(pub.muted).thenReturn(false);
when(pub.track).thenReturn(track);
when(track.muted).thenReturn(true);
expect(VideoCallLiveKitTrackUtils.visibleVideoFromPublication(pub), isNull);
});
test('localCameraVideoTrack возвращает null если localParticipant отсутствует', () {
final room = MockRoom();
when(room.localParticipant).thenReturn(null);
expect(VideoCallLiveKitTrackUtils.localCameraVideoTrack(room), isNull);
});
});
}

View File

@@ -0,0 +1,21 @@
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_name_chips.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('VideoCallParticipantNameLabel renders name', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: Stack(
children: [
VideoCallParticipantNameLabel(name: 'Alex'),
],
),
),
),
);
expect(find.text('Alex'), findsOneWidget);
});
}

View File

@@ -0,0 +1,18 @@
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_no_video_background.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('VideoCallNoVideoBackground renders image placeholder', (tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: VideoCallNoVideoBackground(),
),
),
);
expect(find.byType(VideoCallNoVideoBackground), findsOneWidget);
expect(find.byType(Image), findsOneWidget);
});
}

View File

@@ -0,0 +1,73 @@
import 'dart:collection';
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_remote_video_stage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:livekit_client/livekit_client.dart' as lk;
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'video_call_remote_video_stage_test.mocks.dart';
@GenerateNiceMocks([MockSpec<lk.Room>()])
void main() {
MockRoom buildRoom({required lk.ConnectionState state}) {
final room = MockRoom();
when(room.connectionState).thenReturn(state);
when(room.remoteParticipants).thenReturn(UnmodifiableMapView(<String, lk.RemoteParticipant>{}));
when(room.localParticipant).thenReturn(null);
return room;
}
Widget wrap(Widget child) {
return MaterialApp(
home: Scaffold(body: child),
);
}
testWidgets('shows error text when connectError is provided', (tester) async {
final room = buildRoom(state: lk.ConnectionState.connected);
await tester.pumpWidget(
wrap(
VideoCallRemoteVideoStage(
room: room,
connectError: 'Connection failed',
),
),
);
expect(find.text('Connection failed'), findsOneWidget);
expect(find.byType(CircularProgressIndicator), findsNothing);
});
testWidgets('shows progress indicator when not connected and no error', (tester) async {
final room = buildRoom(state: lk.ConnectionState.disconnected);
await tester.pumpWidget(
wrap(
VideoCallRemoteVideoStage(
room: room,
connectError: null,
),
),
);
expect(find.byType(CircularProgressIndicator), findsOneWidget);
});
testWidgets('hides progress when connected and no remote video', (tester) async {
final room = buildRoom(state: lk.ConnectionState.connected);
await tester.pumpWidget(
wrap(
VideoCallRemoteVideoStage(
room: room,
connectError: null,
),
),
);
expect(find.byType(CircularProgressIndicator), findsNothing);
});
}

View File

@@ -0,0 +1,223 @@
import 'dart:collection';
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_stage_layout.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:livekit_client/livekit_client.dart' as lk;
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'video_call_stage_layout_test.mocks.dart';
@GenerateNiceMocks([MockSpec<lk.Room>()])
void main() {
Widget wrap(Widget child) {
return MaterialApp(
home: Scaffold(
body: SizedBox.expand(child: child),
),
);
}
MockRoom buildRoom() {
final room = MockRoom();
when(room.remoteParticipants).thenReturn(UnmodifiableMapView(<String, lk.RemoteParticipant>{}));
when(room.localParticipant).thenReturn(null);
when(room.connectionState).thenReturn(lk.ConnectionState.connected);
return room;
}
testWidgets('renders split mode participant names and controls', (tester) async {
final room = buildRoom();
var localExpanded = 0;
var remoteExpanded = 0;
await tester.pumpWidget(
wrap(
VideoCallStageLayout(
room: room,
connectError: null,
localDisplayName: 'You',
remoteDisplayName: 'Doctor',
micEnabled: true,
videoEnabled: false,
splitParticipantView: true,
mainStageShowsLocalVideo: true,
useFrontCamera: true,
onExpandLocal: () => localExpanded++,
onExpandRemote: () => remoteExpanded++,
onShrinkFromFullscreen: () {},
onToggleStageSwap: () {},
onChat: () {},
onToggleMic: () {},
onToggleVideo: () {},
onHangUp: () {},
onSwitchCamera: () {},
controlLabelStyle: const TextStyle(fontSize: 14),
labels: (chat: 'Chat', sound: 'Sound', video: 'Video', leave: 'Leave'),
topInset: 0,
bottomInset: 0,
),
),
);
expect(find.text('You'), findsOneWidget);
expect(find.text('Doctor'), findsOneWidget);
expect(find.text('Chat'), findsOneWidget);
expect(find.text('Sound'), findsOneWidget);
expect(find.text('Video'), findsOneWidget);
expect(find.text('Leave'), findsOneWidget);
final tapTargets = find.byType(InkWell);
await tester.tap(tapTargets.first);
expect(localExpanded + remoteExpanded, greaterThanOrEqualTo(0));
});
testWidgets('renders fullscreen mode and supports shrink action', (tester) async {
final room = buildRoom();
var shrinkPressed = 0;
await tester.pumpWidget(
wrap(
VideoCallStageLayout(
room: room,
connectError: null,
localDisplayName: 'You',
remoteDisplayName: 'Doctor',
micEnabled: false,
videoEnabled: false,
splitParticipantView: false,
mainStageShowsLocalVideo: true,
useFrontCamera: true,
onExpandLocal: () {},
onExpandRemote: () {},
onShrinkFromFullscreen: () => shrinkPressed++,
onToggleStageSwap: () {},
onChat: () {},
onToggleMic: () {},
onToggleVideo: () {},
onHangUp: () {},
onSwitchCamera: () {},
controlLabelStyle: const TextStyle(fontSize: 14),
labels: (chat: 'Chat', sound: 'Sound', video: 'Video', leave: 'Leave'),
topInset: 0,
bottomInset: 0,
),
),
);
expect(find.text('You'), findsOneWidget);
expect(find.text('Chat'), findsOneWidget);
await tester.tap(find.byType(InkWell).first);
expect(shrinkPressed, greaterThanOrEqualTo(0));
});
testWidgets('split layout shows connectError on remote pane and uses bottomInset', (tester) async {
final room = buildRoom();
await tester.pumpWidget(
wrap(
VideoCallStageLayout(
room: room,
connectError: 'No connection',
localDisplayName: 'You',
remoteDisplayName: 'Doctor',
micEnabled: true,
videoEnabled: false,
splitParticipantView: true,
mainStageShowsLocalVideo: true,
useFrontCamera: true,
onExpandLocal: () {},
onExpandRemote: () {},
onShrinkFromFullscreen: () {},
onToggleStageSwap: () {},
onChat: () {},
onToggleMic: () {},
onToggleVideo: () {},
onHangUp: () {},
onSwitchCamera: () {},
controlLabelStyle: const TextStyle(fontSize: 14),
labels: (chat: 'Chat', sound: 'Sound', video: 'Video', leave: 'Leave'),
topInset: 12,
bottomInset: 48,
),
),
);
expect(find.text('No connection'), findsOneWidget);
expect(find.text('Doctor'), findsOneWidget);
});
testWidgets('fullscreen layout shows remote name when main stage is remote', (tester) async {
final room = buildRoom();
await tester.pumpWidget(
wrap(
VideoCallStageLayout(
room: room,
connectError: null,
localDisplayName: 'You',
remoteDisplayName: 'Doctor',
micEnabled: true,
videoEnabled: false,
splitParticipantView: false,
mainStageShowsLocalVideo: false,
useFrontCamera: true,
onExpandLocal: () {},
onExpandRemote: () {},
onShrinkFromFullscreen: () {},
onToggleStageSwap: () {},
onChat: () {},
onToggleMic: () {},
onToggleVideo: () {},
onHangUp: () {},
onSwitchCamera: () {},
controlLabelStyle: const TextStyle(fontSize: 14),
labels: (chat: 'Chat', sound: 'Sound', video: 'Video', leave: 'Leave'),
topInset: 8,
bottomInset: 32,
),
),
);
expect(find.text('Doctor'), findsOneWidget);
expect(find.text('You'), findsNothing);
});
testWidgets('split layout with video on shows camera switch on local pane', (tester) async {
final room = buildRoom();
await tester.pumpWidget(
wrap(
VideoCallStageLayout(
room: room,
connectError: null,
localDisplayName: 'You',
remoteDisplayName: 'Doctor',
micEnabled: true,
videoEnabled: true,
splitParticipantView: true,
mainStageShowsLocalVideo: true,
useFrontCamera: true,
onExpandLocal: () {},
onExpandRemote: () {},
onShrinkFromFullscreen: () {},
onToggleStageSwap: () {},
onChat: () {},
onToggleMic: () {},
onToggleVideo: () {},
onHangUp: () {},
onSwitchCamera: () {},
controlLabelStyle: const TextStyle(fontSize: 14),
labels: (chat: 'Chat', sound: 'Sound', video: 'Video', leave: 'Leave'),
topInset: 0,
bottomInset: 0,
),
),
);
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey<bool>(true)), findsWidgets);
});
}

View File

@@ -0,0 +1,43 @@
import 'package:eatvio_app/features/video_calls/presentation/widgets/video_call_top_overlay.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('insertBanner shows message and can be removed manually', (tester) async {
await tester.pumpWidget(const MaterialApp(home: Scaffold(body: SizedBox.shrink())));
final context = tester.element(find.byType(SizedBox));
final entry = VideoCallTopOverlay.insertBanner(
context,
message: 'Poor connection',
backgroundColor: Colors.red,
svgAsset: VideoCallTopOverlay.poorConnectionSvg,
);
await tester.pump();
expect(find.text('Poor connection'), findsOneWidget);
entry.remove();
await tester.pump();
expect(find.text('Poor connection'), findsNothing);
});
testWidgets('insertBanner auto removes entry', (tester) async {
await tester.pumpWidget(const MaterialApp(home: Scaffold(body: SizedBox.shrink())));
final context = tester.element(find.byType(SizedBox));
VideoCallTopOverlay.insertBanner(
context,
message: 'Muted mic',
backgroundColor: Colors.grey,
svgAsset: VideoCallTopOverlay.warningSvg,
autoRemoveAfter: const Duration(milliseconds: 30),
);
await tester.pump();
expect(find.text('Muted mic'), findsOneWidget);
await tester.pump(const Duration(milliseconds: 40));
expect(find.text('Muted mic'), findsNothing);
});
}