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());
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user