Start work on rendering channel participants in collab panel

Co-authored-by: mikayla <mikayla@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-08-02 15:09:37 -07:00
parent a9de73739a
commit fca8cdcb8e
9 changed files with 192 additions and 60 deletions

View file

@ -1,5 +1,5 @@
use call::ActiveCall;
use client::Channel;
use client::{Channel, User};
use gpui::{executor::Deterministic, TestAppContext};
use std::sync::Arc;
@ -26,6 +26,7 @@ async fn test_basic_channels(
.await
.unwrap();
deterministic.run_until_parked();
client_a.channel_store().read_with(cx_a, |channels, _| {
assert_eq!(
channels.channels(),
@ -105,6 +106,13 @@ async fn test_basic_channels(
.read_with(cx_b, |channels, _| assert_eq!(channels.channels(), &[]));
}
fn assert_participants_eq(participants: &[Arc<User>], expected_partitipants: &[u64]) {
assert_eq!(
participants.iter().map(|p| p.id).collect::<Vec<_>>(),
expected_partitipants
);
}
#[gpui::test]
async fn test_channel_room(
deterministic: Arc<Deterministic>,
@ -116,7 +124,7 @@ async fn test_channel_room(
let mut server = TestServer::start(&deterministic).await;
let client_a = server.create_client(cx_a, "user_a").await;
let client_b = server.create_client(cx_b, "user_b").await;
let client_c = server.create_client(cx_b, "user_c").await;
let client_c = server.create_client(cx_c, "user_c").await;
let zed_id = server
.make_channel(
@ -134,8 +142,21 @@ async fn test_channel_room(
.await
.unwrap();
// TODO Test that B and C sees A in the channel room
// Give everyone a chance to observe user A joining
deterministic.run_until_parked();
client_a.channel_store().read_with(cx_a, |channels, _| {
assert_participants_eq(
channels.channel_participants(zed_id),
&[client_a.user_id().unwrap()],
);
});
client_b.channel_store().read_with(cx_b, |channels, _| {
assert_participants_eq(
channels.channel_participants(zed_id),
&[client_a.user_id().unwrap()],
);
assert_eq!(
channels.channels(),
&[Arc::new(Channel {
@ -147,15 +168,41 @@ async fn test_channel_room(
)
});
client_c.channel_store().read_with(cx_c, |channels, _| {
assert_participants_eq(
channels.channel_participants(zed_id),
&[client_a.user_id().unwrap()],
);
});
active_call_b
.update(cx_b, |active_call, cx| active_call.join_channel(zed_id, cx))
.await
.unwrap();
// TODO Test that C sees A and B in the channel room
deterministic.run_until_parked();
client_a.channel_store().read_with(cx_a, |channels, _| {
assert_participants_eq(
channels.channel_participants(zed_id),
&[client_a.user_id().unwrap(), client_b.user_id().unwrap()],
);
});
client_b.channel_store().read_with(cx_b, |channels, _| {
assert_participants_eq(
channels.channel_participants(zed_id),
&[client_a.user_id().unwrap(), client_b.user_id().unwrap()],
);
});
client_c.channel_store().read_with(cx_c, |channels, _| {
assert_participants_eq(
channels.channel_participants(zed_id),
&[client_a.user_id().unwrap(), client_b.user_id().unwrap()],
);
});
let room_a = active_call_a.read_with(cx_a, |call, _| call.room().unwrap().clone());
room_a.read_with(cx_a, |room, _| assert!(room.is_connected()));
assert_eq!(
@ -183,14 +230,47 @@ async fn test_channel_room(
.await
.unwrap();
// TODO Make sure that C sees A leave
deterministic.run_until_parked();
client_a.channel_store().read_with(cx_a, |channels, _| {
assert_participants_eq(
channels.channel_participants(zed_id),
&[client_b.user_id().unwrap()],
);
});
client_b.channel_store().read_with(cx_b, |channels, _| {
assert_participants_eq(
channels.channel_participants(zed_id),
&[client_b.user_id().unwrap()],
);
});
client_c.channel_store().read_with(cx_c, |channels, _| {
assert_participants_eq(
channels.channel_participants(zed_id),
&[client_b.user_id().unwrap()],
);
});
active_call_b
.update(cx_b, |active_call, cx| active_call.hang_up(cx))
.await
.unwrap();
// TODO Make sure that C sees B leave
deterministic.run_until_parked();
client_a.channel_store().read_with(cx_a, |channels, _| {
assert_participants_eq(channels.channel_participants(zed_id), &[]);
});
client_b.channel_store().read_with(cx_b, |channels, _| {
assert_participants_eq(channels.channel_participants(zed_id), &[]);
});
client_c.channel_store().read_with(cx_c, |channels, _| {
assert_participants_eq(channels.channel_participants(zed_id), &[]);
});
active_call_a
.update(cx_a, |active_call, cx| active_call.join_channel(zed_id, cx))