mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Return menu lookup failures from the Align label test
This commit is contained in:
1 parent
bef7a05f47
commit
71894a969a
1 file changed
+18
-14
@@ -22,41 +22,45 @@ const ALIGN_COMMANDS: [&str; 7] = [
|
||||
"layer.align.rightEdges",
|
||||
];
|
||||
|
||||
fn align_rows<'a>(bar: &'a MenuBar, title: &str) -> Vec<(&'a str, bool)> {
|
||||
let layer = bar.menus.iter().find(|menu| menu.title == "Layer").expect("Layer menu");
|
||||
let children = layer.children.iter().find_map(|node| match node {
|
||||
Node::Submenu { label, children, .. } if label == title => Some(children),
|
||||
_ => None,
|
||||
});
|
||||
fn align_rows<'a>(bar: &'a MenuBar, title: &str) -> Result<Vec<(&'a str, bool)>, String> {
|
||||
let layer = bar.menus.iter().find(|menu| menu.title == "Layer").ok_or("Layer menu missing")?;
|
||||
let children = layer
|
||||
.children
|
||||
.iter()
|
||||
.find_map(|node| match node {
|
||||
Node::Submenu { label, children, .. } if label == title => Some(children),
|
||||
_ => None,
|
||||
})
|
||||
.ok_or_else(|| format!("{title} submenu missing"))?;
|
||||
children
|
||||
.expect(title)
|
||||
.iter()
|
||||
.map(|node| match node {
|
||||
Node::Item(item) => (item.command.id.as_str(), item.enabled),
|
||||
Node::Separator => ("---", false),
|
||||
_ => panic!("unexpected row in {title}: {node:?}"),
|
||||
Node::Item(item) => Ok((item.command.id.as_str(), item.enabled)),
|
||||
Node::Separator => Ok(("---", false)),
|
||||
_ => Err(format!("unexpected row in {title}: {node:?}")),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_title_changes_without_changing_the_alignment_commands() {
|
||||
fn the_title_changes_without_changing_the_alignment_commands() -> Result<(), String> {
|
||||
let mut app = PhotocraftApp::new(Session::new(), Default::default());
|
||||
let bar = fresh_bar(&app);
|
||||
let rows = align_rows(&bar, "Align");
|
||||
let rows = align_rows(&bar, "Align")?;
|
||||
assert_eq!(rows.iter().map(|(id, _)| *id).collect::<Vec<_>>(), ALIGN_COMMANDS);
|
||||
assert!(rows.iter().all(|(_, enabled)| !enabled), "no document: all commands are greyed");
|
||||
|
||||
app.run("file.new", json!({"width": 64, "height": 48})).unwrap();
|
||||
app.run("select.rect", json!({"x": 4, "y": 4, "width": 20, "height": 16})).unwrap();
|
||||
let bar = fresh_bar(&app);
|
||||
let rows = align_rows(&bar, "Align Layers to Selection");
|
||||
let rows = align_rows(&bar, "Align Layers to Selection")?;
|
||||
assert_eq!(rows.iter().map(|(id, _)| *id).collect::<Vec<_>>(), ALIGN_COMMANDS);
|
||||
assert!(rows.iter().filter(|(id, _)| *id != "---").all(|(_, enabled)| *enabled));
|
||||
|
||||
app.run("select.deselect", json!({})).unwrap();
|
||||
let bar = fresh_bar(&app);
|
||||
assert_eq!(align_rows(&bar, "Align").iter().map(|(id, _)| *id).collect::<Vec<_>>(), ALIGN_COMMANDS);
|
||||
assert_eq!(align_rows(&bar, "Align")?.iter().map(|(id, _)| *id).collect::<Vec<_>>(), ALIGN_COMMANDS);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
type AppHarness = Harness<'static, Box<PhotocraftApp>>;
|
||||
|
||||
Reference in new issue
Block a user