From c58abf1b0b33285ec541cb2101ee48c031a9ad2e Mon Sep 17 00:00:00 2001 From: Julia Date: Tue, 1 Nov 2022 13:29:21 -0400 Subject: [PATCH] Add test for new tab order history behavior --- crates/workspace/src/pane.rs | 75 +++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/crates/workspace/src/pane.rs b/crates/workspace/src/pane.rs index 5bd228c030..be3909c3c9 100644 --- a/crates/workspace/src/pane.rs +++ b/crates/workspace/src/pane.rs @@ -1631,9 +1631,11 @@ impl NavHistory { #[cfg(test)] mod tests { + use std::sync::Arc; + use super::*; use crate::tests::TestItem; - use gpui::TestAppContext; + use gpui::{executor::Deterministic, TestAppContext}; use project::FakeFs; #[gpui::test] @@ -1913,6 +1915,77 @@ mod tests { ); } + #[gpui::test] + async fn test_remove_item_ordering(deterministic: Arc, cx: &mut TestAppContext) { + Settings::test_async(cx); + let fs = FakeFs::new(cx.background()); + + let project = Project::test(fs, None, cx).await; + let (_, workspace) = + cx.add_window(|cx| Workspace::new(project, |_, _| unimplemented!(), cx)); + let pane = workspace.read_with(cx, |workspace, _| workspace.active_pane().clone()); + + add_labled_item(&workspace, &pane, "A", cx); + add_labled_item(&workspace, &pane, "B", cx); + add_labled_item(&workspace, &pane, "C", cx); + add_labled_item(&workspace, &pane, "D", cx); + assert_item_labels(&pane, ["A", "B", "C", "D*"], cx); + + pane.update(cx, |pane, cx| pane.activate_item(1, false, false, cx)); + add_labled_item(&workspace, &pane, "1", cx); + assert_item_labels(&pane, ["A", "B", "1*", "C", "D"], cx); + + workspace.update(cx, |workspace, cx| { + Pane::close_active_item(workspace, &CloseActiveItem, cx); + }); + deterministic.run_until_parked(); + assert_item_labels(&pane, ["A", "B*", "C", "D"], cx); + + pane.update(cx, |pane, cx| pane.activate_item(3, false, false, cx)); + assert_item_labels(&pane, ["A", "B", "C", "D*"], cx); + + workspace.update(cx, |workspace, cx| { + Pane::close_active_item(workspace, &CloseActiveItem, cx); + }); + deterministic.run_until_parked(); + assert_item_labels(&pane, ["A", "B*", "C"], cx); + + workspace.update(cx, |workspace, cx| { + Pane::close_active_item(workspace, &CloseActiveItem, cx); + }); + deterministic.run_until_parked(); + assert_item_labels(&pane, ["A", "C*"], cx); + + workspace.update(cx, |workspace, cx| { + Pane::close_active_item(workspace, &CloseActiveItem, cx); + }); + deterministic.run_until_parked(); + assert_item_labels(&pane, ["A*"], cx); + } + + fn add_labled_item( + workspace: &ViewHandle, + pane: &ViewHandle, + label: &str, + cx: &mut TestAppContext, + ) -> Box> { + workspace.update(cx, |workspace, cx| { + let labeled_item = Box::new(cx.add_view(|_| TestItem::new().with_label(label))); + + Pane::add_item( + workspace, + pane, + labeled_item.clone(), + false, + false, + None, + cx, + ); + + labeled_item + }) + } + fn set_labeled_items( workspace: &ViewHandle, pane: &ViewHandle,