audit button
This commit is contained in:
@@ -11,6 +11,7 @@ use gpui_native_theme::Theme;
|
||||
struct Harness {
|
||||
clicks: Rc<RefCell<usize>>,
|
||||
disabled: bool,
|
||||
loading: bool,
|
||||
}
|
||||
|
||||
impl Render for Harness {
|
||||
@@ -20,14 +21,18 @@ impl Render for Harness {
|
||||
Button::new("test-button")
|
||||
.label("Save")
|
||||
.disabled(self.disabled)
|
||||
.loading(self.loading)
|
||||
.on_click(move |_, _, _| *clicks.borrow_mut() += 1),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// A maximized window whose button stretches across the top 28px, so
|
||||
/// A maximized window whose button stretches across the top band, so
|
||||
/// `point(px(60.), px(14.))` always lands on it.
|
||||
fn button_window(disabled: bool) -> (VisualTestContext, AnyWindowHandle, Rc<RefCell<usize>>) {
|
||||
fn button_window(
|
||||
disabled: bool,
|
||||
loading: bool,
|
||||
) -> (VisualTestContext, AnyWindowHandle, Rc<RefCell<usize>>) {
|
||||
let mut cx = TestAppContext::single();
|
||||
cx.update(Theme::init);
|
||||
let clicks = Rc::new(RefCell::new(0));
|
||||
@@ -35,6 +40,7 @@ fn button_window(disabled: bool) -> (VisualTestContext, AnyWindowHandle, Rc<RefC
|
||||
let window = cx.add_window(move |_, _| Harness {
|
||||
clicks: harness_clicks,
|
||||
disabled,
|
||||
loading,
|
||||
});
|
||||
let window = window.into();
|
||||
cx.update_window(window, |_, window, cx| {
|
||||
@@ -53,21 +59,28 @@ fn draw(cx: &mut VisualTestContext, window: AnyWindowHandle) {
|
||||
|
||||
#[test]
|
||||
fn pointer_click_fires_on_click() {
|
||||
let (mut cx, _window, clicks) = button_window(false);
|
||||
let (mut cx, _window, clicks) = button_window(false, false);
|
||||
cx.simulate_click(point(px(60.), px(14.)), Modifiers::default());
|
||||
assert_eq!(*clicks.borrow(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disabled_button_ignores_clicks() {
|
||||
let (mut cx, _window, clicks) = button_window(true);
|
||||
let (mut cx, _window, clicks) = button_window(true, false);
|
||||
cx.simulate_click(point(px(60.), px(14.)), Modifiers::default());
|
||||
assert_eq!(*clicks.borrow(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn loading_button_ignores_clicks() {
|
||||
let (mut cx, _window, clicks) = button_window(false, true);
|
||||
cx.simulate_click(point(px(60.), px(14.)), Modifiers::default());
|
||||
assert_eq!(*clicks.borrow(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enter_and_space_fire_on_click_while_focused() {
|
||||
let (mut cx, window, clicks) = button_window(false);
|
||||
let (mut cx, window, clicks) = button_window(false, false);
|
||||
cx.simulate_click(point(px(60.), px(14.)), Modifiers::default());
|
||||
assert_eq!(*clicks.borrow(), 1, "the pointer click itself activates");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user