1use crate::{
2 db::{tests::TestDb, NewUserParams, UserId},
3 executor::Executor,
4 rpc::{Server, CLEANUP_TIMEOUT, RECONNECT_TIMEOUT},
5 AppState, Config,
6};
7use anyhow::anyhow;
8use call::ActiveCall;
9use channel::{ChannelBuffer, ChannelStore};
10use client::{
11 self, proto::PeerId, Client, Connection, Credentials, EstablishConnectionError, UserStore,
12};
13use collab_ui::channel_view::ChannelView;
14use collections::{HashMap, HashSet};
15use fs::FakeFs;
16use futures::{channel::oneshot, StreamExt as _};
17use gpui::{BackgroundExecutor, Context, Model, Task, TestAppContext, View, VisualTestContext};
18use language::LanguageRegistry;
19use node_runtime::FakeNodeRuntime;
20
21use notifications::NotificationStore;
22use parking_lot::Mutex;
23use project::{Project, WorktreeId};
24use rpc::{
25 proto::{self, ChannelRole},
26 RECEIVE_TIMEOUT,
27};
28use serde_json::json;
29use settings::SettingsStore;
30use std::{
31 cell::{Ref, RefCell, RefMut},
32 env,
33 ops::{Deref, DerefMut},
34 path::Path,
35 sync::{
36 atomic::{AtomicBool, AtomicUsize, Ordering::SeqCst},
37 Arc,
38 },
39};
40use util::{http::FakeHttpClient, SemanticVersion};
41use workspace::{Workspace, WorkspaceStore};
42
43pub struct TestServer {
44 pub app_state: Arc<AppState>,
45 pub test_live_kit_server: Arc<live_kit_client::TestServer>,
46 server: Arc<Server>,
47 next_github_user_id: i32,
48 connection_killers: Arc<Mutex<HashMap<PeerId, Arc<AtomicBool>>>>,
49 forbid_connections: Arc<AtomicBool>,
50 _test_db: TestDb,
51}
52
53pub struct TestClient {
54 pub username: String,
55 pub app_state: Arc<workspace::AppState>,
56 channel_store: Model<ChannelStore>,
57 notification_store: Model<NotificationStore>,
58 state: RefCell<TestClientState>,
59}
60
61#[derive(Default)]
62struct TestClientState {
63 local_projects: Vec<Model<Project>>,
64 remote_projects: Vec<Model<Project>>,
65 buffers: HashMap<Model<Project>, HashSet<Model<language::Buffer>>>,
66 channel_buffers: HashSet<Model<ChannelBuffer>>,
67}
68
69pub struct ContactsSummary {
70 pub current: Vec<String>,
71 pub outgoing_requests: Vec<String>,
72 pub incoming_requests: Vec<String>,
73}
74
75impl TestServer {
76 pub async fn start(deterministic: BackgroundExecutor) -> Self {
77 static NEXT_LIVE_KIT_SERVER_ID: AtomicUsize = AtomicUsize::new(0);
78
79 let use_postgres = env::var("USE_POSTGRES").ok();
80 let use_postgres = use_postgres.as_deref();
81 let test_db = if use_postgres == Some("true") || use_postgres == Some("1") {
82 TestDb::postgres(deterministic.clone())
83 } else {
84 TestDb::sqlite(deterministic.clone())
85 };
86 let live_kit_server_id = NEXT_LIVE_KIT_SERVER_ID.fetch_add(1, SeqCst);
87 let live_kit_server = live_kit_client::TestServer::create(
88 format!("http://livekit.{}.test", live_kit_server_id),
89 format!("devkey-{}", live_kit_server_id),
90 format!("secret-{}", live_kit_server_id),
91 deterministic.clone(),
92 )
93 .unwrap();
94 let app_state = Self::build_app_state(&test_db, &live_kit_server).await;
95 let epoch = app_state
96 .db
97 .create_server(&app_state.config.zed_environment)
98 .await
99 .unwrap();
100 let server = Server::new(
101 epoch,
102 app_state.clone(),
103 Executor::Deterministic(deterministic.clone()),
104 );
105 server.start().await.unwrap();
106 // Advance clock to ensure the server's cleanup task is finished.
107 deterministic.advance_clock(CLEANUP_TIMEOUT);
108 Self {
109 app_state,
110 server,
111 connection_killers: Default::default(),
112 forbid_connections: Default::default(),
113 next_github_user_id: 0,
114 _test_db: test_db,
115 test_live_kit_server: live_kit_server,
116 }
117 }
118
119 pub async fn start2(
120 cx_a: &mut TestAppContext,
121 cx_b: &mut TestAppContext,
122 ) -> (TestServer, TestClient, TestClient, u64) {
123 let mut server = Self::start(cx_a.executor()).await;
124 let client_a = server.create_client(cx_a, "user_a").await;
125 let client_b = server.create_client(cx_b, "user_b").await;
126 let channel_id = server
127 .make_channel(
128 "test-channel",
129 None,
130 (&client_a, cx_a),
131 &mut [(&client_b, cx_b)],
132 )
133 .await;
134 cx_a.run_until_parked();
135
136 (server, client_a, client_b, channel_id)
137 }
138
139 pub async fn start1<'a>(cx: &'a mut TestAppContext) -> TestClient {
140 let mut server = Self::start(cx.executor().clone()).await;
141 server.create_client(cx, "user_a").await
142 }
143
144 pub async fn reset(&self) {
145 self.app_state.db.reset();
146 let epoch = self
147 .app_state
148 .db
149 .create_server(&self.app_state.config.zed_environment)
150 .await
151 .unwrap();
152 self.server.reset(epoch);
153 }
154
155 pub async fn create_client(&mut self, cx: &mut TestAppContext, name: &str) -> TestClient {
156 cx.update(|cx| {
157 if cx.has_global::<SettingsStore>() {
158 panic!("Same cx used to create two test clients")
159 }
160 let settings = SettingsStore::test(cx);
161 cx.set_global(settings);
162 release_channel::init("0.0.0", cx);
163 client::init_settings(cx);
164 });
165
166 let http = FakeHttpClient::with_404_response();
167 let user_id = if let Ok(Some(user)) = self.app_state.db.get_user_by_github_login(name).await
168 {
169 user.id
170 } else {
171 let github_user_id = self.next_github_user_id;
172 self.next_github_user_id += 1;
173 self.app_state
174 .db
175 .create_user(
176 &format!("{name}@example.com"),
177 false,
178 NewUserParams {
179 github_login: name.into(),
180 github_user_id,
181 },
182 )
183 .await
184 .expect("creating user failed")
185 .user_id
186 };
187 let client_name = name.to_string();
188 let mut client = cx.update(|cx| Client::new(http.clone(), cx));
189 let server = self.server.clone();
190 let db = self.app_state.db.clone();
191 let connection_killers = self.connection_killers.clone();
192 let forbid_connections = self.forbid_connections.clone();
193
194 Arc::get_mut(&mut client)
195 .unwrap()
196 .set_id(user_id.to_proto())
197 .override_authenticate(move |cx| {
198 cx.spawn(|_| async move {
199 let access_token = "the-token".to_string();
200 Ok(Credentials {
201 user_id: user_id.to_proto(),
202 access_token,
203 })
204 })
205 })
206 .override_establish_connection(move |credentials, cx| {
207 assert_eq!(credentials.user_id, user_id.0 as u64);
208 assert_eq!(credentials.access_token, "the-token");
209
210 let server = server.clone();
211 let db = db.clone();
212 let connection_killers = connection_killers.clone();
213 let forbid_connections = forbid_connections.clone();
214 let client_name = client_name.clone();
215 cx.spawn(move |cx| async move {
216 if forbid_connections.load(SeqCst) {
217 Err(EstablishConnectionError::other(anyhow!(
218 "server is forbidding connections"
219 )))
220 } else {
221 let (client_conn, server_conn, killed) =
222 Connection::in_memory(cx.background_executor().clone());
223 let (connection_id_tx, connection_id_rx) = oneshot::channel();
224 let user = db
225 .get_user_by_id(user_id)
226 .await
227 .expect("retrieving user failed")
228 .unwrap();
229 cx.background_executor()
230 .spawn(server.handle_connection(
231 server_conn,
232 client_name,
233 user,
234 SemanticVersion::default(),
235 None,
236 Some(connection_id_tx),
237 Executor::Deterministic(cx.background_executor().clone()),
238 ))
239 .detach();
240 let connection_id = connection_id_rx.await.unwrap();
241 connection_killers
242 .lock()
243 .insert(connection_id.into(), killed);
244 Ok(client_conn)
245 }
246 })
247 });
248
249 let fs = FakeFs::new(cx.executor());
250 let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
251 let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx));
252 let mut language_registry = LanguageRegistry::test();
253 language_registry.set_executor(cx.executor());
254 let app_state = Arc::new(workspace::AppState {
255 client: client.clone(),
256 user_store: user_store.clone(),
257 workspace_store,
258 languages: Arc::new(language_registry),
259 fs: fs.clone(),
260 build_window_options: |_, _, _| Default::default(),
261 node_runtime: FakeNodeRuntime::new(),
262 });
263
264 cx.update(|cx| {
265 theme::init(theme::LoadThemes::JustBase, cx);
266 Project::init(&client, cx);
267 client::init(&client, cx);
268 language::init(cx);
269 editor::init(cx);
270 workspace::init(app_state.clone(), cx);
271 call::init(client.clone(), user_store.clone(), cx);
272 channel::init(&client, user_store.clone(), cx);
273 notifications::init(client.clone(), user_store, cx);
274 collab_ui::init(&app_state, cx);
275 file_finder::init(cx);
276 menu::init();
277 settings::KeymapFile::load_asset("keymaps/default.json", cx).unwrap();
278 });
279
280 client
281 .authenticate_and_connect(false, &cx.to_async())
282 .await
283 .unwrap();
284
285 let client = TestClient {
286 app_state,
287 username: name.to_string(),
288 channel_store: cx.read(ChannelStore::global).clone(),
289 notification_store: cx.read(NotificationStore::global).clone(),
290 state: Default::default(),
291 };
292 client.wait_for_current_user(cx).await;
293 client
294 }
295
296 pub fn disconnect_client(&self, peer_id: PeerId) {
297 self.connection_killers
298 .lock()
299 .remove(&peer_id)
300 .unwrap()
301 .store(true, SeqCst);
302 }
303
304 pub fn simulate_long_connection_interruption(
305 &self,
306 peer_id: PeerId,
307 deterministic: BackgroundExecutor,
308 ) {
309 self.forbid_connections();
310 self.disconnect_client(peer_id);
311 deterministic.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
312 self.allow_connections();
313 deterministic.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
314 deterministic.run_until_parked();
315 }
316
317 pub fn forbid_connections(&self) {
318 self.forbid_connections.store(true, SeqCst);
319 }
320
321 pub fn allow_connections(&self) {
322 self.forbid_connections.store(false, SeqCst);
323 }
324
325 pub async fn make_contacts(&self, clients: &mut [(&TestClient, &mut TestAppContext)]) {
326 for ix in 1..clients.len() {
327 let (left, right) = clients.split_at_mut(ix);
328 let (client_a, cx_a) = left.last_mut().unwrap();
329 for (client_b, cx_b) in right {
330 client_a
331 .app_state
332 .user_store
333 .update(*cx_a, |store, cx| {
334 store.request_contact(client_b.user_id().unwrap(), cx)
335 })
336 .await
337 .unwrap();
338 cx_a.executor().run_until_parked();
339 client_b
340 .app_state
341 .user_store
342 .update(*cx_b, |store, cx| {
343 store.respond_to_contact_request(client_a.user_id().unwrap(), true, cx)
344 })
345 .await
346 .unwrap();
347 }
348 }
349 }
350
351 pub async fn make_channel(
352 &self,
353 channel: &str,
354 parent: Option<u64>,
355 admin: (&TestClient, &mut TestAppContext),
356 members: &mut [(&TestClient, &mut TestAppContext)],
357 ) -> u64 {
358 let (_, admin_cx) = admin;
359 let channel_id = admin_cx
360 .read(ChannelStore::global)
361 .update(admin_cx, |channel_store, cx| {
362 channel_store.create_channel(channel, parent, cx)
363 })
364 .await
365 .unwrap();
366
367 for (member_client, member_cx) in members {
368 admin_cx
369 .read(ChannelStore::global)
370 .update(admin_cx, |channel_store, cx| {
371 channel_store.invite_member(
372 channel_id,
373 member_client.user_id().unwrap(),
374 ChannelRole::Member,
375 cx,
376 )
377 })
378 .await
379 .unwrap();
380
381 admin_cx.executor().run_until_parked();
382
383 member_cx
384 .read(ChannelStore::global)
385 .update(*member_cx, |channels, cx| {
386 channels.respond_to_channel_invite(channel_id, true, cx)
387 })
388 .await
389 .unwrap();
390 }
391
392 channel_id
393 }
394
395 pub async fn make_public_channel(
396 &self,
397 channel: &str,
398 client: &TestClient,
399 cx: &mut TestAppContext,
400 ) -> u64 {
401 let channel_id = self
402 .make_channel(channel, None, (client, cx), &mut [])
403 .await;
404
405 client
406 .channel_store()
407 .update(cx, |channel_store, cx| {
408 channel_store.set_channel_visibility(
409 channel_id,
410 proto::ChannelVisibility::Public,
411 cx,
412 )
413 })
414 .await
415 .unwrap();
416
417 channel_id
418 }
419
420 pub async fn make_channel_tree(
421 &self,
422 channels: &[(&str, Option<&str>)],
423 creator: (&TestClient, &mut TestAppContext),
424 ) -> Vec<u64> {
425 let mut observed_channels = HashMap::default();
426 let mut result = Vec::new();
427 for (channel, parent) in channels {
428 let id;
429 if let Some(parent) = parent {
430 if let Some(parent_id) = observed_channels.get(parent) {
431 id = self
432 .make_channel(channel, Some(*parent_id), (creator.0, creator.1), &mut [])
433 .await;
434 } else {
435 panic!(
436 "Edge {}->{} referenced before {} was created",
437 parent, channel, parent
438 )
439 }
440 } else {
441 id = self
442 .make_channel(channel, None, (creator.0, creator.1), &mut [])
443 .await;
444 }
445
446 observed_channels.insert(channel, id);
447 result.push(id);
448 }
449
450 result
451 }
452
453 pub async fn create_room(&self, clients: &mut [(&TestClient, &mut TestAppContext)]) {
454 self.make_contacts(clients).await;
455
456 let (left, right) = clients.split_at_mut(1);
457 let (_client_a, cx_a) = &mut left[0];
458 let active_call_a = cx_a.read(ActiveCall::global);
459
460 for (client_b, cx_b) in right {
461 let user_id_b = client_b.current_user_id(*cx_b).to_proto();
462 active_call_a
463 .update(*cx_a, |call, cx| call.invite(user_id_b, None, cx))
464 .await
465 .unwrap();
466
467 cx_b.executor().run_until_parked();
468 let active_call_b = cx_b.read(ActiveCall::global);
469 active_call_b
470 .update(*cx_b, |call, cx| call.accept_incoming(cx))
471 .await
472 .unwrap();
473 }
474 }
475
476 pub async fn build_app_state(
477 test_db: &TestDb,
478 fake_server: &live_kit_client::TestServer,
479 ) -> Arc<AppState> {
480 Arc::new(AppState {
481 db: test_db.db().clone(),
482 live_kit_client: Some(Arc::new(fake_server.create_api_client())),
483 config: Config {
484 http_port: 0,
485 database_url: "".into(),
486 database_max_connections: 0,
487 api_token: "".into(),
488 invite_link_prefix: "".into(),
489 live_kit_server: None,
490 live_kit_key: None,
491 live_kit_secret: None,
492 rust_log: None,
493 log_json: None,
494 zed_environment: "test".into(),
495 },
496 })
497 }
498}
499
500impl Deref for TestServer {
501 type Target = Server;
502
503 fn deref(&self) -> &Self::Target {
504 &self.server
505 }
506}
507
508impl Drop for TestServer {
509 fn drop(&mut self) {
510 self.server.teardown();
511 self.test_live_kit_server.teardown().unwrap();
512 }
513}
514
515impl Deref for TestClient {
516 type Target = Arc<Client>;
517
518 fn deref(&self) -> &Self::Target {
519 &self.app_state.client
520 }
521}
522
523impl TestClient {
524 pub fn fs(&self) -> &FakeFs {
525 self.app_state.fs.as_fake()
526 }
527
528 pub fn channel_store(&self) -> &Model<ChannelStore> {
529 &self.channel_store
530 }
531
532 pub fn notification_store(&self) -> &Model<NotificationStore> {
533 &self.notification_store
534 }
535
536 pub fn user_store(&self) -> &Model<UserStore> {
537 &self.app_state.user_store
538 }
539
540 pub fn language_registry(&self) -> &Arc<LanguageRegistry> {
541 &self.app_state.languages
542 }
543
544 pub fn client(&self) -> &Arc<Client> {
545 &self.app_state.client
546 }
547
548 pub fn current_user_id(&self, cx: &TestAppContext) -> UserId {
549 UserId::from_proto(
550 self.app_state
551 .user_store
552 .read_with(cx, |user_store, _| user_store.current_user().unwrap().id),
553 )
554 }
555
556 pub async fn wait_for_current_user(&self, cx: &TestAppContext) {
557 let mut authed_user = self
558 .app_state
559 .user_store
560 .read_with(cx, |user_store, _| user_store.watch_current_user());
561 while authed_user.next().await.unwrap().is_none() {}
562 }
563
564 pub async fn clear_contacts(&self, cx: &mut TestAppContext) {
565 self.app_state
566 .user_store
567 .update(cx, |store, _| store.clear_contacts())
568 .await;
569 }
570
571 pub fn local_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
572 Ref::map(self.state.borrow(), |state| &state.local_projects)
573 }
574
575 pub fn remote_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
576 Ref::map(self.state.borrow(), |state| &state.remote_projects)
577 }
578
579 pub fn local_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
580 RefMut::map(self.state.borrow_mut(), |state| &mut state.local_projects)
581 }
582
583 pub fn remote_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
584 RefMut::map(self.state.borrow_mut(), |state| &mut state.remote_projects)
585 }
586
587 pub fn buffers_for_project<'a>(
588 &'a self,
589 project: &Model<Project>,
590 ) -> impl DerefMut<Target = HashSet<Model<language::Buffer>>> + 'a {
591 RefMut::map(self.state.borrow_mut(), |state| {
592 state.buffers.entry(project.clone()).or_default()
593 })
594 }
595
596 pub fn buffers<'a>(
597 &'a self,
598 ) -> impl DerefMut<Target = HashMap<Model<Project>, HashSet<Model<language::Buffer>>>> + 'a
599 {
600 RefMut::map(self.state.borrow_mut(), |state| &mut state.buffers)
601 }
602
603 pub fn channel_buffers<'a>(
604 &'a self,
605 ) -> impl DerefMut<Target = HashSet<Model<ChannelBuffer>>> + 'a {
606 RefMut::map(self.state.borrow_mut(), |state| &mut state.channel_buffers)
607 }
608
609 pub fn summarize_contacts(&self, cx: &TestAppContext) -> ContactsSummary {
610 self.app_state
611 .user_store
612 .read_with(cx, |store, _| ContactsSummary {
613 current: store
614 .contacts()
615 .iter()
616 .map(|contact| contact.user.github_login.clone())
617 .collect(),
618 outgoing_requests: store
619 .outgoing_contact_requests()
620 .iter()
621 .map(|user| user.github_login.clone())
622 .collect(),
623 incoming_requests: store
624 .incoming_contact_requests()
625 .iter()
626 .map(|user| user.github_login.clone())
627 .collect(),
628 })
629 }
630
631 pub async fn build_local_project(
632 &self,
633 root_path: impl AsRef<Path>,
634 cx: &mut TestAppContext,
635 ) -> (Model<Project>, WorktreeId) {
636 let project = self.build_empty_local_project(cx);
637 let (worktree, _) = project
638 .update(cx, |p, cx| {
639 p.find_or_create_local_worktree(root_path, true, cx)
640 })
641 .await
642 .unwrap();
643 worktree
644 .read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete())
645 .await;
646 (project, worktree.read_with(cx, |tree, _| tree.id()))
647 }
648
649 pub async fn build_test_project(&self, cx: &mut TestAppContext) -> Model<Project> {
650 self.fs()
651 .insert_tree(
652 "/a",
653 json!({
654 "1.txt": "one\none\none",
655 "2.js": "function two() { return 2; }",
656 "3.rs": "mod test",
657 }),
658 )
659 .await;
660 self.build_local_project("/a", cx).await.0
661 }
662
663 pub async fn host_workspace(
664 &self,
665 workspace: &View<Workspace>,
666 channel_id: u64,
667 cx: &mut VisualTestContext,
668 ) {
669 cx.update(|cx| {
670 let active_call = ActiveCall::global(cx);
671 active_call.update(cx, |call, cx| call.join_channel(channel_id, cx))
672 })
673 .await
674 .unwrap();
675 cx.update(|cx| {
676 let active_call = ActiveCall::global(cx);
677 let project = workspace.read(cx).project().clone();
678 active_call.update(cx, |call, cx| call.share_project(project, cx))
679 })
680 .await
681 .unwrap();
682 cx.executor().run_until_parked();
683 }
684
685 pub async fn join_workspace<'a>(
686 &'a self,
687 channel_id: u64,
688 cx: &'a mut TestAppContext,
689 ) -> (View<Workspace>, &'a mut VisualTestContext) {
690 cx.update(|cx| workspace::open_channel(channel_id, self.app_state.clone(), None, cx))
691 .await
692 .unwrap();
693 cx.run_until_parked();
694
695 self.active_workspace(cx)
696 }
697
698 pub fn build_empty_local_project(&self, cx: &mut TestAppContext) -> Model<Project> {
699 cx.update(|cx| {
700 Project::local(
701 self.client().clone(),
702 self.app_state.node_runtime.clone(),
703 self.app_state.user_store.clone(),
704 self.app_state.languages.clone(),
705 self.app_state.fs.clone(),
706 cx,
707 )
708 })
709 }
710
711 pub async fn build_remote_project(
712 &self,
713 host_project_id: u64,
714 guest_cx: &mut TestAppContext,
715 ) -> Model<Project> {
716 let active_call = guest_cx.read(ActiveCall::global);
717 let room = active_call.read_with(guest_cx, |call, _| call.room().unwrap().clone());
718 room.update(guest_cx, |room, cx| {
719 room.join_project(
720 host_project_id,
721 self.app_state.languages.clone(),
722 self.app_state.fs.clone(),
723 cx,
724 )
725 })
726 .await
727 .unwrap()
728 }
729
730 pub fn build_workspace<'a>(
731 &'a self,
732 project: &Model<Project>,
733 cx: &'a mut TestAppContext,
734 ) -> (View<Workspace>, &'a mut VisualTestContext) {
735 cx.add_window_view(|cx| {
736 cx.activate_window();
737 Workspace::new(0, project.clone(), self.app_state.clone(), cx)
738 })
739 }
740
741 pub async fn build_test_workspace<'a>(
742 &'a self,
743 cx: &'a mut TestAppContext,
744 ) -> (View<Workspace>, &'a mut VisualTestContext) {
745 let project = self.build_test_project(cx).await;
746 cx.add_window_view(|cx| {
747 cx.activate_window();
748 Workspace::new(0, project.clone(), self.app_state.clone(), cx)
749 })
750 }
751
752 pub fn active_workspace<'a>(
753 &'a self,
754 cx: &'a mut TestAppContext,
755 ) -> (View<Workspace>, &'a mut VisualTestContext) {
756 let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
757
758 let view = window.root_view(cx).unwrap();
759 let cx = VisualTestContext::from_window(*window.deref(), cx).as_mut();
760 // it might be nice to try and cleanup these at the end of each test.
761 (view, cx)
762 }
763}
764
765pub fn join_channel_call(cx: &mut TestAppContext) -> Task<anyhow::Result<()>> {
766 let room = cx.read(|cx| ActiveCall::global(cx).read(cx).room().cloned());
767 room.unwrap().update(cx, |room, cx| room.join_call(cx))
768}
769
770pub fn open_channel_notes(
771 channel_id: u64,
772 cx: &mut VisualTestContext,
773) -> Task<anyhow::Result<View<ChannelView>>> {
774 let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
775 let view = window.root_view(cx).unwrap();
776
777 cx.update(|cx| ChannelView::open(channel_id, None, view.clone(), cx))
778}
779
780impl Drop for TestClient {
781 fn drop(&mut self) {
782 self.app_state.client.teardown();
783 }
784}