Visual Studio Code, rebuilt in Rust
Rust
use std::sync::{Arc, Mutex};
use gpui::{TestAppContext, VisualTestContext};
use serde_json::{Value, json};
use super::*;
use crate::menus::{Entry, MenuItem};
use crate::workbench::goto_symbol::tests::open;
/// An expanded thread gets a zone below its range, the glyph toggle removes it, and the reply form grows it; a
/// reply button runs its command with the `CommentReply` and hides the form. The reply is a code editor with the
/// focus: typed text reaches its model and Cmd+Enter submits it (simpleCommentEditor.ts, `editor.action.submitComment`).
#[gpui::test]
fn an_expanded_thread_shows_a_zone_and_replies_run_the_form_actions(cx: &mut TestAppContext) {
let (workbench, cx, host, dir) = open(cx, "comment-thread-widget", "one\ntwo\nthree\n");
workbench.update_in(cx, |workbench, _, _| workbench.load_keybindings(crate::keybindings::default_keybindings(&[]), dir.join("keybindings.json")));
let resource = json!({ "scheme": "file", "path": dir.join("a.txt").to_string_lossy() });
let request = |method: &str, args: Vec<Value>, cx: &mut VisualTestContext| {
workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_comments_request(method, &args, window, cx)));
};
request("$registerCommentController", vec![json!(1), json!("review"), json!("Review"), json!("test.ext")], cx);
request("$updateCommentingRanges", vec![json!(1)], cx);
let range = json!({ "startLineNumber": 2, "startColumn": 1, "endLineNumber": 2, "endColumn": 4 });
request("$createCommentThread", vec![json!(1), json!(7), json!("t"), resource.clone(), range, json!([]), json!({ "value": "test.ext" }), json!(false)], cx);
let zones = |workbench: &gpui::Entity<Workbench>, cx: &mut VisualTestContext| {
workbench.read_with(cx, |workbench, _| workbench.editors.pane_editor().unwrap().view_zones.iter().map(|zone| (zone.anchor, zone.height)).collect::<Vec<_>>())
};
assert!(zones(&workbench, cx).is_empty());
let comment = json!({ "uniqueIdInThread": 1, "body": "Looks good", "userName": "Ann" });
request("$updateCommentThread", vec![json!(1), json!(7), json!("t"), resource.clone(), json!({ "comments": [comment], "collapseState": 1 })], cx);
let shown = zones(&workbench, cx);
assert_eq!(shown.len(), 1);
assert_eq!(shown[0].0, Some(Position::new(1, 2)));
let ran = Arc::new(Mutex::new(Vec::new()));
workbench.update_in(cx, |workbench, window, cx| {
let record = ran.clone();
workbench.commands.register("test.reply", move |_, args, _, _| {
record.lock().unwrap().extend(args);
crate::commands::Outcome::done()
});
let entry = Entry::Command { id: "test.reply".into(), precondition: None, toggled: None, alt: None };
workbench.menus.push(MenuItem { menu: MenuId::CommentThreadActions, entry, title: "Reply".into(), group: "inline".into(), order: 0., when: None });
workbench.expand_comment_reply(1, 7, window, cx);
});
cx.run_until_parked();
cx.simulate_input("Agreed");
cx.simulate_keystrokes("enter");
cx.simulate_input("!");
let comment_editor = workbench.update_in(cx, |workbench, window, _| {
assert_eq!(workbench.comment_editor_text(), "Agreed\n!");
assert_eq!(workbench.key_context(window)["commentEditorFocused"], json!(true));
assert_eq!(workbench.editors.pane_editor().unwrap().document().scheme, "file");
// The editor pane's resource and editor type stay the file's.
assert_eq!(workbench.key_context(window)["resourceScheme"], json!("file"));
assert_eq!(workbench.active_editor_type().unwrap().0["scheme"], json!("file"));
// simpleCommentEditor.ts: no line numbers, glyph margin, decorations or folding before the text.
assert_eq!(workbench.editor_metrics(workbench.comment_editor().unwrap(), window).content_left(), 0.);
crate::host_sync::snapshot_id(workbench.comment_editor().unwrap())
});
// mainThreadDocumentsAndEditors.ts: the input's model is a document, its simple widget editor no text editor; it
// has no comments contribution asking for commenting ranges.
cx.executor().advance_clock(std::time::Duration::from_secs(1));
cx.run_until_parked();
let sent: Vec<String> = host.try_iter().map(|message| format!("{} {}", message.method, json!(message.args))).collect();
assert!(sent.iter().any(|message| message.contains("addedDocuments") && message.contains("commentinput-")));
// mainThreadDocuments.ts asks the text file service, which has no `comment` model: never dirty.
assert!(!sent.iter().any(|message| message.contains("$acceptDirtyStateChanged") && message.contains("commentinput-")), "{sent:#?}");
assert!(sent.iter().any(|message| message.contains("$provideCommentingRanges")));
assert!(!sent.iter().any(|message| message.contains("$provideCommentingRanges") && message.contains("commentinput-")), "{sent:#?}");
assert!(!sent.iter().any(|message| message.contains(&format!("\"{comment_editor}\""))), "{sent:#?}");
assert!(zones(&workbench, cx)[0].1 > shown[0].1);
// calculateEditorHeight: 5 lines fit the 90px editor, each line past them adds 18px.
let replying = zones(&workbench, cx)[0].1;
cx.simulate_keystrokes("enter enter enter enter enter");
assert_eq!(zones(&workbench, cx)[0].1, replying + 36.);
// scrollBeyondLastLine false: grown to its 7 lines, the editor has nothing left to scroll.
cx.run_until_parked();
workbench.read_with(cx, |workbench, _| {
let viewport = workbench.editors.viewport;
assert_eq!(viewport.height, 126.);
assert_eq!(workbench.comment_editor().unwrap().scroll_height(viewport), 126.);
});
cx.simulate_keystrokes("backspace backspace backspace backspace backspace");
assert_eq!(zones(&workbench, cx)[0].1, replying);
cx.simulate_keystrokes(&crate::keybindings::primary_keys("secondary-enter"));
cx.run_until_parked();
let thread = json!({ "$mid": 7, "commentControlHandle": 1, "commentThreadHandle": 7 });
assert_eq!(*ran.lock().unwrap(), vec![json!({ "thread": thread, "text": "Agreed\n!", "$mid": 9 })]);
assert_eq!(zones(&workbench, cx)[0].1, shown[0].1);
workbench.read_with(cx, |workbench, _| assert!(workbench.comment_editor().is_none() && workbench.editors.models.iter().all(|model| model.document().scheme != INPUT_SCHEME)));
workbench.update_in(cx, |workbench, _, cx| workbench.toggle_comment_thread(1, 7, cx));
assert!(zones(&workbench, cx).is_empty());
// Escape in the reply's editor collapses the thread (`workbench.action.hideComment`), and the text editor takes
// the keyboard.
workbench.update_in(cx, |workbench, window, cx| {
workbench.toggle_comment_thread(1, 7, cx);
workbench.expand_comment_reply(1, 7, window, cx);
});
cx.run_until_parked();
cx.simulate_keystrokes("escape");
workbench.update_in(cx, |workbench, window, _| {
assert!(workbench.comment_editor().is_none());
assert_eq!(workbench.key_context(window)["commentEditorFocused"], json!(false));
assert_eq!(workbench.editors.active().unwrap().document().scheme, "file");
});
assert!(zones(&workbench, cx).is_empty());
}
/// The zone widget takes the state colors for its head and body border only from a state change while it shows
/// (commentThreadZoneWidget.ts listens to `onDidChangeState` from its constructor), not from an earlier state.
#[gpui::test]
fn only_a_state_change_while_the_zone_shows_styles_it(cx: &mut TestAppContext) {
let (workbench, cx, _, dir) = open(cx, "comment-thread-state-style", "one\ntwo\n");
let request = |method: &str, args: Vec<Value>, cx: &mut VisualTestContext| {
workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_comments_request(method, &args, window, cx)));
};
let resource = |name: &str| json!({ "scheme": "file", "path": dir.join(name).to_string_lossy() });
let range = json!({ "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 1 });
request("$registerCommentController", vec![json!(1), json!("review"), json!("Review"), json!("test.ext")], cx);
for thread in [7, 8] {
request("$createCommentThread", vec![json!(1), json!(thread), json!("t"), resource("a.txt"), range.clone(), json!([]), json!({ "value": "test.ext" }), json!(false)], cx);
}
request("$updateCommentThread", vec![json!(1), json!(7), json!("t"), resource("a.txt"), json!({ "collapseState": 1 })], cx);
for thread in [7, 8] {
request("$updateCommentThread", vec![json!(1), json!(thread), json!("t"), resource("a.txt"), json!({ "state": 0 })], cx);
}
workbench.read_with(cx, |workbench, _| {
let model_id = workbench.editors.active().unwrap().model_id;
assert_eq!(workbench.comment_thread(1, 7).unwrap().state_styled_in, vec![model_id]);
assert!(workbench.comment_thread(1, 8).unwrap().state_styled_in.is_empty(), "thread 8 stayed collapsed, so had no zone");
});
}
/// A comment's `code` span keeps the text's background: only the hover, suggest details and parameter hints draw
/// `textCodeBlock.background` behind it (hover.css, suggest.css, parameterHints.css; commentsWidget has no rule).
#[gpui::test]
fn a_comment_s_code_span_draws_no_code_block_background(cx: &mut TestAppContext) {
let (workbench, cx, _, dir) = open(cx, "comment-code-span", "one\ntwo\n");
workbench.update(cx, |workbench, _| workbench.theme.set_customizations(&json!({ "textCodeBlock.background": "#123456" }), &json!({})));
let request = |method: &str, args: Vec<Value>, cx: &mut VisualTestContext| {
workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_comments_request(method, &args, window, cx)));
};
let resource = json!({ "scheme": "file", "path": dir.join("a.txt").to_string_lossy() });
let range = json!({ "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 2 });
request("$registerCommentController", vec![json!(1), json!("review"), json!("Review"), json!("test.ext")], cx);
request("$createCommentThread", vec![json!(1), json!(7), json!("t"), resource.clone(), range, json!([]), json!({ "value": "test.ext" }), json!(false)], cx);
let comment = json!({ "uniqueIdInThread": 1, "body": { "value": "Rename `count` here" }, "userName": "Ann" });
request("$updateCommentThread", vec![json!(1), json!(7), json!("t"), resource, json!({ "comments": [comment], "collapseState": 1 })], cx);
cx.run_until_parked();
let code_block = gpui::Background::from(workbench.read_with(cx, |workbench, _| gpui::Hsla::from(workbench.color("textCodeBlock.background"))));
let quads = cx.update(|window, _| window.painted_quads());
assert!(quads.iter().all(|quad| quad.background != code_block), "a quad on textCodeBlock.background");
}
#[test]
fn the_height_counts_the_head_comments_and_form_in_whole_lines() {
let comment = |body: Value| json!({ "body": body, "userName": "Ann" });
let thread = |comments: Vec<Value>| Thread {
handle: 1,
thread_id: String::new(),
resource: Value::Null,
range: None,
label: None,
context_value: None,
comments,
collapse_state: 1,
revealed: false,
can_reply: json!(true),
state: None,
is_template: false,
state_styled_in: Vec::new(),
};
// 22 head + 1 + (42 + 18) + 48 form + 6 arrow + 4 frame + 8 = 149, 9 lines of 18.
assert_eq!(widget_height(&thread(vec![comment(json!("one"))]), &[], |_| None, false, 0., 18.), 162.);
// A markdown body of two paragraphs counts two lines: 167, 10 lines.
assert_eq!(widget_height(&thread(vec![comment(json!({ "value": "one\n\ntwo" }))]), &[], |_| None, false, 0., 18.), 180.);
}
/// The zone takes the body's drawn height (`_refresh` measures the DOM): a one-line comment that wraps grows it past a
/// short one's.
#[gpui::test]
fn a_wrapped_comment_body_grows_its_zone(cx: &mut TestAppContext) {
let (workbench, cx, _, dir) = open(cx, "comment-wrapped-body", "one\ntwo\n");
let request = |method: &str, args: Vec<Value>, cx: &mut VisualTestContext| {
workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_comments_request(method, &args, window, cx)));
};
let resource = json!({ "scheme": "file", "path": dir.join("a.txt").to_string_lossy() });
let range = json!({ "startLineNumber": 1, "startColumn": 1, "endLineNumber": 1, "endColumn": 2 });
request("$registerCommentController", vec![json!(1), json!("review"), json!("Review"), json!("test.ext")], cx);
request("$createCommentThread", vec![json!(1), json!(7), json!("t"), resource.clone(), range, json!([]), json!({ "value": "test.ext" }), json!(false)], cx);
let mut heights = Vec::new();
for body in ["Short".to_owned(), "word ".repeat(200)] {
let comment = json!({ "uniqueIdInThread": 1, "body": body, "userName": "Ann" });
request("$updateCommentThread", vec![json!(1), json!(7), json!("t"), resource.clone(), json!({ "comments": [comment], "collapseState": 1 })], cx);
cx.run_until_parked();
heights.push(workbench.read_with(cx, |workbench, _| workbench.editors.pane_editor().unwrap().view_zones[0].height));
}
assert!(heights[1] > heights[0], "{heights:?}");
}
/// Every thread keeps its own reply form (commentReply.ts, one per `CommentThreadWidget`): opening a second one leaves
/// the first open with its text, and each form's action sends its own text.
#[gpui::test]
fn two_threads_keep_their_reply_forms_open_together(cx: &mut TestAppContext) {
let (workbench, cx, _, dir) = open(cx, "comment-two-forms", "one\ntwo\nthree\n");
let request = |method: &str, args: Vec<Value>, cx: &mut VisualTestContext| {
workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_comments_request(method, &args, window, cx)));
};
let resource = json!({ "scheme": "file", "path": dir.join("a.txt").to_string_lossy() });
request("$registerCommentController", vec![json!(1), json!("review"), json!("Review"), json!("test.ext")], cx);
for (thread, line) in [(7, 1), (8, 3)] {
let range = json!({ "startLineNumber": line, "startColumn": 1, "endLineNumber": line, "endColumn": 2 });
request("$createCommentThread", vec![json!(1), json!(thread), json!("t"), resource.clone(), range, json!([]), json!({ "value": "test.ext" }), json!(false)], cx);
let comment = json!({ "uniqueIdInThread": 1, "body": "Looks good", "userName": "Ann" });
request("$updateCommentThread", vec![json!(1), json!(thread), json!("t"), resource.clone(), json!({ "comments": [comment], "collapseState": 1 })], cx);
}
let heights = |cx: &mut VisualTestContext| workbench.read_with(cx, |workbench, _| workbench.editors.pane_editor().unwrap().view_zones.iter().map(|zone| zone.height).collect::<Vec<_>>());
let collapsed = heights(cx);
assert_eq!(collapsed.len(), 2);
workbench.update_in(cx, |workbench, window, cx| workbench.expand_comment_reply(1, 7, window, cx));
cx.run_until_parked();
cx.simulate_input("first");
workbench.update_in(cx, |workbench, window, cx| workbench.expand_comment_reply(1, 8, window, cx));
cx.run_until_parked();
cx.simulate_input("second");
workbench.read_with(cx, |workbench, _| {
let texts: Vec<_> = workbench.comments.forms.iter().map(|form| (form.thread, workbench.form_text(form))).collect();
assert_eq!(texts, vec![(7, "first".to_owned()), (8, "second".to_owned())]);
});
assert!(heights(cx).iter().zip(&collapsed).all(|(open, closed)| open > closed), "both zones hold a form");
let ran = Arc::new(Mutex::new(Vec::new()));
workbench.update_in(cx, |workbench, window, cx| {
let record = ran.clone();
workbench.commands.register("test.reply", move |_, args, _, _| {
record.lock().unwrap().extend(args);
crate::commands::Outcome::done()
});
workbench.run_comment_reply_action("test.reply", 1, 7, window, cx);
});
cx.run_until_parked();
assert_eq!(ran.lock().unwrap()[0]["text"], json!("first"));
workbench.read_with(cx, |workbench, _| assert_eq!(workbench.comments.forms.iter().map(|form| form.thread).collect::<Vec<_>>(), vec![8]));
}
/// The proposed comment menus: `comments/comment/editorActions` buttons left of the reply and edit form actions run
/// with the typed text and keep the form open (commentReply.ts and commentNode.ts `createCommentWidgetEditorActions`);
/// a right click on the head shows `comments/commentThread/title/context` with the thread (commentThreadHeader.ts) and
/// on a comment `comments/commentThread/comment/context` with the `commentNodeContext` (commentNode.ts).
#[gpui::test]
fn the_comment_editor_actions_and_context_menus_run_their_menus(cx: &mut TestAppContext) {
let (workbench, cx, _host, dir) = open(cx, "comment-editor-actions", "one\ntwo\nthree\n");
let resource = json!({ "scheme": "file", "path": dir.join("a.txt").to_string_lossy() });
let request = |method: &str, args: Vec<Value>, cx: &mut VisualTestContext| {
workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_comments_request(method, &args, window, cx)));
};
request("$registerCommentController", vec![json!(1), json!("review"), json!("Review"), json!("test.ext")], cx);
let range = json!({ "startLineNumber": 2, "startColumn": 1, "endLineNumber": 2, "endColumn": 4 });
request("$createCommentThread", vec![json!(1), json!(7), json!("t"), resource.clone(), range, json!([]), json!({ "value": "test.ext" }), json!(false)], cx);
let comment = json!({ "uniqueIdInThread": 1, "body": "Looks good", "userName": "Ann" });
request("$updateCommentThread", vec![json!(1), json!(7), json!("t"), resource.clone(), json!({ "comments": [comment], "collapseState": 1 })], cx);
let ran = Arc::new(Mutex::new(Vec::new()));
workbench.update_in(cx, |workbench, window, cx| {
let record = ran.clone();
workbench.commands.register("test.insert", move |_, args, _, _| {
record.lock().unwrap().extend(args);
crate::commands::Outcome::done()
});
for (menu, title) in [(MenuId::CommentThreadActions, "Reply"), (MenuId::CommentActions, "Save"), (MenuId::CommentEditorActions, "Insert"), (MenuId::CommentThreadTitleContext, "Title Action"), (MenuId::CommentThreadCommentContext, "Comment Action")] {
let id = if menu == MenuId::CommentEditorActions { "test.insert" } else { "test.other" };
let entry = Entry::Command { id: id.into(), precondition: None, toggled: None, alt: None };
workbench.menus.push(MenuItem { menu, entry, title: title.into(), group: "inline".into(), order: 0., when: None });
}
workbench.expand_comment_reply(1, 7, window, cx);
});
cx.run_until_parked();
cx.simulate_input("Draft");
cx.run_until_parked();
let insert = cx.debug_bounds("comment-reply-editor-action-test.insert").expect("the reply form shows the editor action");
let reply = cx.debug_bounds("comment-reply-action-test.other").expect("the reply form shows its action");
assert!(insert.right() <= reply.left(), "the editor actions sit left of the form actions");
cx.simulate_click(insert.center(), gpui::Modifiers::none());
cx.run_until_parked();
let thread = json!({ "$mid": 7, "commentControlHandle": 1, "commentThreadHandle": 7 });
assert_eq!(ran.lock().unwrap().drain(..).collect::<Vec<_>>(), vec![json!({ "thread": thread, "text": "Draft", "$mid": 9 })]);
workbench.read_with(cx, |workbench, _| assert!(workbench.comment_editor().is_some(), "the reply form stays open"));
let head = cx.debug_bounds("comment-thread-head").expect("the zone shows its head").center();
cx.simulate_mouse_down(head, gpui::MouseButton::Right, gpui::Modifiers::none());
cx.run_until_parked();
workbench.update_in(cx, |workbench, _, cx| {
let menu = workbench.context_menu.as_ref().expect("the head's context menu opens");
assert!(matches!(&menu.levels[0].actions[..], [MenuAction::Command { title, .. }] if title == "Title Action"), "{:?}", menu.levels[0].actions);
assert_eq!(menu.args, [thread.clone()]);
workbench.context_menu = None;
cx.notify();
});
let node = cx.debug_bounds("comment-node-0").expect("the zone shows its comment").center();
cx.simulate_mouse_down(node, gpui::MouseButton::Right, gpui::Modifiers::none());
cx.run_until_parked();
workbench.update_in(cx, |workbench, _, cx| {
let menu = workbench.context_menu.as_ref().expect("the comment's context menu opens");
assert!(matches!(&menu.levels[0].actions[..], [MenuAction::Command { title, .. }] if title == "Comment Action"), "{:?}", menu.levels[0].actions);
assert_eq!(menu.args, [json!({ "thread": thread, "commentUniqueId": 1, "$mid": 10 }), thread.clone()]);
workbench.context_menu = None;
cx.notify();
});
let editing = json!({ "uniqueIdInThread": 1, "body": "Looks good", "userName": "Ann", "mode": 0 });
request("$updateCommentThread", vec![json!(1), json!(7), json!("t"), resource, json!({ "comments": [editing], "collapseState": 1 })], cx);
cx.run_until_parked();
let insert = cx.debug_bounds("comment-edit-editor-action-1-test.insert").expect("the edit form shows the editor action");
let save = cx.debug_bounds("comment-edit-action-test.other").expect("the edit form shows its action");
assert!(insert.right() <= save.left());
cx.simulate_click(insert.center(), gpui::Modifiers::none());
cx.run_until_parked();
assert_eq!(*ran.lock().unwrap(), vec![json!({ "thread": thread, "commentUniqueId": 1, "text": "Looks good", "$mid": 11 })]);
workbench.read_with(cx, |workbench, _| assert!(workbench.comments.forms.iter().any(|form| form.comment == Some(1)), "the edit form stays open"));
}
/// commentThreadAdditionalActions.ts: the `comments/commentThread/additionalActions` items show under the reply form,
/// grow the zone by the separator and button row, and run with the `CommentThreadInstance`; a submenu's chevron opens
/// its actions.
#[gpui::test]
fn additional_actions_show_under_the_body_and_run_with_the_thread(cx: &mut TestAppContext) {
let (workbench, cx, _host, dir) = open(cx, "comment-additional-actions", "one\ntwo\nthree\n");
let resource = json!({ "scheme": "file", "path": dir.join("a.txt").to_string_lossy() });
let request = |method: &str, args: Vec<Value>, cx: &mut VisualTestContext| {
workbench.update_in(cx, |workbench, window, cx| drop(workbench.handle_comments_request(method, &args, window, cx)));
};
request("$registerCommentController", vec![json!(1), json!("review"), json!("Review"), json!("test.ext")], cx);
let range = json!({ "startLineNumber": 2, "startColumn": 1, "endLineNumber": 2, "endColumn": 4 });
request("$createCommentThread", vec![json!(1), json!(7), json!("t"), resource.clone(), range, json!([]), json!({ "value": "test.ext" }), json!(false)], cx);
let comment = json!({ "uniqueIdInThread": 1, "body": "Looks good", "userName": "Ann" });
request("$updateCommentThread", vec![json!(1), json!(7), json!("t"), resource, json!({ "comments": [comment], "collapseState": 1 })], cx);
cx.run_until_parked();
let zone_height = |cx: &mut VisualTestContext| workbench.read_with(cx, |workbench, _| workbench.editors.pane_editor().unwrap().view_zones[0].height);
let without = zone_height(cx);
assert!(cx.debug_bounds("comment-additional-actions").is_none(), "no bar without actions");
let ran = Arc::new(Mutex::new(Vec::new()));
workbench.update_in(cx, |workbench, _, cx| {
let record = ran.clone();
workbench.commands.register("test.resolve", move |_, args, _, _| {
record.lock().unwrap().extend(args);
crate::commands::Outcome::done()
});
let command = |menu, id: &str, title: &str| MenuItem { menu, entry: Entry::Command { id: id.into(), precondition: None, toggled: None, alt: None }, title: title.into(), group: "inline".into(), order: 0., when: None };
workbench.menus.push(command(MenuId::CommentThreadAdditionalActions, "test.resolve", "Resolve"));
workbench.menus.push(MenuItem { menu: MenuId::CommentThreadAdditionalActions, entry: Entry::Submenu { submenu: MenuId::Test, toggled: None }, title: "Status".into(), group: "inline".into(), order: 1., when: None });
workbench.menus.push(command(MenuId::Test, "test.accept", "Accept"));
workbench.menus.push(command(MenuId::Test, "test.reject", "Reject"));
cx.notify();
});
cx.run_until_parked();
let bar = cx.debug_bounds("comment-additional-actions").expect("the bar shows under the body");
// 2px past the reply button's 8px margin, the 1px separator, 14px, the 22px buttons and 10px.
assert_eq!(f32::from(bar.size.height), 49.);
// 149 + 49 = 198, 11 lines of 18.
assert_eq!((without, zone_height(cx)), (162., 198.));
let node = cx.debug_bounds("comment-node-0").expect("the zone shows its comment");
assert!(bar.top() >= node.bottom() + px(48.), "the bar sits under the reply form");
let resolve = cx.debug_bounds("comment-additional-action-test.resolve").expect("the command shows as a button");
let accept = cx.debug_bounds("comment-additional-action-test.accept").expect("the submenu shows its first action");
assert!(resolve.right() < accept.left());
cx.simulate_click(resolve.center(), gpui::Modifiers::none());
cx.run_until_parked();
let instance = json!({ "thread": { "$mid": 7, "commentControlHandle": 1, "commentThreadHandle": 7 }, "$mid": 8 });
assert_eq!(*ran.lock().unwrap(), vec![instance.clone()]);
let dropdown = cx.debug_bounds("comment-additional-dropdown").expect("the submenu has a chevron");
cx.simulate_click(dropdown.center(), gpui::Modifiers::none());
cx.run_until_parked();
workbench.read_with(cx, |workbench, _| {
let menu = workbench.context_menu.as_ref().expect("the chevron opens the submenu's actions");
let titles: Vec<_> = menu.levels[0].actions.iter().filter_map(|action| match action {
MenuAction::Command { title, .. } => Some(title.as_str()),
_ => None,
}).collect();
assert_eq!(titles, ["Accept", "Reject"]);
assert_eq!(menu.args, [instance]);
});
}