From ab3994954e0c118491a892f024c8e5a287c722c6 Mon Sep 17 00:00:00 2001 From: bflatastic Date: Sat, 21 Nov 2026 21:27:44 +0700 Subject: [PATCH] document-panels-w6: net change of 1 commits - document-panels-w6: written from its sheet --- crates/ui-panels/tests/it/rails/locate.rs | 50 +++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 crates/ui-panels/tests/it/rails/locate.rs diff --git a/crates/ui-panels/tests/it/rails/locate.rs b/crates/ui-panels/tests/it/rails/locate.rs new file mode 100644 index 000000000..308366de9 --- /dev/null +++ b/crates/ui-panels/tests/it/rails/locate.rs @@ -0,0 +1,50 @@ +//! Locating a tool on the rail: `reveal` opens the flyout of a slot that hides the tool, `mark` dresses it, and +//! neither chooses it. + +use super::{CUT, REDO, UNDO, tools}; +use craft_ui::contract::{Role, Show as _}; +use craft_ui::display::TargetMark; +use craft_ui::rails::{LastUsed, SlotId, ToolRail, ToolSlot}; +use craft_ui::testing::{Fixture, trial}; +use std::cell::{Cell, RefCell}; +use std::rc::Rc; + +struct Rig { + fixture: Fixture, + selected: Rc>>, + flyout: Rc>>, +} + +/// One slot of three tools that shows Undo, with `reveal` and `mark` passed in every pass. +fn rig(reveal: Option, mark: Option) -> Rig { + let selected = Rc::new(RefCell::new(Vec::new())); + let flyout = Rc::new(Cell::new(None)); + let (seen, opened) = (selected.clone(), flyout.clone()); + let mut fixture = Fixture::new(move |ui| { + let slots = [ToolSlot::new(0, tools(&[UNDO, REDO, CUT]))]; + let last = LastUsed::default(); + let current = UNDO; + let out = ToolRail::new("Tools", &slots, ¤t, &last).reveal(reveal.as_ref()).mark(mark.as_ref()).show_rail(ui, |_, _| {}); + if let Some(tool) = out.select { + seen.borrow_mut().push(tool); + } + opened.set(out.flyout); + }); + fixture.settle(); + Rig { fixture, selected, flyout } +} + +#[trial] +fn a_revealed_tool_opens_its_group_and_wears_the_mark_without_being_chosen() { + let hidden = rig(Some(REDO), Some(REDO)); + assert!(hidden.flyout.get().is_some(), "revealing a tool the slot hides opens the slot's flyout"); + assert!(!hidden.fixture.by_role(Role::MENU).is_empty(), "the flyout shows"); + assert!(!hidden.fixture.styles_of(std::any::type_name::()).is_empty(), "the marked tool wears a mark"); + assert!(hidden.selected.borrow().is_empty(), "revealing and marking choose nothing"); + + let shown = rig(None, Some(UNDO)); + assert!(shown.flyout.get().is_none(), "a mark alone opens no flyout"); + assert!(shown.fixture.by_role(Role::MENU).is_empty(), "no flyout shows"); + assert!(!shown.fixture.styles_of(std::any::type_name::()).is_empty(), "the shown tool's button wears the mark"); + assert!(shown.selected.borrow().is_empty(), "a mark chooses nothing"); +}