mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-27 13:17:41 +00:00
Cloud: send no folder listing while a sign-in waits for its answer
browse and load_shared checked only that a service was wired. A call made after sign_in and before the account answer sent a listing in the new session. When its answer arrived after the account answer, the folder kept it and read as loaded, although the listing could be the previous account's. Both now return while the sign-in is outstanding, as save_as does; start already waits on the folders' loading state.
This commit is contained in:
@@ -419,17 +419,22 @@ pub fn sign_out<A: CloudApp>(app: &mut A) {
|
||||
}
|
||||
|
||||
/// Lists one folder. An empty path is the user's root.
|
||||
///
|
||||
/// Nothing is sent while a sign-in waits for its answer. A listing sent then
|
||||
/// can answer after the account does, and its files may be the previous
|
||||
/// account's; the answer empties the folder so it is listed again.
|
||||
pub fn browse<A: CloudApp>(app: &mut A, path: &str) {
|
||||
if !available(app) {
|
||||
if !available(app) || app.cloud().relist_after_sign_in {
|
||||
return;
|
||||
}
|
||||
app.cloud_mut().mine.begin(path);
|
||||
submit(app, Job::List(path.to_owned()));
|
||||
}
|
||||
|
||||
/// Lists what other people have shared with this user.
|
||||
/// Lists what other people have shared with this user. Like [`browse`], it
|
||||
/// sends nothing while a sign-in waits for its answer.
|
||||
pub fn load_shared<A: CloudApp>(app: &mut A) {
|
||||
if !available(app) {
|
||||
if !available(app) || app.cloud().relist_after_sign_in {
|
||||
return;
|
||||
}
|
||||
app.cloud_mut().shared.begin("");
|
||||
|
||||
@@ -479,6 +479,31 @@ fn a_sign_in_that_drops_a_listing_leaves_no_folder_loading() {
|
||||
assert_eq!(report(&app)["entries"], serde_json::json!(["Minutes.note", "Archive"]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_listing_asked_for_before_the_sign_in_answers_is_not_sent() {
|
||||
let (mut app, jobs, ctx) = wired();
|
||||
sign_in(&mut app);
|
||||
jobs.lock().unwrap().clear();
|
||||
|
||||
// Asked for after the sign-in and before its answer. A listing sent now
|
||||
// could answer after the account does, and its files may be the previous
|
||||
// account's.
|
||||
browse(&mut app, "");
|
||||
load_shared(&mut app);
|
||||
assert!(
|
||||
!jobs.lock().unwrap().iter().any(|j| matches!(j, Job::List(_) | Job::SharedWithMe)),
|
||||
"no listing goes out while the sign-in is outstanding"
|
||||
);
|
||||
pumped(&mut app, &ctx);
|
||||
assert!(!app.cloud.mine.loaded && !app.cloud.mine.loading, "the folder waits to be listed for the new account");
|
||||
assert!(!app.cloud.shared.loaded && !app.cloud.shared.loading, "and so does the shared one");
|
||||
|
||||
// Once the sign-in has answered, a listing goes through.
|
||||
browse(&mut app, "");
|
||||
pumped(&mut app, &ctx);
|
||||
assert!(app.cloud.mine.loaded);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytes_are_said_the_way_a_person_reads_them() {
|
||||
assert_eq!(size_text(None), "");
|
||||
|
||||
Reference in New Issue
Block a user