tests and mocks for e2e testing (#78)
* tests and mocks for e2e testing * formatting * fix analyze errors
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
@Timeout(Duration(seconds: 5))
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:livekit_client/livekit_client.dart';
|
||||
|
||||
import '../mock/e2e_container.dart';
|
||||
import '../mock/test_data.dart';
|
||||
import '../mock/websocket_mock.dart';
|
||||
import 'signal_client_test.dart';
|
||||
|
||||
void main() {
|
||||
late E2EContainer container;
|
||||
late Room room;
|
||||
late MockWebSocketConnector ws;
|
||||
setUp(() async {
|
||||
container = E2EContainer();
|
||||
room = container.room;
|
||||
ws = container.wsConnector;
|
||||
await container.connectRoom();
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await container.dispose();
|
||||
});
|
||||
|
||||
group('connection', () {
|
||||
test('disconnect and connect', () async {
|
||||
await room.disconnect();
|
||||
await container.connectRoom();
|
||||
expect(room.connectionState, ConnectionState.connected);
|
||||
expect(room.localParticipant?.sid, joinResponse.join.participant.sid);
|
||||
}, skip: 'todo');
|
||||
});
|
||||
|
||||
group('room updates', () {
|
||||
test('participant join', () async {
|
||||
expect(
|
||||
room.events.streamCtrl.stream,
|
||||
emits(predicate<ParticipantConnectedEvent>(
|
||||
(event) => event.participant.sid == remoteParticipantData.sid,
|
||||
)),
|
||||
);
|
||||
ws.onData(participantJoinResponse.writeToBuffer());
|
||||
|
||||
await room.events.waitFor<ParticipantConnectedEvent>(
|
||||
duration: const Duration(seconds: 1));
|
||||
expect(room.participants.length, 1);
|
||||
});
|
||||
|
||||
test('participant disconnect', () async {
|
||||
ws.onData(participantJoinResponse.writeToBuffer());
|
||||
await room.events.waitFor<ParticipantConnectedEvent>(
|
||||
duration: const Duration(seconds: 1));
|
||||
|
||||
ws.onData(participantDisconnectResponse.writeToBuffer());
|
||||
expect(
|
||||
room.events.streamCtrl.stream,
|
||||
emitsInOrder(<Matcher>[
|
||||
predicate<TrackUnpublishedEvent>(
|
||||
(event) => event.participant.sid == remoteParticipantData.sid),
|
||||
predicate<ParticipantDisconnectedEvent>(
|
||||
(event) => event.participant.sid == remoteParticipantData.sid),
|
||||
]),
|
||||
);
|
||||
|
||||
await room.events.waitFor<ParticipantDisconnectedEvent>(
|
||||
duration: const Duration(seconds: 1));
|
||||
expect(room.participants.length, 0);
|
||||
});
|
||||
|
||||
test('participant metadata changed', () async {
|
||||
ws.onData(participantJoinResponse.writeToBuffer());
|
||||
await room.events.waitFor<ParticipantConnectedEvent>(
|
||||
duration: const Duration(seconds: 1));
|
||||
|
||||
ws.onData(participantMetadataChangedResponse.writeToBuffer());
|
||||
expect(
|
||||
room.events.streamCtrl.stream,
|
||||
emits(
|
||||
predicate<ParticipantMetadataUpdatedEvent>((event) =>
|
||||
event.participant.metadata ==
|
||||
participantMetadataChangedResponse
|
||||
.update.participants[0].metadata),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('room update', () async {
|
||||
ws.onData(roomUpdateResponse.writeToBuffer());
|
||||
// TODO: room update event and handling
|
||||
}, skip: 'todo');
|
||||
|
||||
test('connection quality', () async {
|
||||
expect(
|
||||
room.events.streamCtrl.stream,
|
||||
emits(predicate<ParticipantConnectionQualityUpdatedEvent>((event) =>
|
||||
event.participant.sid == localParticipantData.sid &&
|
||||
event.connectionQuality == ConnectionQuality.excellent)),
|
||||
);
|
||||
ws.onData(connectionQualityResponse.writeToBuffer());
|
||||
});
|
||||
|
||||
test('active speakers changed', () async {
|
||||
ws.onData(participantJoinResponse.writeToBuffer());
|
||||
await room.events.waitFor<ParticipantConnectedEvent>(
|
||||
duration: const Duration(seconds: 1));
|
||||
|
||||
expect(
|
||||
room.events.streamCtrl.stream,
|
||||
emits(
|
||||
predicate<ActiveSpeakersChangedEvent>(
|
||||
(event) => event.speakers[0].sid == remoteParticipantData.sid),
|
||||
),
|
||||
);
|
||||
ws.onData(activeSpeakerResponse.writeToBuffer());
|
||||
});
|
||||
|
||||
test('leave', () async {
|
||||
expect(
|
||||
room.events.streamCtrl.stream,
|
||||
emits(predicate<RoomDisconnectedEvent>((event) =>
|
||||
room.connectionState == ConnectionState.disconnected)));
|
||||
ws.onData(leaveResponse.writeToBuffer());
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
@Timeout(Duration(seconds: 5))
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:livekit_client/livekit_client.dart';
|
||||
import 'package:livekit_client/src/core/signal_client.dart';
|
||||
import 'package:livekit_client/src/internal/events.dart';
|
||||
import 'package:livekit_client/src/proto/livekit_models.pb.dart' as lk_models;
|
||||
import 'package:livekit_client/src/proto/livekit_rtc.pb.dart' as lk_rtc;
|
||||
import 'package:protobuf/protobuf.dart';
|
||||
|
||||
import '../mock/test_data.dart';
|
||||
import '../mock/websocket_mock.dart';
|
||||
|
||||
void main() {
|
||||
late SignalClient client;
|
||||
late MockWebSocketConnector connector;
|
||||
setUp(() async {
|
||||
connector = MockWebSocketConnector();
|
||||
client = SignalClient(connector.connect);
|
||||
});
|
||||
|
||||
group('connection', () {
|
||||
test('connect', () async {
|
||||
expect(
|
||||
client.events.streamCtrl.stream,
|
||||
emitsInOrder(<Matcher>[
|
||||
predicate<SignalConnectionStateUpdatedEvent>(
|
||||
(event) => event.connectionState == ConnectionState.connecting),
|
||||
predicate<SignalConnectionStateUpdatedEvent>(
|
||||
(event) => event.connectionState == ConnectionState.connected),
|
||||
]));
|
||||
await client.connect(exampleUri, token);
|
||||
});
|
||||
test('reconnect', () async {
|
||||
expect(
|
||||
client.events.streamCtrl.stream,
|
||||
emitsInOrder(<Matcher>[
|
||||
predicate<SignalConnectionStateUpdatedEvent>((event) =>
|
||||
event.connectionState == ConnectionState.reconnecting),
|
||||
predicate<SignalConnectionStateUpdatedEvent>((event) =>
|
||||
event.connectionState == ConnectionState.connected &&
|
||||
event.didReconnect == true),
|
||||
]));
|
||||
await client.connect(exampleUri, token, reconnect: true);
|
||||
});
|
||||
});
|
||||
|
||||
group('messaging', () {
|
||||
test('join', () async {
|
||||
await client.connect(exampleUri, token);
|
||||
expect(client.events.streamCtrl.stream,
|
||||
emits(isA<SignalJoinResponseEvent>()));
|
||||
connector.handlers?.onData!(joinResponse.writeToBuffer());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
final lk_rtc.SignalResponse joinResponse = lk_rtc.SignalResponse(
|
||||
join: lk_rtc.JoinResponse(
|
||||
room: lk_models.Room(
|
||||
name: 'room_name',
|
||||
sid: 'room_sid',
|
||||
),
|
||||
participant: localParticipantData,
|
||||
subscriberPrimary: true,
|
||||
serverVersion: '99.999',
|
||||
),
|
||||
);
|
||||
|
||||
final lk_rtc.SignalResponse offerResponse = lk_rtc.SignalResponse(
|
||||
offer: lk_rtc.SessionDescription(
|
||||
sdp: 'remote_offer',
|
||||
type: 'offer',
|
||||
));
|
||||
|
||||
final lk_rtc.SignalResponse participantJoinResponse = lk_rtc.SignalResponse(
|
||||
update: lk_rtc.ParticipantUpdate(
|
||||
participants: [remoteParticipantData],
|
||||
),
|
||||
);
|
||||
|
||||
final lk_rtc.SignalResponse participantDisconnectResponse =
|
||||
lk_rtc.SignalResponse(
|
||||
update: lk_rtc.ParticipantUpdate(
|
||||
participants: [
|
||||
remoteParticipantData.deepCopy()
|
||||
..state = lk_models.ParticipantInfo_State.DISCONNECTED,
|
||||
],
|
||||
),
|
||||
);
|
||||
final lk_rtc.SignalResponse participantMetadataChangedResponse =
|
||||
lk_rtc.SignalResponse(
|
||||
update: lk_rtc.ParticipantUpdate(
|
||||
participants: [
|
||||
remoteParticipantData.deepCopy()..metadata = 'metadata_changed',
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
final lk_rtc.SignalResponse roomUpdateResponse = lk_rtc.SignalResponse(
|
||||
roomUpdate: lk_rtc.RoomUpdate(
|
||||
room: lk_models.Room(
|
||||
metadata: 'changed_metadata',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final lk_rtc.SignalResponse connectionQualityResponse = lk_rtc.SignalResponse(
|
||||
connectionQuality: lk_rtc.ConnectionQualityUpdate(updates: [
|
||||
lk_rtc.ConnectionQualityInfo(
|
||||
participantSid: localParticipantData.sid,
|
||||
quality: lk_models.ConnectionQuality.EXCELLENT,
|
||||
)
|
||||
]),
|
||||
);
|
||||
|
||||
final lk_rtc.SignalResponse activeSpeakerResponse = lk_rtc.SignalResponse(
|
||||
speakersChanged: lk_rtc.SpeakersChanged(
|
||||
speakers: [remoteSpeakerInfo],
|
||||
),
|
||||
);
|
||||
final lk_rtc.SignalResponse leaveResponse =
|
||||
lk_rtc.SignalResponse(leave: lk_rtc.LeaveRequest());
|
||||
const exampleUri = 'ws://www.example.com';
|
||||
const token = 'token';
|
||||
Reference in New Issue
Block a user