//! Finding a word on a visual scene through the app's public finder: the //! hotspot is found with its words, the way presses it, and a message's word //! on the scene is its hotspot (aac-web finder.rs, aac-core scene.rs). use aac_core::finder::{Finder, Place, Reach, Step}; use aac_core::{scene, BoardType, CellAction, CellContent, GridLayout}; use aac_web::finder::{message_items, spots_in}; #[test] fn the_way_to_a_word_on_a_scene_presses_its_hotspot() { let mut home = aac_core::Board::new("Home", BoardType::Grid, GridLayout::new(2, 2)); let mut park = scene::new_scene("Park", "data:image/png;base64,AAAA", 1200, 800, &scene::starter_words(Some(home.id))); let swing = scene::place_hotspot( &mut park, &scene::Hotspot::from_outline(&[(0.1, 0.2), (0.3, 0.2), (0.35, 0.6), (0.05, 0.6)]).unwrap(), scene::hotspot_cell("swing", CellAction::Speak("swing".into())), ) .unwrap(); home.add_cell(0, 0, CellContent::Text("Park".into()), CellAction::Navigate(park.id)); let (home_id, park_id) = (home.id, park.id); let boards: std::collections::HashMap<_, _> = [(home_id, home), (park_id, park)].into_iter().collect(); let finder = Finder::new(spots_in(&boards, "en-US")); let found = finder.find("swing", &[home_id], Reach::default()); let way = found[0].way.as_ref().expect("a way from Home"); assert_eq!(way.len(), 2); assert!(matches!(&way.presses[1].what, Step::Place(Place::Cell { id, .. }) if *id == swing)); let items = message_items(&finder, &[("swing".to_string(), None)], &[home_id, park_id], Reach::default(), |_| false, None); assert!(matches!(items[0].target.as_ref().map(|t| &t.place), Some(Place::Cell { id, .. }) if *id == swing)); }