use aura_ui::core::Action;
use aura_ui::prelude::*;
use aura_ui::view::key_context::KeyContext;
use aura_ui::view::keymap::KeymapMatch;
fn resolve(keystroke: &str, context: &str) -> KeymapMatch {
let window = Window::new(Theme::dark(), Size::new(px(400.0), px(300.0)), 1.0);
window.keymap.resolve(&[keystroke.to_owned()], &[KeyContext::parse(context)])
}
#[test]
fn los_atajos_de_los_widgets_vienen_puestos() {
assert_eq!(resolve("backspace", "TextInput"), KeymapMatch::Action(Action("input::Backspace")));
assert_eq!(resolve("mod-a", "TextInput"), KeymapMatch::Action(Action("input::SelectAll")));
assert_eq!(resolve("down", "Picker"), KeymapMatch::Action(Action("picker::SelectNext")));
assert_eq!(resolve("escape", "ContextMenu"), KeymapMatch::Action(Action("menu::Cancel")));
assert_eq!(resolve("enter", "TextInput"), KeymapMatch::Action(Action("input::Submit")));
let window = Window::new(Theme::dark(), Size::new(px(400.0), px(300.0)), 1.0);
assert_eq!(
window.keymap.resolve(&["enter".into()], &[KeyContext::parse("Picker"), KeyContext::parse("TextInput")]),
KeymapMatch::Action(Action("picker::Confirm")),
);
}
#[test]
fn una_ventana_existente_monta_closure_y_conserva_el_estado_entre_frames() {
let mut window = Window::new(Theme::dark(), Size::new(px(400.0), px(300.0)), 1.0);
let initializations = std::rc::Rc::new(std::cell::Cell::new(0));
let count = initializations.clone();
window.set_ui("Aura closure integration test", move |ui| {
let count = count.clone();
let state = ui.state_with("initialization", move || {
count.set(count.get() + 1);
7
});
ui.page().child(format!("{}", state.get()))
});
window.draw(None);
window.draw(None);
assert_eq!(initializations.get(), 1);
assert!(!window.scene().quads.is_empty());
}
struct Ancha;
impl Component for Ancha {
fn view(&mut self, _: &mut ViewContext<Self>) -> impl IntoElement {
div().h(px(50.0)).bg(Token::Accent)
}
}
#[test]
fn la_vista_raiz_ocupa_el_ancho_sin_w_full() {
let mut window = Window::new(Theme::dark(), Size::new(px(400.0), px(300.0)), 1.0);
window.set_root(Ancha);
window.draw(None);
let quad = window.scene().quads.last().expect("la vista pinta su fondo");
assert_eq!(quad.bounds, [0.0, 0.0, 400.0, 50.0]);
}
struct Centrada;
impl Component for Centrada {
fn view(&mut self, _: &mut ViewContext<Self>) -> impl IntoElement {
div().page().center().child(div().size(px(20.0)).bg(Token::Accent))
}
}
#[test]
fn page_y_center_centran_en_la_ventana() {
let mut window = Window::new(Theme::dark(), Size::new(px(400.0), px(300.0)), 1.0);
window.set_root(Centrada);
window.draw(None);
let quad = window.scene().quads.last().expect("el hijo pinta su fondo");
assert_eq!(quad.bounds, [190.0, 140.0, 20.0, 20.0]);
}