Skip to content

Commit 0063af2

Browse files
AprilNEAcostajohnt
andcommitted
test(gui): pin long bindings inside their label card
Adopt the regression test from #1406: mark each label card and its value row with a debug selector, render the synthetic model at 1200px, and assert the row's bounds stay inside the card. Without the card's `items_stretch` the Forward row measures 206px over a 156px card, the overflow #1401 reported from Windows. Pinned to English under the locale lock, since the zh-CN labels are short enough to pass regardless. Every `BindingLabel` constructor supplies an icon, so the field doc and the row comment stop claiming the gesture summary has none. Co-authored-by: John Costa <costajohnt@gmail.com>
1 parent 55a86be commit 0063af2

1 file changed

Lines changed: 59 additions & 5 deletions

File tree

  • crates/openlogi-desktop/src/features/mouse

‎crates/openlogi-desktop/src/features/mouse/view.rs‎

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ fn label_control(
580580
Side::Right => model.left + model.width + SIDE_GAP,
581581
};
582582
let view = view.clone();
583+
let control = label.id;
583584
let trigger = LabelTrigger {
584585
id: ("label-trigger", idx).into(),
585586
label,
@@ -594,26 +595,27 @@ fn label_control(
594595
.top(px(label.y - LABEL_H / 2.))
595596
.w(px(LABEL_W))
596597
.h(px(LABEL_H))
598+
.debug_selector(move || format!("label-card-{control:?}"))
597599
.child(trigger)
598600
}
599601

600602
struct BindingLabel {
601603
text: gpui::SharedString,
602604
/// Vendored action-icon asset path (see [`action_icon_path`]) for the
603-
/// card's leading glyph, or `None` for the gesture summary / unbound.
605+
/// card's leading glyph. Every constructor currently supplies one; the
606+
/// `Option` is the seam for icon-less bindings.
604607
icon: Option<&'static str>,
605608
}
606609

607610
impl BindingLabel {
608611
/// The card's value row: the leading action icon, the binding text, and
609612
/// the trailing chevron, all tinted with `color`.
610-
fn row(self, color: Hsla, pal: theme::Palette) -> impl IntoElement {
613+
fn row(self, color: Hsla, pal: theme::Palette) -> gpui::Div {
611614
h_flex()
612615
.items_center()
613616
.gap_2()
614617
// Leading action icon (same glyph as the picker rows), tinted with
615618
// the value so it tracks the default / set / highlighted state.
616-
// Absent for the gesture summary / unbound.
617619
.when_some(self.icon, |row, path| {
618620
row.child(svg().path(path).size_4().flex_none().text_color(color))
619621
})
@@ -717,7 +719,11 @@ impl RenderOnce for LabelTrigger {
717719
)
718720
// Current binding — the value (sm), the same size as the action rows
719721
// it edits.
720-
.child(self.binding.row(binding_color, pal))
722+
.child(
723+
self.binding
724+
.row(binding_color, pal)
725+
.debug_selector(move || format!("label-value-row-{btn:?}")),
726+
)
721727
.on_click(move |_event, _window, cx| {
722728
click_view.update(cx, |this, cx| {
723729
this.select(btn);
@@ -929,11 +935,12 @@ impl RenderOnce for HotspotTrigger {
929935

930936
#[cfg(test)]
931937
mod tests {
932-
use gpui::TestAppContext;
938+
use gpui::{TestAppContext, size};
933939
use openlogi_core::config::Config;
934940

935941
use super::*;
936942
use crate::services::assets::AssetResolver;
943+
use crate::services::i18n::LOCALE_LOCK;
937944
use crate::state::ConfigPersistence;
938945

939946
fn install_app_state(cx: &mut TestAppContext) {
@@ -955,6 +962,53 @@ mod tests {
955962
});
956963
}
957964

965+
#[gpui::test]
966+
fn long_bindings_stay_inside_their_label_card(cx: &mut TestAppContext) {
967+
// #1401: the card's Button base centres its children on the cross axis,
968+
// so without `items_stretch` the value row keeps its natural width and
969+
// overflows both edges once the binding name is wider than the card. The
970+
// English defaults are enough to trip it under the test text system
971+
// ("Forward (Button 5)" measures a 206px row over a 156px card). Pinned
972+
// to English under the lock: another test in this binary leaves the
973+
// process locale at zh-CN, whose labels are short enough to fit and
974+
// would have made this a false pass.
975+
let _locale = LOCALE_LOCK.lock().unwrap();
976+
rust_i18n::set_locale("en");
977+
cx.update(gpui_component::init);
978+
install_app_state(cx);
979+
let (view, cx) = cx.add_window_view(MouseModelView::new);
980+
// Wide enough for labels on both sides (`model_layout` hides them under 960).
981+
cx.simulate_resize(size(px(1200.), px(800.)));
982+
cx.update(|window, cx| window.draw(cx).clear(cx));
983+
984+
// Selectors are `label-card-{MouseControlId:?}` / `label-value-row-{MouseControlId:?}`.
985+
for (card_selector, row_selector) in [
986+
(
987+
"label-card-Button(Forward)",
988+
"label-value-row-Button(Forward)",
989+
),
990+
(
991+
"label-card-Button(MiddleClick)",
992+
"label-value-row-Button(MiddleClick)",
993+
),
994+
] {
995+
let card = cx
996+
.debug_bounds(card_selector)
997+
.expect("the synthetic model renders a label card for this control");
998+
let row = cx
999+
.debug_bounds(row_selector)
1000+
.expect("the label card renders its value row");
1001+
assert!(
1002+
card.contains(&row.origin) && card.contains(&row.bottom_right()),
1003+
"{row_selector}: value row {row:?} must sit inside its card {card:?}"
1004+
);
1005+
}
1006+
1007+
drop(view);
1008+
cx.update(|window, _| window.remove_window());
1009+
cx.run_until_parked();
1010+
}
1011+
9581012
#[gpui::test]
9591013
fn a_selected_gesture_can_render_in_the_binding_inspector(cx: &mut TestAppContext) {
9601014
cx.update(gpui_component::init);

0 commit comments

Comments
 (0)