use super::super::*;
impl App {
pub(super) fn cycle_setting(&mut self) -> Effect {
if self.authorize_write().is_none() {
return Effect::None;
}
let Some(cursor) = self.settings().and_then(Settings::cursor) else {
return Effect::None;
};
match cursor {
SettingsRow::Scalar(field) => self.cycle_scalar(field),
SettingsRow::Dog(index) => self.cycle_dog(index),
}
}
fn cycle_scalar(&mut self, field: SettingField) -> Effect {
let Some(settings) = (match &mut self.body {
Body::Settings(settings) => Some(settings),
Body::FlockTable
| Body::ConfigPane(_)
| Body::Bleats(_)
| Body::Secrets(_)
| Body::Sheep(_) => None,
}) else {
return Effect::None;
};
let Some(value) = settings.next_candidate(field) else {
return Effect::None;
};
let source = settings.source_of(field);
let text = confirm_text(field, &value, source);
settings.pending = Some(Pending::Armed {
edit: SettingEdit::Set { field, value },
text,
at: self.now,
});
Effect::None
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::lookout::view::fixtures;
#[test]
fn space_advances_the_candidate_rather_than_needing_a_cancel() {
let mut app = fixtures::app_in_settings_with_control();
let _ = app.update(Msg::Key(KeyPress::Cycle));
let first = app.settings().unwrap().pending().unwrap().text.to_string();
let _ = app.update(Msg::Key(KeyPress::Cycle));
let second = app.settings().unwrap().pending().unwrap().text.to_string();
assert_ne!(first, second);
}
#[test]
fn the_style_cycle_starts_from_the_file_and_not_the_level_in_force() {
let mut app = fixtures::app_in_settings_with_shadowed_style(StyleSource::Env);
let _ = app.update(Msg::Key(KeyPress::Cycle));
let text = app.settings().unwrap().pending().unwrap().text.to_string();
assert!(
text.contains("set style level to plain"),
"the file says full, so one step is plain: {text}"
);
}
}