Skip to content

Commit 0d3d299

Browse files
authored
chore: Add first tests for video_flutter and noise cancellation (#972)
* Add first tests for video_flutter and noise cancellation * chore: also test disabled microphone
1 parent 28965ee commit 0d3d299

File tree

4 files changed

+105
-0
lines changed

4 files changed

+105
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_test/flutter_test.dart';
3+
import 'package:mocktail/mocktail.dart';
4+
import 'package:stream_video_flutter/stream_video_flutter.dart';
5+
6+
import '../../../test_utils/test_wrapper.dart';
7+
8+
void main() {
9+
testWidgets('ToggleMicrophoneOption', (tester) async {
10+
var isAudioEnabled = true;
11+
12+
final localParticipant = MockCallParticipantState();
13+
final call = MockCall();
14+
15+
when(() => localParticipant.isAudioEnabled).thenReturn(isAudioEnabled);
16+
when(() => call.setMicrophoneEnabled(enabled: any(named: 'enabled')))
17+
.thenAnswer(
18+
(invocation) async {
19+
isAudioEnabled =
20+
invocation.namedArguments[const Symbol('enabled')] as bool;
21+
return const Result.success(none);
22+
},
23+
);
24+
25+
// Microphone is enabled
26+
await tester.pumpWidget(
27+
TestWrapper(
28+
child: ToggleMicrophoneOption(
29+
localParticipant: localParticipant,
30+
call: call,
31+
),
32+
),
33+
);
34+
35+
expect(find.byIcon(Icons.mic_rounded), findsOneWidget);
36+
expect(find.byIcon(Icons.mic_off_rounded), findsNothing);
37+
38+
await tester.tap(find.byIcon(Icons.mic_rounded));
39+
await tester.pumpAndSettle();
40+
41+
verify(() => call.setMicrophoneEnabled(enabled: false)).called(1);
42+
43+
// Microphone is disabled
44+
when(() => localParticipant.isAudioEnabled).thenReturn(isAudioEnabled);
45+
await tester.pumpWidget(
46+
TestWrapper(
47+
child: ToggleMicrophoneOption(
48+
localParticipant: localParticipant,
49+
call: call,
50+
),
51+
),
52+
);
53+
expect(find.byIcon(Icons.mic_rounded), findsNothing);
54+
expect(find.byIcon(Icons.mic_off_rounded), findsOneWidget);
55+
});
56+
}
57+
58+
// ignore: avoid_implementing_value_types
59+
class MockCallParticipantState extends Mock implements CallParticipantState {}
60+
61+
class MockCall extends Mock implements Call {}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:flutter/material.dart';
2+
3+
class TestWrapper extends StatelessWidget {
4+
const TestWrapper({super.key, required this.child});
5+
6+
final Widget child;
7+
8+
@override
9+
Widget build(BuildContext context) {
10+
return MaterialApp(
11+
home: Scaffold(body: child),
12+
);
13+
}
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'package:stream_video_noise_cancellation/stream_video_noise_cancellation_platform_interface.dart';
2+
3+
class FakeNoiseCancellationPlatform
4+
extends StreamVideoNoiseCancellationPlatform {
5+
int registerProcessorCallCount = 0;
6+
7+
@override
8+
Future<void> registerProcessor() async {
9+
registerProcessorCallCount++;
10+
}
11+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:stream_video_noise_cancellation/noise_cancellation_audio_processor.dart';
3+
import 'package:stream_video_noise_cancellation/stream_video_noise_cancellation_platform_interface.dart';
4+
5+
import 'mock_noise_cancellation_platform.dart';
6+
7+
void main() {
8+
test('NoiseCancellationAudioProcessor init registers processor', () async {
9+
final platform = FakeNoiseCancellationPlatform();
10+
StreamVideoNoiseCancellationPlatform.instance = platform;
11+
12+
expect(platform.registerProcessorCallCount, 0);
13+
14+
final _ = NoiseCancellationAudioProcessor();
15+
await Future.delayed(const Duration());
16+
17+
expect(platform.registerProcessorCallCount, 1);
18+
});
19+
}

0 commit comments

Comments
 (0)