chore: clean up all tests

This commit is contained in:
2026-11-11 16:52:13 +07:00
parent 9326fca63d
commit 4db2f14865
52 changed files with 0 additions and 11093 deletions
View File
-140
View File
@@ -1,140 +0,0 @@
use std::{cell::RefCell, rc::Rc};
use gpui::{
Context, IntoElement, Modifiers, MouseButton, ParentElement as _, Render, Styled as _,
TestAppContext, VisualTestContext, Window, WindowHandle, div, point, px,
};
use gpui_native_data::list::{List, ListItem};
use gpui_native_theme::Theme;
struct Harness {
selected: Option<usize>,
changes: Rc<RefCell<Vec<Option<usize>>>>,
}
impl Render for Harness {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let changes = self.changes.clone();
let view = cx.entity();
div().size_full().child(
List::new("test-list")
.selected(self.selected)
.on_change(move |next, _, cx| {
changes.borrow_mut().push(next);
view.update(cx, |harness, cx| {
harness.selected = next;
cx.notify();
});
})
.items(|_, _| {
vec![
ListItem::new("one", "One"),
ListItem::new("two", "Two"),
ListItem::new("unavailable", "Unavailable").disabled(true),
ListItem::new("three", "Three"),
]
}),
)
}
}
type Changes = Rc<RefCell<Vec<Option<usize>>>>;
type ListWindow = (
TestAppContext,
VisualTestContext,
WindowHandle<Harness>,
Changes,
);
/// Rows paint at the top-left with no outer padding: one row per ~34 px band
/// (16 px text line + 2×4 px padding + 2 px gap), so clicks at `(50, 16/48/80/112)`
/// land on One / Two / the disabled Unavailable / Three.
fn list_window(selected: Option<usize>) -> ListWindow {
let mut cx = TestAppContext::single();
cx.update(Theme::init);
let changes = Rc::new(RefCell::new(Vec::new()));
let harness_changes = changes.clone();
let window = cx.add_window(move |_, _| Harness {
selected,
changes: harness_changes,
});
let mut visual = VisualTestContext::from_window(window.into(), &cx);
visual.update(|window, cx| {
window.draw(cx).clear(cx);
});
(cx, visual, window, changes)
}
fn draw(visual: &mut VisualTestContext) {
visual.update(|window, cx| {
window.draw(cx).clear(cx);
});
}
fn click(visual: &mut VisualTestContext, position: gpui::Point<gpui::Pixels>) {
visual.simulate_mouse_down(position, MouseButton::Left, Modifiers::default());
visual.simulate_mouse_up(position, MouseButton::Left, Modifiers::default());
}
#[test]
fn clicking_a_row_selects_it_and_hands_the_list_the_keyboard() {
let (_cx, mut visual, _window, changes) = list_window(None);
click(&mut visual, point(px(50.), px(16.)));
assert_eq!(*changes.borrow(), vec![Some(0)]);
// The click focused the list, so the arrows navigate from here.
visual.simulate_keystrokes("down");
draw(&mut visual);
assert_eq!(*changes.borrow(), vec![Some(0), Some(1)]);
}
#[test]
fn clicking_a_disabled_row_reports_nothing() {
let (_cx, mut visual, _window, changes) = list_window(None);
click(&mut visual, point(px(50.), px(80.)));
draw(&mut visual);
assert_eq!(*changes.borrow(), Vec::<Option<usize>>::new());
}
#[test]
fn keyboard_navigation_skips_disabled_rows_and_never_wraps() {
let (_cx, mut visual, _window, changes) = list_window(None);
click(&mut visual, point(px(50.), px(16.)));
visual.simulate_keystrokes("down"); // over the disabled row → Two
visual.simulate_keystrokes("down"); // over the disabled row → Three
visual.simulate_keystrokes("down"); // last selectable; no wrap
draw(&mut visual);
assert_eq!(*changes.borrow(), vec![Some(0), Some(1), Some(3)]);
visual.simulate_keystrokes("home");
visual.simulate_keystrokes("end");
visual.simulate_keystrokes("up"); // over the disabled row → Two
draw(&mut visual);
assert_eq!(
*changes.borrow(),
vec![Some(0), Some(1), Some(3), Some(0), Some(3), Some(1)]
);
}
#[test]
fn arrow_down_with_no_selection_picks_the_first_selectable_row() {
let (mut cx, mut visual, window, changes) = list_window(Some(1));
// Focus the list, then clear the selection app-side.
click(&mut visual, point(px(50.), px(48.)));
window
.update(&mut cx, |harness, _, cx| {
harness.selected = None;
cx.notify();
})
.unwrap();
draw(&mut visual);
visual.simulate_keystrokes("down");
draw(&mut visual);
assert_eq!(*changes.borrow(), vec![Some(1), Some(0)]);
}
-119
View File
@@ -1,119 +0,0 @@
use std::{cell::RefCell, rc::Rc};
use gpui::{
Context, IntoElement, Modifiers, MouseButton, ParentElement as _, Render, Styled as _,
TestAppContext, VisualTestContext, Window, div, point, px,
};
use gpui_native_data::sidebar::{Sidebar, SidebarEntry};
use gpui_native_theme::Theme;
type Changes = Rc<RefCell<Vec<Option<usize>>>>;
struct Harness {
selected: Option<usize>,
changes: Changes,
}
impl Render for Harness {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let changes = self.changes.clone();
let view = cx.entity();
div().size_full().child(
Sidebar::new("test-sidebar")
.selected(self.selected)
.on_change(move |next, _, cx| {
changes.borrow_mut().push(next);
view.update(cx, |harness, cx| {
harness.selected = next;
cx.notify();
});
})
.entries(|_, _| {
vec![
SidebarEntry::header("Favorites"), // 0: never selectable
SidebarEntry::row("documents", "Documents"), // 1
SidebarEntry::row("locked", "Locked").disabled(true), // 2
SidebarEntry::header("Locations"), // 3: never selectable
SidebarEntry::row("trash", "Trash"), // 4
]
}),
)
}
}
/// Entries stack from the top-left: the header band (~32 px) then ~34 px row
/// bands, so clicks at `(50, 16)` hit the header, `(50, 48)` Documents,
/// `(50, 82)` Locked, `(50, 116)` the second header, `(50, 150)` Trash.
fn sidebar_window() -> (TestAppContext, VisualTestContext, Changes) {
let mut cx = TestAppContext::single();
cx.update(Theme::init);
let changes = Rc::new(RefCell::new(Vec::new()));
let harness_changes = changes.clone();
let window = cx.add_window(move |_, _| Harness {
selected: None,
changes: harness_changes,
});
let mut visual = VisualTestContext::from_window(window.into(), &cx);
visual.update(|window, cx| {
window.draw(cx).clear(cx);
});
(cx, visual, changes)
}
fn draw(visual: &mut VisualTestContext) {
visual.update(|window, cx| {
window.draw(cx).clear(cx);
});
}
fn click(visual: &mut VisualTestContext, position: gpui::Point<gpui::Pixels>) {
visual.simulate_mouse_down(position, MouseButton::Left, Modifiers::default());
visual.simulate_mouse_up(position, MouseButton::Left, Modifiers::default());
}
#[test]
fn clicking_a_row_selects_it_and_hands_the_sidebar_the_keyboard() {
let (_cx, mut visual, changes) = sidebar_window();
// The header band is not a row: clicking it reports nothing.
click(&mut visual, point(px(50.), px(16.)));
draw(&mut visual);
assert!(changes.borrow().is_empty());
click(&mut visual, point(px(50.), px(48.)));
assert_eq!(*changes.borrow(), vec![Some(1)]);
// The click focused the sidebar; the arrows move from here.
visual.simulate_keystrokes("down");
draw(&mut visual);
assert_eq!(*changes.borrow(), vec![Some(1), Some(4)]);
}
#[test]
fn clicking_a_disabled_row_reports_nothing() {
let (_cx, mut visual, changes) = sidebar_window();
click(&mut visual, point(px(50.), px(82.)));
draw(&mut visual);
assert!(changes.borrow().is_empty());
}
#[test]
fn keyboard_navigation_skips_headers_disabled_rows_and_never_wraps() {
let (_cx, mut visual, changes) = sidebar_window();
click(&mut visual, point(px(50.), px(48.))); // Documents, focuses
visual.simulate_keystrokes("down"); // over Locked → Trash
visual.simulate_keystrokes("down"); // over the second header; no wrap
draw(&mut visual);
assert_eq!(*changes.borrow(), vec![Some(1), Some(4)]);
visual.simulate_keystrokes("up"); // over Locked → Documents
visual.simulate_keystrokes("end"); // last selectable row
visual.simulate_keystrokes("home"); // first selectable row
draw(&mut visual);
assert_eq!(
*changes.borrow(),
vec![Some(1), Some(4), Some(1), Some(4), Some(1)]
);
}
-168
View File
@@ -1,168 +0,0 @@
use std::{cell::RefCell, rc::Rc};
use gpui::{
Context, IntoElement, Modifiers, MouseButton, ParentElement as _, Render, Styled as _,
TestAppContext, VisualTestContext, Window, div, point, px,
};
use gpui_native_data::tabs::{Tab, Tabs};
use gpui_native_theme::Theme;
type Changes = Rc<RefCell<Vec<usize>>>;
type Closes = Rc<RefCell<Vec<usize>>>;
struct Harness {
selected: usize,
changes: Changes,
}
impl Render for Harness {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let changes = self.changes.clone();
let view = cx.entity();
div().size_full().child(
Tabs::new("test-tabs")
.selected(self.selected)
.on_change(move |next, _, cx| {
changes.borrow_mut().push(next);
view.update(cx, |harness, cx| {
harness.selected = next;
cx.notify();
});
})
.tabs(|_, _| {
vec![
Tab::new("one", "One"),
Tab::new("two", "Two"),
Tab::new("off", "Off").disabled(true),
Tab::new("end", "End"),
]
}),
)
}
}
/// Same-length labels keep the strip's geometry predictable: each tab is
/// roughly 40 px wide with a 4 px gap, so clicks at `(20/62/104/146, 12)`
/// land on One / Two / the disabled Off / End.
fn tabs_window() -> (TestAppContext, VisualTestContext, Changes) {
let mut cx = TestAppContext::single();
cx.update(Theme::init);
let changes = Rc::new(RefCell::new(Vec::new()));
let harness_changes = changes.clone();
let window = cx.add_window(move |_, _| Harness {
selected: 0,
changes: harness_changes,
});
let mut visual = VisualTestContext::from_window(window.into(), &cx);
visual.update(|window, cx| {
window.draw(cx).clear(cx);
});
(cx, visual, changes)
}
fn click(visual: &mut VisualTestContext, position: gpui::Point<gpui::Pixels>) {
visual.simulate_mouse_down(position, MouseButton::Left, Modifiers::default());
visual.simulate_mouse_up(position, MouseButton::Left, Modifiers::default());
}
struct CloseHarness {
changes: Changes,
closes: Closes,
}
impl Render for CloseHarness {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let changes = self.changes.clone();
let closes = self.closes.clone();
let view = cx.entity();
let close_view = view.clone();
div().size_full().child(
Tabs::new("close-tabs")
.on_change(move |next, _, cx| {
changes.borrow_mut().push(next);
view.update(cx, |_, cx| cx.notify());
})
.on_close(move |index, _, cx| {
closes.borrow_mut().push(index);
close_view.update(cx, |_, cx| cx.notify());
})
.tabs(|_, _| {
vec![
Tab::new("one", "One").closeable(true),
Tab::new("two", "Two"),
]
}),
)
}
}
fn close_tabs_window() -> (TestAppContext, VisualTestContext, Changes, Closes) {
let mut cx = TestAppContext::single();
cx.update(Theme::init);
let changes = Rc::new(RefCell::new(Vec::new()));
let closes = Rc::new(RefCell::new(Vec::new()));
let harness_changes = changes.clone();
let harness_closes = closes.clone();
let window = cx.add_window(move |_, _| CloseHarness {
changes: harness_changes,
closes: harness_closes,
});
let mut visual = VisualTestContext::from_window(window.into(), &cx);
visual.update(|window, cx| {
window.draw(cx).clear(cx);
});
(cx, visual, changes, closes)
}
#[test]
fn clicking_a_tab_selects_it_and_hands_the_strip_the_keyboard() {
let (_cx, mut visual, changes) = tabs_window();
// Tab 0 is already selected; selecting it again reports nothing.
click(&mut visual, point(px(20.), px(12.)));
assert!(changes.borrow().is_empty());
// The click focused the strip, so the arrows switch from here.
visual.simulate_keystrokes("right");
assert_eq!(*changes.borrow(), vec![1]);
}
#[test]
fn clicking_a_disabled_tab_reports_nothing() {
let (_cx, mut visual, changes) = tabs_window();
click(&mut visual, point(px(104.), px(12.)));
assert!(changes.borrow().is_empty());
}
#[test]
fn arrow_keys_skip_disabled_tabs_and_never_wrap() {
let (_cx, mut visual, changes) = tabs_window();
click(&mut visual, point(px(20.), px(12.))); // One: already selected, no report
visual.simulate_keystrokes("right"); // Two
visual.simulate_keystrokes("right"); // over the disabled tab → End
visual.simulate_keystrokes("right"); // last; no wrap
assert_eq!(*changes.borrow(), vec![1, 3]);
visual.simulate_keystrokes("left"); // over the disabled tab → Two
visual.simulate_keystrokes("home"); // One
visual.simulate_keystrokes("end"); // End
assert_eq!(*changes.borrow(), vec![1, 3, 1, 0, 3]);
}
#[test]
fn clicking_the_close_control_reports_a_close_without_selecting() {
let (_cx, mut visual, changes, closes) = close_tabs_window();
// Only the closeable tab ships a close control.
let selector: &'static str = Box::leak(String::from("close-tabs-close-One").into_boxed_str());
let close_bounds = visual
.debug_bounds(selector)
.expect("closeable tab renders a close control");
assert!(visual.debug_bounds("close-tabs-close-Two").is_none());
click(&mut visual, close_bounds.center());
assert_eq!(*closes.borrow(), vec![0]);
assert!(changes.borrow().is_empty(), "a close is not a selection");
}
-181
View File
@@ -1,181 +0,0 @@
use std::{cell::RefCell, rc::Rc};
use gpui::{
Context, IntoElement, Modifiers, MouseButton, ParentElement as _, Render, Styled as _,
TestAppContext, VisualTestContext, Window, WindowHandle, div, point, px,
};
use gpui_native_data::tree::{Tree, TreeItem};
use gpui_native_theme::Theme;
type Changes = Rc<RefCell<Vec<Option<usize>>>>;
type Disclosures = Rc<RefCell<Vec<usize>>>;
struct Harness {
selected: Option<usize>,
changes: Changes,
disclosures: Disclosures,
}
impl Render for Harness {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let changes = self.changes.clone();
let disclosures = self.disclosures.clone();
let view = cx.entity();
let change_view = view.clone();
div().size_full().child(
Tree::new("test-tree")
.selected(self.selected)
.on_change(move |next, _, cx| {
changes.borrow_mut().push(next);
change_view.update(cx, |harness, cx| {
harness.selected = next;
cx.notify();
});
})
.on_disclosure(move |index, _, cx| {
disclosures.borrow_mut().push(index);
view.update(cx, |_, cx| cx.notify());
})
.items(|_, _| {
vec![
TreeItem::new("root", "Root")
.depth(0)
.expandable(true)
.expanded(true),
TreeItem::new("child", "Child").depth(1),
TreeItem::new("collapsed", "Collapsed")
.depth(0)
.expandable(true),
TreeItem::new("untouchable", "Untouchable")
.depth(1)
.disabled(true),
TreeItem::new("last", "Last").depth(0),
]
}),
)
}
}
/// Rows paint at the top-left, one per ~34 px band (same rhythm as the
/// list), so clicks at `(50, 16/48/80/112/144)` land on Root / Child /
/// Collapsed / the disabled Untouchable / Last. Each expandable row leads
/// with a 16 px disclosure slot at its indent — a click at `(24, y)` hits
/// row 0's chevron.
fn tree_window() -> (
TestAppContext,
VisualTestContext,
WindowHandle<Harness>,
Changes,
Disclosures,
) {
let mut cx = TestAppContext::single();
cx.update(Theme::init);
let changes = Rc::new(RefCell::new(Vec::new()));
let disclosures = Rc::new(RefCell::new(Vec::new()));
let harness_changes = changes.clone();
let harness_disclosures = disclosures.clone();
let window = cx.add_window(move |_, _| Harness {
selected: None,
changes: harness_changes,
disclosures: harness_disclosures,
});
let mut visual = VisualTestContext::from_window(window.into(), &cx);
visual.update(|window, cx| {
window.draw(cx).clear(cx);
});
(cx, visual, window, changes, disclosures)
}
fn draw(visual: &mut VisualTestContext) {
visual.update(|window, cx| {
window.draw(cx).clear(cx);
});
}
fn click(visual: &mut VisualTestContext, position: gpui::Point<gpui::Pixels>) {
visual.simulate_mouse_down(position, MouseButton::Left, Modifiers::default());
visual.simulate_mouse_up(position, MouseButton::Left, Modifiers::default());
}
#[test]
fn clicking_a_row_selects_it_and_hands_the_tree_the_keyboard() {
let (_cx, mut visual, _window, changes, disclosures) = tree_window();
click(&mut visual, point(px(50.), px(16.)));
assert_eq!(*changes.borrow(), vec![Some(0)]);
assert!(disclosures.borrow().is_empty());
// The click focused the tree; arrows move within the visible rows.
visual.simulate_keystrokes("down");
draw(&mut visual);
assert_eq!(*changes.borrow(), vec![Some(0), Some(1)]);
}
#[test]
fn clicking_the_disclosure_toggles_without_selecting() {
let (_cx, mut visual, _window, changes, disclosures) = tree_window();
// Row 0's chevron, not its label.
click(&mut visual, point(px(24.), px(16.)));
draw(&mut visual);
assert_eq!(*disclosures.borrow(), vec![0]);
assert!(
changes.borrow().is_empty(),
"a disclosure is not a selection"
);
}
#[test]
fn arrow_right_expands_and_left_collapses_the_selected_row() {
let (_cx, mut visual, _window, changes, disclosures) = tree_window();
click(&mut visual, point(px(50.), px(16.))); // Root: expanded expandable
visual.simulate_keystrokes("left"); // collapse → reports
visual.simulate_keystrokes("right"); // still collapsed per the caller → nothing yet
visual.simulate_keystrokes("down"); // Child: a leaf → arrows are inert
visual.simulate_keystrokes("right");
visual.simulate_keystrokes("left");
draw(&mut visual);
assert_eq!(*disclosures.borrow(), vec![0]);
assert_eq!(
*changes.borrow(),
vec![Some(0), Some(1)],
"disclosure keys never change the selection"
);
// Select the collapsed expandable row and expand it.
click(&mut visual, point(px(50.), px(80.)));
visual.simulate_keystrokes("right");
draw(&mut visual);
assert_eq!(*disclosures.borrow(), vec![0, 2]);
}
#[test]
fn keyboard_navigation_skips_disabled_rows_and_never_wraps() {
let (_cx, mut visual, _window, changes, _disclosures) = tree_window();
click(&mut visual, point(px(50.), px(16.)));
visual.simulate_keystrokes("down"); // Two
visual.simulate_keystrokes("down"); // Collapsed — selectable, not disabled
visual.simulate_keystrokes("down"); // over the disabled row → Last
visual.simulate_keystrokes("down"); // last selectable; no wrap
draw(&mut visual);
assert_eq!(*changes.borrow(), vec![Some(0), Some(1), Some(2), Some(4)]);
visual.simulate_keystrokes("home");
visual.simulate_keystrokes("end");
visual.simulate_keystrokes("up"); // over the disabled row
draw(&mut visual);
assert_eq!(
*changes.borrow(),
vec![
Some(0),
Some(1),
Some(2),
Some(4),
Some(0),
Some(4),
Some(2)
]
);
}