Add test for StackView::move_layer

From #213 (thanks xliiv)
This commit is contained in:
Alexandre Bury 2018-03-05 18:47:25 -08:00
parent 48514991d2
commit 5e58726ffd

View File

@ -470,3 +470,26 @@ impl View for StackView {
Err(())
}
}
#[cfg(test)]
mod tests {
use super::*;
use views::TextView;
#[test]
fn move_layer_works() {
let mut stack = StackView::new()
.layer(TextView::new("1"))
.layer(TextView::new("2"))
.layer(TextView::new("3"));
stack.move_layer(LayerPosition::FromFront(0), LayerPosition::FromBack(0));
stack.move_layer(LayerPosition::FromBack(0), LayerPosition::FromFront(0));
stack.move_layer(LayerPosition::FromFront(1), LayerPosition::FromFront(0));
let layer = stack.pop_layer().unwrap();
let box_view = layer.as_any().downcast_ref::<Box<AnyView>>().unwrap();
let text_view = (**box_view).as_any().downcast_ref::<TextView>().unwrap();
assert_eq!(text_view.get_content().source(), "2");
}
}