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;
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 None,
235 Some(connection_id_tx),
236 Executor::Deterministic(cx.background_executor().clone()),
237 ))
238 .detach();
239 let connection_id = connection_id_rx.await.unwrap();
240 connection_killers
241 .lock()
242 .insert(connection_id.into(), killed);
243 Ok(client_conn)
244 }
245 })
246 });
247
248 let fs = FakeFs::new(cx.executor());
249 let user_store = cx.new_model(|cx| UserStore::new(client.clone(), cx));
250 let workspace_store = cx.new_model(|cx| WorkspaceStore::new(client.clone(), cx));
251 let mut language_registry = LanguageRegistry::test();
252 language_registry.set_executor(cx.executor());
253 let app_state = Arc::new(workspace::AppState {
254 client: client.clone(),
255 user_store: user_store.clone(),
256 workspace_store,
257 languages: Arc::new(language_registry),
258 fs: fs.clone(),
259 build_window_options: |_, _, _| Default::default(),
260 node_runtime: FakeNodeRuntime::new(),
261 });
262
263 cx.update(|cx| {
264 theme::init(theme::LoadThemes::JustBase, cx);
265 Project::init(&client, cx);
266 client::init(&client, cx);
267 language::init(cx);
268 editor::init(cx);
269 workspace::init(app_state.clone(), cx);
270 call::init(client.clone(), user_store.clone(), cx);
271 channel::init(&client, user_store.clone(), cx);
272 notifications::init(client.clone(), user_store, cx);
273 collab_ui::init(&app_state, cx);
274 file_finder::init(cx);
275 menu::init();
276 settings::KeymapFile::load_asset("keymaps/default.json", cx).unwrap();
277 });
278
279 client
280 .authenticate_and_connect(false, &cx.to_async())
281 .await
282 .unwrap();
283
284 let client = TestClient {
285 app_state,
286 username: name.to_string(),
287 channel_store: cx.read(ChannelStore::global).clone(),
288 notification_store: cx.read(NotificationStore::global).clone(),
289 state: Default::default(),
290 };
291 client.wait_for_current_user(cx).await;
292 client
293 }
294
295 pub fn disconnect_client(&self, peer_id: PeerId) {
296 self.connection_killers
297 .lock()
298 .remove(&peer_id)
299 .unwrap()
300 .store(true, SeqCst);
301 }
302
303 pub fn simulate_long_connection_interruption(
304 &self,
305 peer_id: PeerId,
306 deterministic: BackgroundExecutor,
307 ) {
308 self.forbid_connections();
309 self.disconnect_client(peer_id);
310 deterministic.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
311 self.allow_connections();
312 deterministic.advance_clock(RECEIVE_TIMEOUT + RECONNECT_TIMEOUT);
313 deterministic.run_until_parked();
314 }
315
316 pub fn forbid_connections(&self) {
317 self.forbid_connections.store(true, SeqCst);
318 }
319
320 pub fn allow_connections(&self) {
321 self.forbid_connections.store(false, SeqCst);
322 }
323
324 pub async fn make_contacts(&self, clients: &mut [(&TestClient, &mut TestAppContext)]) {
325 for ix in 1..clients.len() {
326 let (left, right) = clients.split_at_mut(ix);
327 let (client_a, cx_a) = left.last_mut().unwrap();
328 for (client_b, cx_b) in right {
329 client_a
330 .app_state
331 .user_store
332 .update(*cx_a, |store, cx| {
333 store.request_contact(client_b.user_id().unwrap(), cx)
334 })
335 .await
336 .unwrap();
337 cx_a.executor().run_until_parked();
338 client_b
339 .app_state
340 .user_store
341 .update(*cx_b, |store, cx| {
342 store.respond_to_contact_request(client_a.user_id().unwrap(), true, cx)
343 })
344 .await
345 .unwrap();
346 }
347 }
348 }
349
350 pub async fn make_channel(
351 &self,
352 channel: &str,
353 parent: Option<u64>,
354 admin: (&TestClient, &mut TestAppContext),
355 members: &mut [(&TestClient, &mut TestAppContext)],
356 ) -> u64 {
357 let (_, admin_cx) = admin;
358 let channel_id = admin_cx
359 .read(ChannelStore::global)
360 .update(admin_cx, |channel_store, cx| {
361 channel_store.create_channel(channel, parent, cx)
362 })
363 .await
364 .unwrap();
365
366 for (member_client, member_cx) in members {
367 admin_cx
368 .read(ChannelStore::global)
369 .update(admin_cx, |channel_store, cx| {
370 channel_store.invite_member(
371 channel_id,
372 member_client.user_id().unwrap(),
373 ChannelRole::Member,
374 cx,
375 )
376 })
377 .await
378 .unwrap();
379
380 admin_cx.executor().run_until_parked();
381
382 member_cx
383 .read(ChannelStore::global)
384 .update(*member_cx, |channels, cx| {
385 channels.respond_to_channel_invite(channel_id, true, cx)
386 })
387 .await
388 .unwrap();
389 }
390
391 channel_id
392 }
393
394 pub async fn make_public_channel(
395 &self,
396 channel: &str,
397 client: &TestClient,
398 cx: &mut TestAppContext,
399 ) -> u64 {
400 let channel_id = self
401 .make_channel(channel, None, (client, cx), &mut [])
402 .await;
403
404 client
405 .channel_store()
406 .update(cx, |channel_store, cx| {
407 channel_store.set_channel_visibility(
408 channel_id,
409 proto::ChannelVisibility::Public,
410 cx,
411 )
412 })
413 .await
414 .unwrap();
415
416 channel_id
417 }
418
419 pub async fn make_channel_tree(
420 &self,
421 channels: &[(&str, Option<&str>)],
422 creator: (&TestClient, &mut TestAppContext),
423 ) -> Vec<u64> {
424 let mut observed_channels = HashMap::default();
425 let mut result = Vec::new();
426 for (channel, parent) in channels {
427 let id;
428 if let Some(parent) = parent {
429 if let Some(parent_id) = observed_channels.get(parent) {
430 id = self
431 .make_channel(channel, Some(*parent_id), (creator.0, creator.1), &mut [])
432 .await;
433 } else {
434 panic!(
435 "Edge {}->{} referenced before {} was created",
436 parent, channel, parent
437 )
438 }
439 } else {
440 id = self
441 .make_channel(channel, None, (creator.0, creator.1), &mut [])
442 .await;
443 }
444
445 observed_channels.insert(channel, id);
446 result.push(id);
447 }
448
449 result
450 }
451
452 pub async fn create_room(&self, clients: &mut [(&TestClient, &mut TestAppContext)]) {
453 self.make_contacts(clients).await;
454
455 let (left, right) = clients.split_at_mut(1);
456 let (_client_a, cx_a) = &mut left[0];
457 let active_call_a = cx_a.read(ActiveCall::global);
458
459 for (client_b, cx_b) in right {
460 let user_id_b = client_b.current_user_id(*cx_b).to_proto();
461 active_call_a
462 .update(*cx_a, |call, cx| call.invite(user_id_b, None, cx))
463 .await
464 .unwrap();
465
466 cx_b.executor().run_until_parked();
467 let active_call_b = cx_b.read(ActiveCall::global);
468 active_call_b
469 .update(*cx_b, |call, cx| call.accept_incoming(cx))
470 .await
471 .unwrap();
472 }
473 }
474
475 pub async fn build_app_state(
476 test_db: &TestDb,
477 fake_server: &live_kit_client::TestServer,
478 ) -> Arc<AppState> {
479 Arc::new(AppState {
480 db: test_db.db().clone(),
481 live_kit_client: Some(Arc::new(fake_server.create_api_client())),
482 blob_store_client: None,
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 blob_store_url: None,
496 blob_store_region: None,
497 blob_store_access_key: None,
498 blob_store_secret_key: None,
499 blob_store_bucket: None,
500 },
501 })
502 }
503}
504
505impl Deref for TestServer {
506 type Target = Server;
507
508 fn deref(&self) -> &Self::Target {
509 &self.server
510 }
511}
512
513impl Drop for TestServer {
514 fn drop(&mut self) {
515 self.server.teardown();
516 self.test_live_kit_server.teardown().unwrap();
517 }
518}
519
520impl Deref for TestClient {
521 type Target = Arc<Client>;
522
523 fn deref(&self) -> &Self::Target {
524 &self.app_state.client
525 }
526}
527
528impl TestClient {
529 pub fn fs(&self) -> &FakeFs {
530 self.app_state.fs.as_fake()
531 }
532
533 pub fn channel_store(&self) -> &Model<ChannelStore> {
534 &self.channel_store
535 }
536
537 pub fn notification_store(&self) -> &Model<NotificationStore> {
538 &self.notification_store
539 }
540
541 pub fn user_store(&self) -> &Model<UserStore> {
542 &self.app_state.user_store
543 }
544
545 pub fn language_registry(&self) -> &Arc<LanguageRegistry> {
546 &self.app_state.languages
547 }
548
549 pub fn client(&self) -> &Arc<Client> {
550 &self.app_state.client
551 }
552
553 pub fn current_user_id(&self, cx: &TestAppContext) -> UserId {
554 UserId::from_proto(
555 self.app_state
556 .user_store
557 .read_with(cx, |user_store, _| user_store.current_user().unwrap().id),
558 )
559 }
560
561 pub async fn wait_for_current_user(&self, cx: &TestAppContext) {
562 let mut authed_user = self
563 .app_state
564 .user_store
565 .read_with(cx, |user_store, _| user_store.watch_current_user());
566 while authed_user.next().await.unwrap().is_none() {}
567 }
568
569 pub async fn clear_contacts(&self, cx: &mut TestAppContext) {
570 self.app_state
571 .user_store
572 .update(cx, |store, _| store.clear_contacts())
573 .await;
574 }
575
576 pub fn local_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
577 Ref::map(self.state.borrow(), |state| &state.local_projects)
578 }
579
580 pub fn remote_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
581 Ref::map(self.state.borrow(), |state| &state.remote_projects)
582 }
583
584 pub fn local_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
585 RefMut::map(self.state.borrow_mut(), |state| &mut state.local_projects)
586 }
587
588 pub fn remote_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
589 RefMut::map(self.state.borrow_mut(), |state| &mut state.remote_projects)
590 }
591
592 pub fn buffers_for_project<'a>(
593 &'a self,
594 project: &Model<Project>,
595 ) -> impl DerefMut<Target = HashSet<Model<language::Buffer>>> + 'a {
596 RefMut::map(self.state.borrow_mut(), |state| {
597 state.buffers.entry(project.clone()).or_default()
598 })
599 }
600
601 pub fn buffers<'a>(
602 &'a self,
603 ) -> impl DerefMut<Target = HashMap<Model<Project>, HashSet<Model<language::Buffer>>>> + 'a
604 {
605 RefMut::map(self.state.borrow_mut(), |state| &mut state.buffers)
606 }
607
608 pub fn channel_buffers<'a>(
609 &'a self,
610 ) -> impl DerefMut<Target = HashSet<Model<ChannelBuffer>>> + 'a {
611 RefMut::map(self.state.borrow_mut(), |state| &mut state.channel_buffers)
612 }
613
614 pub fn summarize_contacts(&self, cx: &TestAppContext) -> ContactsSummary {
615 self.app_state
616 .user_store
617 .read_with(cx, |store, _| ContactsSummary {
618 current: store
619 .contacts()
620 .iter()
621 .map(|contact| contact.user.github_login.clone())
622 .collect(),
623 outgoing_requests: store
624 .outgoing_contact_requests()
625 .iter()
626 .map(|user| user.github_login.clone())
627 .collect(),
628 incoming_requests: store
629 .incoming_contact_requests()
630 .iter()
631 .map(|user| user.github_login.clone())
632 .collect(),
633 })
634 }
635
636 pub async fn build_local_project(
637 &self,
638 root_path: impl AsRef<Path>,
639 cx: &mut TestAppContext,
640 ) -> (Model<Project>, WorktreeId) {
641 let project = self.build_empty_local_project(cx);
642 let (worktree, _) = project
643 .update(cx, |p, cx| {
644 p.find_or_create_local_worktree(root_path, true, cx)
645 })
646 .await
647 .unwrap();
648 worktree
649 .read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete())
650 .await;
651 (project, worktree.read_with(cx, |tree, _| tree.id()))
652 }
653
654 pub async fn build_test_project(&self, cx: &mut TestAppContext) -> Model<Project> {
655 self.fs()
656 .insert_tree(
657 "/a",
658 json!({
659 "1.txt": "one\none\none",
660 "2.js": "function two() { return 2; }",
661 "3.rs": "mod test",
662 }),
663 )
664 .await;
665 self.build_local_project("/a", cx).await.0
666 }
667
668 pub async fn host_workspace(
669 &self,
670 workspace: &View<Workspace>,
671 channel_id: u64,
672 cx: &mut VisualTestContext,
673 ) {
674 cx.update(|cx| {
675 let active_call = ActiveCall::global(cx);
676 active_call.update(cx, |call, cx| call.join_channel(channel_id, cx))
677 })
678 .await
679 .unwrap();
680 cx.update(|cx| {
681 let active_call = ActiveCall::global(cx);
682 let project = workspace.read(cx).project().clone();
683 active_call.update(cx, |call, cx| call.share_project(project, cx))
684 })
685 .await
686 .unwrap();
687 cx.executor().run_until_parked();
688 }
689
690 pub async fn join_workspace<'a>(
691 &'a self,
692 channel_id: u64,
693 cx: &'a mut TestAppContext,
694 ) -> (View<Workspace>, &'a mut VisualTestContext) {
695 cx.update(|cx| workspace::join_channel(channel_id, self.app_state.clone(), None, cx))
696 .await
697 .unwrap();
698 cx.run_until_parked();
699
700 self.active_workspace(cx)
701 }
702
703 pub fn build_empty_local_project(&self, cx: &mut TestAppContext) -> Model<Project> {
704 cx.update(|cx| {
705 Project::local(
706 self.client().clone(),
707 self.app_state.node_runtime.clone(),
708 self.app_state.user_store.clone(),
709 self.app_state.languages.clone(),
710 self.app_state.fs.clone(),
711 cx,
712 )
713 })
714 }
715
716 pub async fn build_remote_project(
717 &self,
718 host_project_id: u64,
719 guest_cx: &mut TestAppContext,
720 ) -> Model<Project> {
721 let active_call = guest_cx.read(ActiveCall::global);
722 let room = active_call.read_with(guest_cx, |call, _| call.room().unwrap().clone());
723 room.update(guest_cx, |room, cx| {
724 room.join_project(
725 host_project_id,
726 self.app_state.languages.clone(),
727 self.app_state.fs.clone(),
728 cx,
729 )
730 })
731 .await
732 .unwrap()
733 }
734
735 pub fn build_workspace<'a>(
736 &'a self,
737 project: &Model<Project>,
738 cx: &'a mut TestAppContext,
739 ) -> (View<Workspace>, &'a mut VisualTestContext) {
740 cx.add_window_view(|cx| {
741 cx.activate_window();
742 Workspace::new(0, project.clone(), self.app_state.clone(), cx)
743 })
744 }
745
746 pub async fn build_test_workspace<'a>(
747 &'a self,
748 cx: &'a mut TestAppContext,
749 ) -> (View<Workspace>, &'a mut VisualTestContext) {
750 let project = self.build_test_project(cx).await;
751 cx.add_window_view(|cx| {
752 cx.activate_window();
753 Workspace::new(0, project.clone(), self.app_state.clone(), cx)
754 })
755 }
756
757 pub fn active_workspace<'a>(
758 &'a self,
759 cx: &'a mut TestAppContext,
760 ) -> (View<Workspace>, &'a mut VisualTestContext) {
761 let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
762
763 let view = window.root_view(cx).unwrap();
764 let cx = VisualTestContext::from_window(*window.deref(), cx).as_mut();
765 // it might be nice to try and cleanup these at the end of each test.
766 (view, cx)
767 }
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}