Add tests for the list model
This commit is contained in:
parent
3251d098bd
commit
889351df24
|
@ -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#"<p>This is a test list</p>
|
||||
<ul>
|
||||
<li>One</li>
|
||||
<li>Two</li>
|
||||
<li>Three</li>
|
||||
</ul>
|
||||
"#);
|
||||
}
|
||||
|
||||
#[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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue