use super::super::tick;
use super::asking;
use crate::test_support::Scratch;
use crate::test_support::wire::{entry, wired};
use crate::ui::{Aim, Channel, Chunk, Model};
use crate::verbs::Where;
use serde_json::{Value, json};
fn aimed_at_an_entry() -> Model {
let held = Channel {
name: "b".to_owned(),
named_there: Some("b".to_owned()),
dials: None,
};
Model {
roster: vec![Chunk::of(held.clone())],
aim: Some(Aim {
channel: held.name,
address: "b".to_owned(),
}),
..Model::default()
}
}
fn asked(engine: &crate::test_support::engine::Engine) -> Vec<String> {
engine
.heard()
.iter()
.filter_map(|said| said.get("op").and_then(Value::as_str))
.map(str::to_owned)
.collect()
}
#[test]
fn the_listing_stands_on_the_pane_and_the_file_read_on_the_destination() {
let scratch = Scratch::new();
let engine = wired(
&scratch,
&entry("b"),
vec![
vec![json!({"ok": true, "kind": "workspaces", "rows": []})],
vec![json!({"ok": true, "kind": "conversations", "rows": []})],
vec![json!({"ok": true, "kind": "workspaces", "rows": []})],
vec![json!({"ok": true, "kind": "conversations", "rows": []})],
vec![json!({"ok": true, "kind": "lineages", "rows": []})],
vec![json!({"ok": true, "kind": "workspaces", "rows": []})],
vec![json!({"ok": true, "kind": "conversations", "rows": []})],
vec![json!({"ok": true, "kind": "lineages", "rows": []})],
vec![json!({"ok": true, "kind": "config", "text": "x", "settings": []})],
],
);
let mut model = aimed_at_an_entry();
let link = asking(&model);
tick(&link, scratch.path());
model.begin_configuring();
link.settle(&mut model);
tick(&link, scratch.path());
assert_eq!(
asked(&engine),
vec![
"workspaces",
"conversations",
"workspaces",
"conversations",
"lineages"
],
"the listing stands on the pane, and no file has been picked"
);
model.read_config(&Where::Brazen {
workspace: "b".to_owned(),
});
link.settle(&mut model);
tick(&link, scratch.path());
assert_eq!(asked(&engine).last().map(String::as_str), Some("config"));
link.settle(&mut model);
assert_eq!(
model.config.map(|held| held.text),
Some("x".to_owned()),
"the answer is filed"
);
assert_eq!(model.lineages, Some(Vec::new()));
}
#[test]
fn a_destination_naming_no_workspace_is_asked_down_the_aimed_channel() {
let scratch = Scratch::new();
let engine = wired(
&scratch,
&entry("b"),
vec![
vec![json!({"ok": true, "kind": "workspaces", "rows": []})],
vec![json!({"ok": true, "kind": "conversations", "rows": []})],
vec![json!({"ok": true, "kind": "lineages", "rows": []})],
vec![json!({"ok": true, "kind": "config", "text": "cadence:\n", "settings": []})],
],
);
let mut model = aimed_at_an_entry();
model.begin_configuring();
model.read_config(&Where::Cadence);
let link = asking(&model);
tick(&link, scratch.path());
assert_eq!(
asked(&engine),
vec!["workspaces", "conversations", "lineages", "config"],
"the engine the window is aimed at answered it"
);
link.settle(&mut model);
assert_eq!(
model.config.map(|held| held.text),
Some("cadence:\n".to_owned())
);
assert_eq!(
model.notice, None,
"and nothing fell through to a flat root"
);
}