chore: audit components

This commit is contained in:
2026-11-10 15:06:16 +07:00
parent af2177c6c8
commit 03369f501e
92 changed files with 2744 additions and 1947 deletions
+4 -4
View File
@@ -28,10 +28,10 @@ impl Render for Harness {
})
.items(|_, _| {
vec![
ListItem::new("One"),
ListItem::new("Two"),
ListItem::new("Unavailable").disabled(true),
ListItem::new("Three"),
ListItem::new("one", "One"),
ListItem::new("two", "Two"),
ListItem::new("unavailable", "Unavailable").disabled(true),
ListItem::new("three", "Three"),
]
}),
)
+5 -5
View File
@@ -30,11 +30,11 @@ impl Render for Harness {
})
.entries(|_, _| {
vec![
SidebarEntry::header("Favorites"), // 0: never selectable
SidebarEntry::row("Documents"), // 1
SidebarEntry::row("Locked").disabled(true), // 2
SidebarEntry::header("Locations"), // 3: never selectable
SidebarEntry::row("Trash"), // 4
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
]
}),
)
+66
View File
@@ -8,6 +8,7 @@ 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,
@@ -64,6 +65,55 @@ fn click(visual: &mut VisualTestContext, position: gpui::Point<gpui::Pixels>) {
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();
@@ -100,3 +150,19 @@ fn arrow_keys_skip_disabled_tabs_and_never_wrap() {
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");
}
+9 -5
View File
@@ -38,14 +38,18 @@ impl Render for Harness {
})
.items(|_, _| {
vec![
TreeItem::new("Root")
TreeItem::new("root", "Root")
.depth(0)
.expandable(true)
.expanded(true),
TreeItem::new("Child").depth(1),
TreeItem::new("Collapsed").depth(0).expandable(true),
TreeItem::new("Untouchable").depth(1).disabled(true),
TreeItem::new("Last").depth(0),
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),
]
}),
)