Save splashes when loading art is missing and restore art notifications (#83)
This commit was merged in pull request #93.
This commit is contained in:
1 parent
e440d155fc
commit
cee9ff2989
5 files changed
+190
-86
No files matched your search
@@ -391,11 +391,10 @@ fn splash_downloads_resume_after_a_network_error_and_only_fetch_new_champions()
|
||||
let splash_calls = source.splash_calls.clone();
|
||||
let loading_calls = source.card_counter();
|
||||
let tracker = reopen(dir.path(), source);
|
||||
tracker.refresh_champions().unwrap();
|
||||
|
||||
let mut attempts = Vec::new();
|
||||
tracker
|
||||
.refresh_champion_art(&mut |saved| {
|
||||
.refresh_champion_art(|| {}, &mut |saved| {
|
||||
attempts.push(saved);
|
||||
// Three cards, then one splash. The next splash loses the network.
|
||||
if attempts.len() == 4 {
|
||||
@@ -425,8 +424,9 @@ fn splash_downloads_resume_after_a_network_error_and_only_fetch_new_champions()
|
||||
let calls = next.splash_calls.clone();
|
||||
let loading_calls = next.card_counter();
|
||||
let tracker = reopen(dir.path(), next);
|
||||
tracker.refresh_champions().unwrap();
|
||||
tracker.refresh_champion_art(&mut |ok| assert!(ok)).unwrap();
|
||||
tracker
|
||||
.refresh_champion_art(|| {}, &mut |ok| assert!(ok))
|
||||
.unwrap();
|
||||
let splashes = statistics(&tracker)
|
||||
.rows
|
||||
.into_iter()
|
||||
@@ -435,30 +435,73 @@ fn splash_downloads_resume_after_a_network_error_and_only_fetch_new_champions()
|
||||
assert_eq!(splashes.len(), 4);
|
||||
assert!(splashes.contains(&first[0]));
|
||||
tracker
|
||||
.refresh_champion_art(&mut |_| panic!("already cached"))
|
||||
.refresh_champion_art(|| {}, &mut |_| panic!("already cached"))
|
||||
.unwrap();
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 3);
|
||||
assert_eq!(loading_calls.load(Ordering::SeqCst), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_loading_art_still_saves_the_original_splash_once_with_fixed_focus() {
|
||||
for cached_card in [false, true] {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let catalog = &CATALOG[..1];
|
||||
if cached_card {
|
||||
let tracker = reopen(dir.path(), FakeChampions::new("1", catalog));
|
||||
tracker.refresh_champions().unwrap();
|
||||
tracker.refresh_card_portraits(&mut |_| {}).unwrap();
|
||||
}
|
||||
let source = FakeChampions::new("1", catalog).without_portrait("Annie");
|
||||
let calls = source.splash_calls.clone();
|
||||
let tracker = reopen(dir.path(), source);
|
||||
tracker.refresh_champion_art(|| {}, &mut |_| {}).unwrap();
|
||||
let splash = statistics(&tracker).rows.remove(0).splash.unwrap();
|
||||
assert_eq!((splash.focus.x, splash.focus.y), (50, 30));
|
||||
assert_eq!(std::fs::read(splash.path).unwrap(), common::splash_art());
|
||||
tracker.refresh_champion_art(|| {}, &mut |_| {}).unwrap();
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_temporarily_unreadable_loading_image_is_retried_before_caching_the_splash() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let source = FakeChampions::new("1", &CATALOG[..1]).with_card_art(b"not a JPEG".to_vec());
|
||||
let splash_calls = source.splash_calls.clone();
|
||||
let tracker = reopen(dir.path(), source);
|
||||
tracker.refresh_champions().unwrap();
|
||||
tracker.refresh_champion_art(&mut |_| {}).unwrap();
|
||||
tracker.refresh_champion_art(|| {}, &mut |_| {}).unwrap();
|
||||
assert!(statistics(&tracker).rows.iter().all(|r| r.splash.is_none()));
|
||||
assert_eq!(splash_calls.load(Ordering::SeqCst), 0);
|
||||
|
||||
let tracker = reopen(dir.path(), FakeChampions::new("1", &CATALOG[..1]));
|
||||
tracker
|
||||
.refresh_champion_art(&mut |saved| assert!(saved))
|
||||
.refresh_champion_art(|| {}, &mut |saved| assert!(saved))
|
||||
.unwrap();
|
||||
assert!(statistics(&tracker).rows.iter().all(|r| r.splash.is_some()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_offline_launch_keeps_the_cached_catalog_and_makes_no_art_requests() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
reopen(dir.path(), FakeChampions::new("1", &CATALOG))
|
||||
.refresh_champions()
|
||||
.unwrap();
|
||||
let source = FakeChampions::new("1", &CATALOG).failing();
|
||||
let cards = source.card_counter();
|
||||
let splashes = source.splash_calls.clone();
|
||||
let tracker = reopen(dir.path(), source);
|
||||
let mut notified = false;
|
||||
assert!(
|
||||
tracker
|
||||
.refresh_champion_art(|| notified = true, &mut |_| panic!("offline art attempt"))
|
||||
.is_err()
|
||||
);
|
||||
assert!(notified);
|
||||
assert_eq!(statistics(&tracker).rows.len(), CATALOG.len());
|
||||
assert_eq!(cards.load(Ordering::SeqCst), 0);
|
||||
assert_eq!(splashes.load(Ordering::SeqCst), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn losing_the_network_during_cards_skips_all_splashes() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
@@ -466,15 +509,14 @@ fn losing_the_network_during_cards_skips_all_splashes() {
|
||||
source.card_failure().store(true, Ordering::SeqCst);
|
||||
let calls = source.splash_calls.clone();
|
||||
let tracker = reopen(dir.path(), source);
|
||||
tracker.refresh_champions().unwrap();
|
||||
let mut attempts = Vec::new();
|
||||
tracker
|
||||
.refresh_champion_art(&mut |saved| attempts.push(saved))
|
||||
.refresh_champion_art(|| {}, &mut |saved| attempts.push(saved))
|
||||
.unwrap();
|
||||
assert_eq!(attempts, [false]);
|
||||
assert_eq!(calls.load(Ordering::SeqCst), 0);
|
||||
open_tracker(dir.path(), &[])
|
||||
.refresh_champion_art(&mut |_| panic!("no source"))
|
||||
.refresh_champion_art(|| {}, &mut |_| panic!("no source"))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user