Add test for pane: toggle pin tab (#31906)

Also adds the optimization to not move a tab being pinned when its
destination index is the same as its index.

Release Notes:

- N/A
This commit is contained in:
Joseph T. Lyons 2025-06-02 11:58:10 -04:00 committed by GitHub
parent ebed567adb
commit 1ed4647203
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2087,13 +2087,17 @@ impl Pane {
let id = self.item_for_index(ix)?.item_id();
self.workspace
.update(cx, |_, cx| {
cx.defer_in(window, move |_, window, cx| {
move_item(&pane, &pane, id, destination_index, window, cx)
});
})
.ok()?;
if ix == destination_index {
cx.notify()
} else {
self.workspace
.update(cx, |_, cx| {
cx.defer_in(window, move |_, window, cx| {
move_item(&pane, &pane, id, destination_index, window, cx)
});
})
.ok()?;
}
Some(())
});
@ -4085,6 +4089,30 @@ mod tests {
assert_item_labels(&pane, ["A^", "B^", "C^", "G*^"], cx);
}
#[gpui::test]
async fn test_toggle_pin_tab(cx: &mut TestAppContext) {
init_test(cx);
let fs = FakeFs::new(cx.executor());
let project = Project::test(fs, None, cx).await;
let (workspace, cx) =
cx.add_window_view(|window, cx| Workspace::test_new(project.clone(), window, cx));
let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone());
set_labeled_items(&pane, ["A", "B*", "C"], cx);
assert_item_labels(&pane, ["A", "B*", "C"], cx);
pane.update_in(cx, |pane, window, cx| {
pane.toggle_pin_tab(&TogglePinTab, window, cx);
});
assert_item_labels(&pane, ["B*!", "A", "C"], cx);
pane.update_in(cx, |pane, window, cx| {
pane.toggle_pin_tab(&TogglePinTab, window, cx);
});
assert_item_labels(&pane, ["B*", "A", "C"], cx);
}
#[gpui::test]
async fn test_add_item_with_new_item(cx: &mut TestAppContext) {
init_test(cx);