Library: remove selected cards from the library
The bulk bar gets a Remove from library button that removes every copy of the selected cards. Decks keep them. Undo puts back the counts, locations and printing groups.
This commit is contained in:
@@ -522,4 +522,38 @@ mod tests {
|
||||
// Card not in the deck.
|
||||
assert!(cat.set_deck_card_printing(d.id, "lightning-bolt", Some("print-lightning-bolt")).is_err());
|
||||
}
|
||||
|
||||
/// What the Library tab's "Remove from library" and its undo rely on.
|
||||
#[test]
|
||||
fn removing_a_card_keeps_its_decks_and_can_be_put_back() {
|
||||
let fx = test_support::make();
|
||||
let cat = &fx.catalog;
|
||||
add_sol_ring_printings(cat);
|
||||
let groups = |cat: &Catalog| -> Vec<(String, String, i64)> {
|
||||
let copies = cat.list_library_copies("sol-ring").unwrap();
|
||||
copies.into_iter().map(|c| (c.scryfall_id, c.finish, c.quantity)).collect()
|
||||
};
|
||||
cat.set_owned("sol-ring", 5).unwrap();
|
||||
cat.set_location("sol-ring", "Binder 2").unwrap();
|
||||
cat.set_library_copy("sol-ring", "sol-2x2", "foil", 1).unwrap();
|
||||
cat.set_library_copy("sol-ring", "sol-c21", "nonfoil", 2).unwrap();
|
||||
let d = cat.create_deck("Rocks", None).unwrap();
|
||||
cat.set_deck_card(d.id, "sol-ring", 1, false, false).unwrap();
|
||||
let before = groups(cat);
|
||||
|
||||
cat.set_owned("sol-ring", 0).unwrap();
|
||||
assert!(groups(cat).is_empty(), "going to 0 drops the groups");
|
||||
assert!(cat.list_library().unwrap().iter().all(|c| c.card.oracle_id != "sol-ring"));
|
||||
assert_eq!(cat.deck_contents(d.id).unwrap().len(), 1, "the deck keeps it");
|
||||
|
||||
cat.set_owned("sol-ring", 5).unwrap();
|
||||
cat.set_location("sol-ring", "Binder 2").unwrap();
|
||||
for (scryfall_id, finish, quantity) in &before {
|
||||
cat.set_library_copy("sol-ring", scryfall_id, finish, *quantity).unwrap();
|
||||
}
|
||||
assert_eq!(groups(cat), before);
|
||||
let card = cat.list_library().unwrap().into_iter().find(|c| c.card.oracle_id == "sol-ring").unwrap();
|
||||
assert_eq!(card.quantity_owned, 5);
|
||||
assert_eq!(card.location, "Binder 2");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user