channel_guest_tests.rs

 1use crate::tests::TestServer;
 2use call::ActiveCall;
 3use gpui::{BackgroundExecutor, TestAppContext, VisualTestContext};
 4use rpc::proto;
 5use workspace::Workspace;
 6
 7#[gpui::test]
 8async fn test_channel_guests(
 9    executor: BackgroundExecutor,
10    cx_a: &mut TestAppContext,
11    cx_b: &mut TestAppContext,
12) {
13    let mut server = TestServer::start(executor.clone()).await;
14    let client_a = server.create_client(cx_a, "user_a").await;
15    let client_b = server.create_client(cx_b, "user_b").await;
16
17    let channel_id = server
18        .make_channel("the-channel", None, (&client_a, cx_a), &mut [])
19        .await;
20
21    client_a
22        .channel_store()
23        .update(cx_a, |channel_store, cx| {
24            channel_store.set_channel_visibility(channel_id, proto::ChannelVisibility::Public, cx)
25        })
26        .await
27        .unwrap();
28
29    client_a
30        .fs()
31        .insert_tree(
32            "/a",
33            serde_json::json!({
34                "a.txt": "a-contents",
35            }),
36        )
37        .await;
38
39    let active_call_a = cx_a.read(ActiveCall::global);
40
41    // Client A shares a project in the channel
42    active_call_a
43        .update(cx_a, |call, cx| call.join_channel(channel_id, cx))
44        .await
45        .unwrap();
46    let (project_a, _) = client_a.build_local_project("/a", cx_a).await;
47    let project_id = active_call_a
48        .update(cx_a, |call, cx| call.share_project(project_a.clone(), cx))
49        .await
50        .unwrap();
51    cx_a.executor().run_until_parked();
52
53    // Client B joins channel A as a guest
54    cx_b.update(|cx| workspace::join_channel(channel_id, client_b.app_state.clone(), None, cx))
55        .await
56        .unwrap();
57
58    // b should be following a in the shared project.
59    // B is a guest,
60    cx_a.executor().run_until_parked();
61
62    // todo!() the test window does not call activation handlers
63    // correctly yet, so this API does not work.
64    // let project_b = active_call_b.read_with(cx_b, |call, _| {
65    //     call.location()
66    //         .unwrap()
67    //         .upgrade()
68    //         .expect("should not be weak")
69    // });
70
71    let window_b = cx_b.update(|cx| cx.active_window().unwrap());
72    let cx_b = &mut VisualTestContext::from_window(window_b, cx_b);
73
74    let workspace_b = window_b
75        .downcast::<Workspace>()
76        .unwrap()
77        .root_view(cx_b)
78        .unwrap();
79    let project_b = workspace_b.update(cx_b, |workspace, _| workspace.project().clone());
80
81    assert_eq!(
82        project_b.read_with(cx_b, |project, _| project.remote_id()),
83        Some(project_id),
84    );
85    assert!(project_b.read_with(cx_b, |project, _| project.is_read_only()));
86
87    assert!(project_b
88        .update(cx_b, |project, cx| {
89            let worktree_id = project.worktrees().next().unwrap().read(cx).id();
90            project.create_entry((worktree_id, "b.txt"), false, cx)
91        })
92        .await
93        .is_err())
94}