pointer: tests for the cases the mutants found open; a Select or TextInput press has one arm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
f86fd23d99
commit
8784e529a2
3 changed files with 136 additions and 4 deletions
|
|
@ -112,8 +112,6 @@ impl Input {
|
|||
owners.drafts.set(surface, &hit.node, InputValue::Number(NumberValue { value }));
|
||||
Some(Press::Drag { node: hit.node, prior })
|
||||
}
|
||||
// A press on a Select or a TextInput does nothing yet: the chooser and text editing are not here.
|
||||
(Control::Select | Control::TextInput, _) => None,
|
||||
_ => Some(Press::Target(hit)),
|
||||
});
|
||||
}
|
||||
|
|
@ -146,6 +144,8 @@ impl Input {
|
|||
let checked = matches!(shown.as_deref(), Some(Bound::Bool(true)));
|
||||
Activation { node: pressed.node, kind: ActivationKind::Change(InputValue::Bool(BoolValue { value: !checked })) }
|
||||
}
|
||||
// A Select's chooser and a TextInput's editing are not here: a press on them does nothing, and
|
||||
// does not fall through to a control around them. A Slider's press is a `Drag`, never a target.
|
||||
Control::Slider | Control::Select | Control::TextInput => return Vec::new(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -140,11 +140,20 @@ fn clip_surface() -> SurfaceDocument {
|
|||
)
|
||||
}
|
||||
|
||||
/// A root with a 16px left margin, so no control's rect starts where the root's does.
|
||||
fn indented(id: &str, children: Vec<Node>) -> Node {
|
||||
let mut root = column(id, None, Overflow::Visible, children);
|
||||
if let Node::Box(b) = &mut root {
|
||||
b.style.padding.left = px(16.0);
|
||||
}
|
||||
root
|
||||
}
|
||||
|
||||
fn controls_surface() -> SurfaceDocument {
|
||||
let slider = Node::Slider(SliderNode { common: common("level"), min: 0.0, max: 100.0, step: 10.0, value: lit_number(0.0), commit: command("set") });
|
||||
let toggle = Node::Toggle(ToggleNode { common: common("flag"), checked: lit_bool(false), on_change: command("flip") });
|
||||
surface(
|
||||
column("root", None, Overflow::Visible, vec![button("a", "go", 160.0, 48.0), button("b", "go", 160.0, 48.0), toggle, slider]),
|
||||
indented("root", vec![button("a", "go", 160.0, 48.0), button("b", "go", 160.0, 48.0), toggle, slider]),
|
||||
vec![decl("go", &[]), decl("flip", &["flag"]), decl("set", &["level"])],
|
||||
)
|
||||
}
|
||||
|
|
@ -323,6 +332,8 @@ fn a_rect_is_half_open_so_a_shared_edge_belongs_to_the_second_node() {
|
|||
assert!(target(&rig.rendered, &rig.laid, &index_of(&rig), edge).is_some_and(|hit| hit.node.as_str() == "b"), "{mode:?}");
|
||||
let last = (a.x + 0.5, b.y - 0.25);
|
||||
assert!(target(&rig.rendered, &rig.laid, &index_of(&rig), last).is_some_and(|hit| hit.node.as_str() == "a"), "{mode:?}");
|
||||
let under = (b.x + 0.5, b.y + b.h);
|
||||
assert_eq!(target(&rig.rendered, &rig.laid, &index_of(&rig), under), None, "{mode:?}: the bottom edge is outside");
|
||||
let beyond = (a.x + a.w, a.y + 0.5);
|
||||
assert_ne!(target(&rig.rendered, &rig.laid, &index_of(&rig), beyond).map(|hit| hit.node), Some(nid("a")), "{mode:?}: the right edge is outside");
|
||||
}
|
||||
|
|
@ -746,3 +757,121 @@ fn input_other_than_the_pointer_changes_nothing() {
|
|||
}
|
||||
assert_eq!((rig.minted(), rig.drafts.len()), (vec![], before.1));
|
||||
}
|
||||
|
||||
// ----- the cases the mutants found open -----
|
||||
|
||||
fn lone_slider(min: f64, max: f64, step: f64) -> SurfaceDocument {
|
||||
let slider = Node::Slider(SliderNode { common: common("level"), min, max, step, value: lit_number(min), commit: command("set") });
|
||||
surface(indented("root", vec![slider]), vec![decl("set", &["level"])])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_slider_snaps_from_its_own_minimum_and_follows_its_own_track() {
|
||||
for mode in MODES {
|
||||
let mut rig = Rig::new(MemState::new(), &lone_slider(20.0, 120.0, 10.0), mode);
|
||||
let track = rig.rect("level");
|
||||
assert!(track.x > 0.0, "{mode:?}: the track does not start at the root's edge");
|
||||
let along = |fraction: f32| (track.x + fraction * track.w, track.y + 0.5);
|
||||
let value = |v: f64| Some(InputValue::Number(NumberValue { value: v }));
|
||||
rig.send(down(along(0.0)));
|
||||
assert_eq!(rig.draft("level"), value(20.0), "{mode:?}: the track's left edge is the minimum");
|
||||
rig.send(mv(along(0.47)));
|
||||
assert_eq!(rig.draft("level"), value(70.0), "{mode:?}: 20 + 47 = 67 snaps to 70 from 20");
|
||||
rig.send(mv(along(1.0)));
|
||||
assert_eq!(rig.draft("level"), value(120.0), "{mode:?}");
|
||||
// A move that is not a position is not a value.
|
||||
rig.send(mv((f32::NAN, track.y)));
|
||||
assert_eq!(rig.draft("level"), value(120.0), "{mode:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_slider_with_no_range_or_a_step_of_zero_is_handled_by_what_it_declares() {
|
||||
for mode in MODES {
|
||||
for (min, max) in [(5.0, 5.0), (0.0, f64::INFINITY), (9.0, 3.0)] {
|
||||
let mut rig = Rig::new(MemState::new(), &lone_slider(min, max, 1.0), mode);
|
||||
let at = inside(rig.rect("level"));
|
||||
rig.click(at);
|
||||
assert_eq!((rig.draft("level"), rig.minted()), (None, vec![]), "{mode:?} {min}..{max}");
|
||||
}
|
||||
// No step: the raw position, unsnapped.
|
||||
let mut rig = Rig::new(MemState::new(), &lone_slider(0.0, 100.0, 0.0), mode);
|
||||
let track = rig.rect("level");
|
||||
rig.send(down((track.x + 0.25 * track.w, track.y + 0.5)));
|
||||
assert_eq!(rig.draft("level"), Some(InputValue::Number(NumberValue { value: 25.0 })), "{mode:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_press_on_a_text_input_or_a_select_does_not_fall_through_to_the_button_around_it() {
|
||||
let input = Node::TextInput(TextInputNode {
|
||||
common: common("field"),
|
||||
multiline: false,
|
||||
input_kind: InputKind::Text,
|
||||
placeholder: lit_text(""),
|
||||
initial: lit_text("x"),
|
||||
submit: command("go"),
|
||||
});
|
||||
let select = Node::Select(SelectNode {
|
||||
common: common("choice"),
|
||||
options: OptionList::Literal(LiteralOptions { options: vec![SelectOption { value: "a".into(), label: "A".into() }] }),
|
||||
value: record_bind(path(&["Theme"]), None),
|
||||
on_change: command("go"),
|
||||
});
|
||||
let card = Node::Button(ButtonNode {
|
||||
common: common("card"),
|
||||
content: vec![fixed("pad", 160.0, 16.0), input, select],
|
||||
on_activate: command("go"),
|
||||
enabled: lit_bool(true),
|
||||
});
|
||||
for mode in MODES {
|
||||
let document = surface(column("root", None, Overflow::Visible, vec![card.clone()]), vec![decl("go", &[])]);
|
||||
let mut rig = Rig::new(MemState::new(), &document, mode);
|
||||
for id in ["field", "choice"] {
|
||||
let r = rig.rect(id);
|
||||
assert!(r.w >= 1.0 && r.h >= 1.0, "{mode:?} {id}");
|
||||
assert_eq!(rig.click(inside(r)), vec![], "{mode:?} {id}");
|
||||
}
|
||||
assert_eq!(rig.minted(), vec![], "{mode:?}: the card around them was not pressed");
|
||||
// The card itself still is.
|
||||
rig.click(inside(rig.rect("pad")));
|
||||
assert_eq!(commands_of(&rig.minted()), ["go"], "{mode:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wheel_that_is_not_a_number_or_runs_on_a_bad_scale_is_ignored_or_taken_at_one() {
|
||||
let mut rig = Rig::new(MemState::new(), &nested_surface(), (Metrics::Pixels, 1.5));
|
||||
let over = inside(rig.rect("inner"));
|
||||
// The scale the host gave is not usable: the offset is the wheel's units as they are.
|
||||
for bad in [0.0, f32::INFINITY, f32::NAN, -2.0] {
|
||||
rig.scroll = ScrollOffsets::default();
|
||||
rig.scale = bad;
|
||||
rig.send(wheel(over, (0.0, 10.0), WheelUnit::Units));
|
||||
assert_eq!(rig.offset("inner"), Some((0.0, 10.0)), "scale {bad}");
|
||||
}
|
||||
// A delta that is not a number moves nothing, and does not reset what is scrolled.
|
||||
rig.scale = 1.5;
|
||||
rig.scroll.set(nid("inner"), (0.0, 30.0));
|
||||
for bad in [f32::NAN, f32::INFINITY] {
|
||||
rig.send(wheel(over, (0.0, bad), WheelUnit::Units));
|
||||
rig.send(wheel(over, (bad, 0.0), WheelUnit::Units));
|
||||
assert_eq!(rig.offset("inner"), Some((0.0, 30.0)), "delta {bad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_wheel_scrolls_the_horizontal_axis_by_its_own_delta() {
|
||||
let pane = column("pane", Some((160.0, 80.0)), Overflow::Scroll, vec![fixed("wide", 400.0, 400.0)]);
|
||||
let document = surface(column("root", None, Overflow::Visible, vec![pane]), vec![]);
|
||||
for mode in MODES {
|
||||
let mut rig = Rig::new(MemState::new(), &document, mode);
|
||||
let k = if mode.0 == Metrics::Pixels { mode.1 } else { 1.0 };
|
||||
let over = inside(rig.rect("pane"));
|
||||
assert!(rig.max_scroll("pane").0 > 0.0 && rig.max_scroll("pane").1 > 0.0, "{mode:?}");
|
||||
rig.send(wheel(over, (16.0, 8.0), WheelUnit::Units));
|
||||
assert_eq!(rig.offset("pane"), Some((16.0 * k, 8.0 * k)), "{mode:?}");
|
||||
rig.send(wheel(over, (-4.0, 0.0), WheelUnit::Units));
|
||||
assert_eq!(rig.offset("pane"), Some((12.0 * k, 8.0 * k)), "{mode:?}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1452,9 +1452,12 @@ fn drafts_draw_over_the_bound_values_of_a_form() {
|
|||
drafts.set(&surface, &nid("enabled"), InputValue::Bool(BoolValue { value: false }));
|
||||
drafts.set(&surface, &nid("volume"), InputValue::Number(NumberValue { value: min + (max - min) * 0.25 }));
|
||||
drafts.set(&surface, &nid("theme"), InputValue::Choice(ChoiceValue { value: chosen }));
|
||||
drafts.set(&surface, &nid("port"), InputValue::Text(TextValue { value: "9999".into() }));
|
||||
drafts.set(&surface, &nid("port"), InputValue::Number(NumberValue { value: 9999.0 }));
|
||||
let (text, drawn) = session_text(Fixture::F04Form, &drafts, &NodeStates::default());
|
||||
golden::check(&golden_dir(), "render-f04-form-session.txt", text.as_bytes());
|
||||
// A number input's draft is its number or the text typed: both are drawn as the text they are.
|
||||
drafts.set(&surface, &nid("port"), InputValue::Text(TextValue { value: "9999".into() }));
|
||||
assert_eq!(session_text(Fixture::F04Form, &drafts, &NodeStates::default()).1.commands, drawn.commands);
|
||||
let (_, plain) = session_text(Fixture::F04Form, &Drafts::new(), &NodeStates::default());
|
||||
assert_ne!(drawn.commands, plain.commands);
|
||||
assert_eq!(plain.commands, fixture_runs(Fixture::F04Form, &pixels(1.0), &ScrollOffsets::default())[0].1.as_ref().unwrap().commands, "no drafts, no states: the bound frame");
|
||||
|
|
|
|||
Loading…
Reference in a new issue