Lines
97.96 %
Functions
100 %
Branches
//! A new row's to-commodity starts empty, meaning the from-commodity.
use super::*;
fn usd_eur() -> Vec<SelectOption> {
[("u-usd", "USD"), ("u-eur", "EUR")]
.map(|(id, label)| SelectOption {
id: id.to_string(),
label: label.to_string(),
})
.to_vec()
}
#[test]
fn a_row_added_after_the_options_arrive_starts_on_same_as_from() {
let mut sw = SplitsWidget::default();
sw.set_commodity_options(usd_eur());
sw.add_row();
let row = &sw.rows()[1];
assert_eq!(row.from_commodity.value(), "");
assert_eq!(row.to_commodity.value(), "");
assert_eq!(row.to_commodity.display(), "same");
fn a_row_present_when_the_options_arrive_starts_on_same_as_from() {
assert!(sw.rows().iter().all(|row| row.to_commodity.value() == ""));
fn a_chosen_to_commodity_survives_a_second_delivery_of_options() {
sw.col_focus = COL_TO_COMM;
if let Some(FocusedSubWidget::Select(select)) = sw.focused_subwidget_mut() {
select.next();
assert_eq!(sw.rows()[0].to_commodity.value(), "u-eur");
fn a_loaded_row_without_a_to_commodity_keeps_it_empty() {
let row =
forms::Row::from([("from-commodity", "USD")].map(|(k, v)| (k.to_string(), v.to_string())));
sw.load_rows(&[row]);
assert_eq!(sw.rows()[0].text("to-commodity"), "");
fn the_conversion_arrow_stays_hidden_while_the_to_commodity_is_empty() {
sw.row_focus = 0;
sw.col_focus = COL_FROM;
let grid = sw.grid(true, None, None);
assert!(
(0..grid.lines.len()).all(|line| crate::test_support::arrows(&grid, line) == 1),
"{grid:?}"
);