use shep_core::protocol::Response;
use crate::lookout::app::{App, Control, KeyPress, Msg, Sent};
use super::flock::{app_with, flock_of};
use super::palette::plain;
use super::settings::settings_snapshot;
use super::sheep_pane::select_field;
pub fn dog_section() -> String {
"# how often\npoll = \"60s\"\nhistory_bytes = 4096\n\n[sinks.ops]\nkind = \"slack\"\nurl = \"https://hooks.example/x\"\n"
.to_string()
}
pub fn app_in_dog_pane() -> App {
let mut app = app_with(flock_of(3, 0), plain());
app.set_control_for_tests(Control::Allowed);
app.update(Msg::Key(KeyPress::Settings));
app.update(Msg::Settings {
result: Ok(settings_snapshot()),
});
for _ in 0..6 {
app.update(Msg::Key(KeyPress::SelectDown));
}
app.update(Msg::Key(KeyPress::Edit));
app.update(Msg::DogPane {
name: "bark".to_string(),
adopted_path: None,
result: Ok(crate::dog::builtin_schema("bark").expect("bark is a built-in")),
});
app.update(Msg::Replied {
sent: Sent::DogSection {
name: "bark".to_string(),
},
result: Ok(Response::DogSection {
toml: dog_section().into(),
}),
});
app
}
pub fn app_in_dog_pane_with_two_edits() -> App {
let mut app = app_in_dog_pane();
for (key, typed) in [("poll", "45s"), ("history_bytes", "8192")] {
select_field(&mut app, key);
app.update(Msg::Key(KeyPress::Confirm));
for _ in 0..64 {
app.update(Msg::Key(KeyPress::TextBackspace));
}
for character in typed.chars() {
app.update(Msg::Key(KeyPress::TextChar(character)));
}
app.update(Msg::Key(KeyPress::TextApply));
}
assert_eq!(
app.config_pane().expect("the pane is open").edits().len(),
2,
"the fixture files two edits"
);
app
}