Lines
95.24 %
Functions
100 %
Branches
//! The account-create parent select is filled from `form-options`.
use crate::form::Form;
use crate::modal::Modal;
use crate::route::{FormOptionsSource, Route, RouteCtx};
use crate::view::ViewId;
use crate::widgets::{SelectWidget, Widget};
const ROOT: &str = "550e8400-e29b-41d4-a716-446655440001";
fn options_wire() -> String {
format!(r#"(:id 9 :value "((:id \"{ROOT}\" :label \"Assets\" :alias \"x\"))")"#)
}
fn deliver(app: &mut crate::app::App, seq: u64) {
app.deliver_reply(
Route {
target: Some(app.window_of(ViewId::Accounts)),
ctx: RouteCtx::FormOptions {
seq,
source: FormOptionsSource::FormAccounts,
},
&options_wire(),
);
fn parent(app: &crate::app::App) -> Option<&SelectWidget> {
let Some(Modal::Form(form)) = app.overlays.top() else {
return None;
};
match &form.fields.get(1)?.widget {
Widget::Select(select) => Some(select),
_ => None,
fn open_app() -> crate::app::App {
let mut app = crate::test_support::app();
app.overlays.push(Modal::Form(Form::account_create()));
app.form_options_seq.advance();
app
#[test]
fn the_parent_select_gets_none_and_the_accounts() {
let mut app = open_app();
deliver(&mut app, 1);
let select = parent(&app).expect("parent select");
assert_eq!(select.options().len(), 2);
assert_eq!(select.display(), "(none)");
assert_eq!(select.value(), "");
fn a_stale_options_reply_is_dropped() {
assert_eq!(parent(&app).map(|select| select.options().len()), Some(0));