1use crate::{
2 db::{tests::TestDb, NewUserParams, UserId},
3 executor::Executor,
4 rpc::{Server, ZedVersion, 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 ZedVersion(SemanticVersion::new(1, 0, 0)),
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-macos.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 blob_store_client: None,
484 config: Config {
485 http_port: 0,
486 database_url: "".into(),
487 database_max_connections: 0,
488 api_token: "".into(),
489 invite_link_prefix: "".into(),
490 live_kit_server: None,
491 live_kit_key: None,
492 live_kit_secret: None,
493 rust_log: None,
494 log_json: None,
495 zed_environment: "test".into(),
496 blob_store_url: None,
497 blob_store_region: None,
498 blob_store_access_key: None,
499 blob_store_secret_key: None,
500 blob_store_bucket: None,
501 },
502 })
503 }
504}
505
506impl Deref for TestServer {
507 type Target = Server;
508
509 fn deref(&self) -> &Self::Target {
510 &self.server
511 }
512}
513
514impl Drop for TestServer {
515 fn drop(&mut self) {
516 self.server.teardown();
517 self.test_live_kit_server.teardown().unwrap();
518 }
519}
520
521impl Deref for TestClient {
522 type Target = Arc<Client>;
523
524 fn deref(&self) -> &Self::Target {
525 &self.app_state.client
526 }
527}
528
529impl TestClient {
530 pub fn fs(&self) -> &FakeFs {
531 self.app_state.fs.as_fake()
532 }
533
534 pub fn channel_store(&self) -> &Model<ChannelStore> {
535 &self.channel_store
536 }
537
538 pub fn notification_store(&self) -> &Model<NotificationStore> {
539 &self.notification_store
540 }
541
542 pub fn user_store(&self) -> &Model<UserStore> {
543 &self.app_state.user_store
544 }
545
546 pub fn language_registry(&self) -> &Arc<LanguageRegistry> {
547 &self.app_state.languages
548 }
549
550 pub fn client(&self) -> &Arc<Client> {
551 &self.app_state.client
552 }
553
554 pub fn current_user_id(&self, cx: &TestAppContext) -> UserId {
555 UserId::from_proto(
556 self.app_state
557 .user_store
558 .read_with(cx, |user_store, _| user_store.current_user().unwrap().id),
559 )
560 }
561
562 pub async fn wait_for_current_user(&self, cx: &TestAppContext) {
563 let mut authed_user = self
564 .app_state
565 .user_store
566 .read_with(cx, |user_store, _| user_store.watch_current_user());
567 while authed_user.next().await.unwrap().is_none() {}
568 }
569
570 pub async fn clear_contacts(&self, cx: &mut TestAppContext) {
571 self.app_state
572 .user_store
573 .update(cx, |store, _| store.clear_contacts())
574 .await;
575 }
576
577 pub fn local_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
578 Ref::map(self.state.borrow(), |state| &state.local_projects)
579 }
580
581 pub fn remote_projects<'a>(&'a self) -> impl Deref<Target = Vec<Model<Project>>> + 'a {
582 Ref::map(self.state.borrow(), |state| &state.remote_projects)
583 }
584
585 pub fn local_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
586 RefMut::map(self.state.borrow_mut(), |state| &mut state.local_projects)
587 }
588
589 pub fn remote_projects_mut<'a>(&'a self) -> impl DerefMut<Target = Vec<Model<Project>>> + 'a {
590 RefMut::map(self.state.borrow_mut(), |state| &mut state.remote_projects)
591 }
592
593 pub fn buffers_for_project<'a>(
594 &'a self,
595 project: &Model<Project>,
596 ) -> impl DerefMut<Target = HashSet<Model<language::Buffer>>> + 'a {
597 RefMut::map(self.state.borrow_mut(), |state| {
598 state.buffers.entry(project.clone()).or_default()
599 })
600 }
601
602 pub fn buffers<'a>(
603 &'a self,
604 ) -> impl DerefMut<Target = HashMap<Model<Project>, HashSet<Model<language::Buffer>>>> + 'a
605 {
606 RefMut::map(self.state.borrow_mut(), |state| &mut state.buffers)
607 }
608
609 pub fn channel_buffers<'a>(
610 &'a self,
611 ) -> impl DerefMut<Target = HashSet<Model<ChannelBuffer>>> + 'a {
612 RefMut::map(self.state.borrow_mut(), |state| &mut state.channel_buffers)
613 }
614
615 pub fn summarize_contacts(&self, cx: &TestAppContext) -> ContactsSummary {
616 self.app_state
617 .user_store
618 .read_with(cx, |store, _| ContactsSummary {
619 current: store
620 .contacts()
621 .iter()
622 .map(|contact| contact.user.github_login.clone())
623 .collect(),
624 outgoing_requests: store
625 .outgoing_contact_requests()
626 .iter()
627 .map(|user| user.github_login.clone())
628 .collect(),
629 incoming_requests: store
630 .incoming_contact_requests()
631 .iter()
632 .map(|user| user.github_login.clone())
633 .collect(),
634 })
635 }
636
637 pub async fn build_local_project(
638 &self,
639 root_path: impl AsRef<Path>,
640 cx: &mut TestAppContext,
641 ) -> (Model<Project>, WorktreeId) {
642 let project = self.build_empty_local_project(cx);
643 let (worktree, _) = project
644 .update(cx, |p, cx| {
645 p.find_or_create_local_worktree(root_path, true, cx)
646 })
647 .await
648 .unwrap();
649 worktree
650 .read_with(cx, |tree, _| tree.as_local().unwrap().scan_complete())
651 .await;
652 (project, worktree.read_with(cx, |tree, _| tree.id()))
653 }
654
655 pub async fn build_test_project(&self, cx: &mut TestAppContext) -> Model<Project> {
656 self.fs()
657 .insert_tree(
658 "/a",
659 json!({
660 "1.txt": "one\none\none",
661 "2.js": "function two() { return 2; }",
662 "3.rs": "mod test",
663 }),
664 )
665 .await;
666 self.build_local_project("/a", cx).await.0
667 }
668
669 pub async fn host_workspace(
670 &self,
671 workspace: &View<Workspace>,
672 channel_id: u64,
673 cx: &mut VisualTestContext,
674 ) {
675 cx.update(|cx| {
676 let active_call = ActiveCall::global(cx);
677 active_call.update(cx, |call, cx| call.join_channel(channel_id, cx))
678 })
679 .await
680 .unwrap();
681 cx.update(|cx| {
682 let active_call = ActiveCall::global(cx);
683 let project = workspace.read(cx).project().clone();
684 active_call.update(cx, |call, cx| call.share_project(project, cx))
685 })
686 .await
687 .unwrap();
688 cx.executor().run_until_parked();
689 }
690
691 pub async fn join_workspace<'a>(
692 &'a self,
693 channel_id: u64,
694 cx: &'a mut TestAppContext,
695 ) -> (View<Workspace>, &'a mut VisualTestContext) {
696 cx.update(|cx| workspace::join_channel(channel_id, self.app_state.clone(), None, cx))
697 .await
698 .unwrap();
699 cx.run_until_parked();
700
701 self.active_workspace(cx)
702 }
703
704 pub fn build_empty_local_project(&self, cx: &mut TestAppContext) -> Model<Project> {
705 cx.update(|cx| {
706 Project::local(
707 self.client().clone(),
708 self.app_state.node_runtime.clone(),
709 self.app_state.user_store.clone(),
710 self.app_state.languages.clone(),
711 self.app_state.fs.clone(),
712 cx,
713 )
714 })
715 }
716
717 pub async fn build_remote_project(
718 &self,
719 host_project_id: u64,
720 guest_cx: &mut TestAppContext,
721 ) -> Model<Project> {
722 let active_call = guest_cx.read(ActiveCall::global);
723 let room = active_call.read_with(guest_cx, |call, _| call.room().unwrap().clone());
724 room.update(guest_cx, |room, cx| {
725 room.join_project(
726 host_project_id,
727 self.app_state.languages.clone(),
728 self.app_state.fs.clone(),
729 cx,
730 )
731 })
732 .await
733 .unwrap()
734 }
735
736 pub fn build_workspace<'a>(
737 &'a self,
738 project: &Model<Project>,
739 cx: &'a mut TestAppContext,
740 ) -> (View<Workspace>, &'a mut VisualTestContext) {
741 cx.add_window_view(|cx| {
742 cx.activate_window();
743 Workspace::new(0, project.clone(), self.app_state.clone(), cx)
744 })
745 }
746
747 pub async fn build_test_workspace<'a>(
748 &'a self,
749 cx: &'a mut TestAppContext,
750 ) -> (View<Workspace>, &'a mut VisualTestContext) {
751 let project = self.build_test_project(cx).await;
752 cx.add_window_view(|cx| {
753 cx.activate_window();
754 Workspace::new(0, project.clone(), self.app_state.clone(), cx)
755 })
756 }
757
758 pub fn active_workspace<'a>(
759 &'a self,
760 cx: &'a mut TestAppContext,
761 ) -> (View<Workspace>, &'a mut VisualTestContext) {
762 let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
763
764 let view = window.root_view(cx).unwrap();
765 let cx = VisualTestContext::from_window(*window.deref(), cx).as_mut();
766 // it might be nice to try and cleanup these at the end of each test.
767 (view, cx)
768 }
769}
770
771pub fn open_channel_notes(
772 channel_id: u64,
773 cx: &mut VisualTestContext,
774) -> Task<anyhow::Result<View<ChannelView>>> {
775 let window = cx.update(|cx| cx.active_window().unwrap().downcast::<Workspace>().unwrap());
776 let view = window.root_view(cx).unwrap();
777
778 cx.update(|cx| ChannelView::open(channel_id, None, view.clone(), cx))
779}
780
781impl Drop for TestClient {
782 fn drop(&mut self) {
783 self.app_state.client.teardown();
784 }
785}