1use std::iter::zip;
2
3use crate::{
4 debugger_panel::DebugPanel,
5 persistence::SerializedPaneLayout,
6 tests::{init_test, init_test_workspace, start_debug_session},
7};
8use dap::{StoppedEvent, StoppedEventReason, messages::Events};
9use gpui::{BackgroundExecutor, TestAppContext, VisualTestContext};
10use project::{FakeFs, Project};
11use serde_json::json;
12use util::path;
13use workspace::{Panel, dock::DockPosition};
14
15#[gpui::test]
16async fn test_invert_axis_on_panel_position_change(
17 executor: BackgroundExecutor,
18 cx: &mut TestAppContext,
19) {
20 init_test(cx);
21
22 let fs = FakeFs::new(executor.clone());
23 fs.insert_tree(
24 path!("/project"),
25 json!({
26 "main.rs": "fn main() {\n println!(\"Hello, world!\");\n}",
27 }),
28 )
29 .await;
30
31 let project = Project::test(fs, [path!("/project").as_ref()], cx).await;
32 let workspace = init_test_workspace(&project, cx).await;
33 let cx = &mut VisualTestContext::from_window(*workspace, cx);
34
35 // Start a debug session
36 let session = start_debug_session(&workspace, cx, |_| {}).unwrap();
37 let client = session.update(cx, |session, _| session.adapter_client().unwrap());
38
39 // Setup thread response
40 client.on_request::<dap::requests::Threads, _>(move |_, _| {
41 Ok(dap::ThreadsResponse { threads: vec![] })
42 });
43
44 cx.run_until_parked();
45
46 client
47 .fake_event(Events::Stopped(StoppedEvent {
48 reason: StoppedEventReason::Pause,
49 description: None,
50 thread_id: Some(1),
51 preserve_focus_hint: None,
52 text: None,
53 all_threads_stopped: None,
54 hit_breakpoint_ids: None,
55 }))
56 .await;
57
58 cx.run_until_parked();
59
60 let (debug_panel, dock_position) = workspace
61 .update(cx, |workspace, window, cx| {
62 let debug_panel = workspace.panel::<DebugPanel>(cx).unwrap();
63 let dock_position = debug_panel.read(cx).position(window, cx);
64 (debug_panel, dock_position)
65 })
66 .unwrap();
67
68 assert_eq!(
69 dock_position,
70 DockPosition::Bottom,
71 "Default dock position should be bottom for debug panel"
72 );
73
74 let pre_serialized_layout = debug_panel
75 .read_with(cx, |panel, cx| {
76 panel
77 .active_session()
78 .unwrap()
79 .read(cx)
80 .running_state()
81 .read(cx)
82 .serialized_layout(cx)
83 })
84 .panes;
85
86 let post_serialized_layout = debug_panel
87 .update_in(cx, |panel, window, cx| {
88 panel.set_position(DockPosition::Right, window, cx);
89
90 panel
91 .active_session()
92 .unwrap()
93 .read(cx)
94 .running_state()
95 .read(cx)
96 .serialized_layout(cx)
97 })
98 .panes;
99
100 let pre_panes = pre_serialized_layout.in_order();
101 let post_panes = post_serialized_layout.in_order();
102
103 assert_eq!(pre_panes.len(), post_panes.len());
104
105 for (pre, post) in zip(pre_panes, post_panes) {
106 match (pre, post) {
107 (
108 SerializedPaneLayout::Group {
109 axis: pre_axis,
110 flexes: pre_flexes,
111 children: _,
112 },
113 SerializedPaneLayout::Group {
114 axis: post_axis,
115 flexes: post_flexes,
116 children: _,
117 },
118 ) => {
119 assert_ne!(pre_axis, post_axis);
120 assert_eq!(pre_flexes, post_flexes);
121 }
122 (SerializedPaneLayout::Pane(pre_pane), SerializedPaneLayout::Pane(post_pane)) => {
123 assert_eq!(pre_pane.children, post_pane.children);
124 assert_eq!(pre_pane.active_item, post_pane.active_item);
125 }
126 _ => {
127 panic!("Variants don't match")
128 }
129 }
130 }
131}