mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
add a unit test for multiple mutations
This commit is contained in:
parent
996d9f9bbc
commit
3adf03f9cb
1 changed files with 21 additions and 5 deletions
|
@ -247,7 +247,7 @@ mod test {
|
||||||
use crate::{collection::open_test_collection, prelude::*};
|
use crate::{collection::open_test_collection, prelude::*};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn undo() {
|
fn undo() -> Result<()> {
|
||||||
let mut col = open_test_collection();
|
let mut col = open_test_collection();
|
||||||
|
|
||||||
let mut card = Card {
|
let mut card = Card {
|
||||||
|
@ -324,10 +324,7 @@ mod test {
|
||||||
card.interval = 5;
|
card.interval = 5;
|
||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.unwrap();
|
})?;
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.unwrap();
|
|
||||||
assert_eq!(col.storage.get_card(cid).unwrap().unwrap().interval, 5);
|
assert_eq!(col.storage.get_card(cid).unwrap().unwrap().interval, 5);
|
||||||
assert_eq!(col.can_undo(), Some(Op::UpdateCard));
|
assert_eq!(col.can_undo(), Some(Op::UpdateCard));
|
||||||
assert_eq!(col.can_redo(), None);
|
assert_eq!(col.can_redo(), None);
|
||||||
|
@ -336,5 +333,24 @@ mod test {
|
||||||
col.transact_no_undo(|_col| Ok(())).unwrap();
|
col.transact_no_undo(|_col| Ok(())).unwrap();
|
||||||
assert_eq!(col.can_undo(), None);
|
assert_eq!(col.can_undo(), None);
|
||||||
assert_eq!(col.can_redo(), None);
|
assert_eq!(col.can_redo(), None);
|
||||||
|
|
||||||
|
// if an object is mutated multiple times in one operation,
|
||||||
|
// the changes should be undone in the correct order
|
||||||
|
col.transact(Op::UpdateCard, |col| {
|
||||||
|
col.get_and_update_card(cid, |card| {
|
||||||
|
card.interval = 10;
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
col.get_and_update_card(cid, |card| {
|
||||||
|
card.interval = 15;
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
})?;
|
||||||
|
|
||||||
|
assert_eq!(col.storage.get_card(cid).unwrap().unwrap().interval, 15);
|
||||||
|
col.undo()?;
|
||||||
|
assert_eq!(col.storage.get_card(cid).unwrap().unwrap().interval, 5);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue