An import of 10 Matches or more of the Account shown draws a thin arc around the ring's ticks, filled from noon as Matches arrive and gone when the import ends. The ring stays a cached view, told at most once a second. While the import waits for a 429's Retry-After, the progress carries the wait and the status line counts it down each second (« Quota Riot atteint : reprise dans 12 s »), on a timer that only exists during the wait. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
151 lines
5.0 KiB
Rust
151 lines
5.0 KiB
Rust
//! The status line while the import waits for the Riot quota (#140): the seconds left, counted
|
|
//! down by one timer that exists only for the wait.
|
|
|
|
use super::banner_fixtures::ring_renders;
|
|
use super::import_arc::{arc, choose, on_alice, progress, second, tell};
|
|
use super::page_fixtures::draw;
|
|
use crate::page::Page;
|
|
use crate::worker::Msg;
|
|
use arena_tracker_core::SyncProgress;
|
|
use gpui_kit::{Entity, TestAppContext, VisualTestContext};
|
|
use std::cell::Cell;
|
|
use std::rc::Rc;
|
|
use std::time::Duration;
|
|
|
|
fn line(page: &Entity<Page>, cx: &mut VisualTestContext) -> String {
|
|
page.read_with(cx, |p, cx| {
|
|
p.status_line(cx.background_executor().now()).to_string()
|
|
})
|
|
}
|
|
|
|
fn waiting(fetched: usize, to_fetch: usize, secs: u64) -> SyncProgress {
|
|
SyncProgress {
|
|
quota_wait: Some(Duration::from_secs(secs)),
|
|
..progress(fetched, to_fetch)
|
|
}
|
|
}
|
|
|
|
/// How many times the page is told it changed from now on.
|
|
fn notifications(page: &Entity<Page>, cx: &mut VisualTestContext) -> Rc<Cell<usize>> {
|
|
let told = Rc::new(Cell::new(0));
|
|
let counted = told.clone();
|
|
cx.update(|_, cx| {
|
|
cx.observe(page, move |_, _| counted.set(counted.get() + 1))
|
|
.detach()
|
|
});
|
|
told
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn the_own_sync_counts_the_wait_down_then_the_import_line_comes_back(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
let (page, mut window, _) = on_alice(cx).await;
|
|
let cx = &mut window;
|
|
tell(&page, cx, Msg::Progress(progress(3, 12)));
|
|
assert_eq!(line(&page, cx), "Import en cours : 3 / 12 Parties");
|
|
|
|
tell(&page, cx, Msg::Progress(waiting(3, 12, 12)));
|
|
assert_eq!(line(&page, cx), "Quota Riot atteint : reprise dans 12 s");
|
|
second(cx);
|
|
assert_eq!(line(&page, cx), "Quota Riot atteint : reprise dans 11 s");
|
|
cx.executor().advance_clock(Duration::from_millis(500));
|
|
// Rounded up: 10.5 s left say 11.
|
|
assert_eq!(line(&page, cx), "Quota Riot atteint : reprise dans 11 s");
|
|
for _ in 0..10 {
|
|
second(cx);
|
|
}
|
|
assert_eq!(line(&page, cx), "Quota Riot atteint : reprise dans 1 s");
|
|
|
|
tell(&page, cx, Msg::Progress(progress(3, 12)));
|
|
assert_eq!(line(&page, cx), "Import en cours : 3 / 12 Parties");
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn a_wait_that_passed_without_news_falls_back_to_the_import_line(cx: &mut TestAppContext) {
|
|
let (page, mut window, _) = on_alice(cx).await;
|
|
let cx = &mut window;
|
|
tell(&page, cx, Msg::Progress(waiting(3, 12, 2)));
|
|
second(cx);
|
|
second(cx);
|
|
assert_eq!(line(&page, cx), "Import en cours : 3 / 12 Parties");
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn nothing_ticks_before_a_wait_nor_after_it(cx: &mut TestAppContext) {
|
|
let (page, mut window, _) = on_alice(cx).await;
|
|
let cx = &mut window;
|
|
let told = notifications(&page, cx);
|
|
for _ in 0..3 {
|
|
second(cx);
|
|
}
|
|
assert_eq!(told.get(), 0);
|
|
|
|
// The wait: the page is drawn again each second, and the ring is not.
|
|
tell(&page, cx, Msg::Progress(progress(3, 12)));
|
|
draw(cx);
|
|
let renders = ring_renders(&page, cx);
|
|
tell(&page, cx, Msg::Progress(waiting(3, 12, 30)));
|
|
let before = told.get();
|
|
for _ in 0..3 {
|
|
second(cx);
|
|
}
|
|
assert_eq!(told.get() - before, 3);
|
|
assert_eq!(ring_renders(&page, cx), renders);
|
|
assert_eq!(arc(&page, cx), Some((3, 12)));
|
|
|
|
// Resumed: the timer has ended itself.
|
|
tell(&page, cx, Msg::Progress(progress(4, 12)));
|
|
let before = told.get();
|
|
for _ in 0..3 {
|
|
second(cx);
|
|
}
|
|
assert_eq!(told.get(), before);
|
|
}
|
|
|
|
#[gpui::test]
|
|
async fn a_friends_import_tells_its_wait_too_and_the_own_sync_keeps_its_priority(
|
|
cx: &mut TestAppContext,
|
|
) {
|
|
let (page, mut window, handles) = on_alice(cx).await;
|
|
handles.gate.set(false);
|
|
choose(&page, &mut window, "Carl");
|
|
cx.condition(&page, |p, _| {
|
|
p.friend_status().as_deref() == Some("Import de Carl : 0 / 2 Parties")
|
|
})
|
|
.await;
|
|
let cx = &mut window;
|
|
let friend = |progress| Msg::FriendProgress {
|
|
puuid: "Carl".into(),
|
|
progress,
|
|
};
|
|
|
|
tell(&page, cx, friend(waiting(0, 2, 5)));
|
|
assert_eq!(line(&page, cx), "Quota Riot atteint : reprise dans 5 s");
|
|
second(cx);
|
|
assert_eq!(line(&page, cx), "Quota Riot atteint : reprise dans 4 s");
|
|
|
|
// The own sync's line comes first, waiting or not.
|
|
tell(&page, cx, Msg::Progress(progress(1, 12)));
|
|
assert_eq!(line(&page, cx), "Import en cours : 1 / 12 Parties");
|
|
tell(&page, cx, Msg::Progress(waiting(1, 12, 20)));
|
|
assert_eq!(line(&page, cx), "Quota Riot atteint : reprise dans 20 s");
|
|
|
|
// Its end brings the Friend's wait back, still counting.
|
|
let status = page.read_with(cx, |p, _| p.tracker.status());
|
|
let end = Msg::Round {
|
|
status,
|
|
reload: false,
|
|
matches: Vec::new(),
|
|
game_end: None,
|
|
};
|
|
tell(&page, cx, end);
|
|
assert_eq!(line(&page, cx), "Quota Riot atteint : reprise dans 4 s");
|
|
second(cx);
|
|
assert_eq!(line(&page, cx), "Quota Riot atteint : reprise dans 3 s");
|
|
|
|
tell(&page, cx, friend(progress(0, 2)));
|
|
assert_eq!(line(&page, cx), "Import de Carl : 0 / 2 Parties");
|
|
handles.gate.set(true);
|
|
}
|