diff --git a/src/models/list.rs b/src/models/list.rs index fc05efa..74ae8b6 100644 --- a/src/models/list.rs +++ b/src/models/list.rs @@ -82,3 +82,54 @@ impl List { lists } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn loads_all_lists() { + let lists = List::load_all(Some("test")); + let list_ids: Vec<&str> = lists.iter() + .map(|list| list.id.as_ref()).collect(); + assert_eq!(list_ids, vec!["test", "updatable"]); + } + + #[test] + fn converts_to_html() { + let lists = List::load_all(Some("test")); + let list = lists.iter() + .find(|list| list.id == "test") + .unwrap(); + assert_eq!(list.to_html(), r#"

This is a test list

+ +"#); + } + + #[test] + fn updates_data() { + let mut lists = List::load_all(Some("test")); + let list = lists.iter_mut() + .find(|list| list.id == "updatable") + .unwrap(); + + let new_data = match list.data.as_ref() { + "contentA" => "contentB", + _ => "contentA" + }; + list.update_data(&String::from(new_data)); + assert_eq!(list.data, new_data); + + // Verify that the data is written to the file of the list by + // loading them again + let lists = List::load_all(Some("test")); + let list = lists.iter() + .find(|list| list.id == "updatable") + .unwrap(); + assert_eq!(list.data, new_data); + } +}