Multiple collections, tab close-all and rename, tab scroll bar fix
- Keep several collections open at once. Each has its own environments, selected environment, cookie jar and file watcher, and they are reopened on start. The environment picker acts on the current collection (the active tab's, or the one last chosen). Overlapping folders are refused. - Close all / close others for tabs (Ctrl+Shift+W, tab menu, File menu), asking once about tabs with unsaved changes. - Rename a request from its tab (double-click, tab menu, or the … menu). - Give the tab strip's scroll bar its own row so it no longer covers the tab names. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b729c5d32
commit
d5e7b484fc
13 files changed
+997
-237
No files matched your search
@@ -36,7 +36,12 @@ fn response(status: u16, body: &str, headers: &[(&str, &str)]) -> Response {
|
||||
|
||||
/// A loaded collection at `/c` with the given files.
|
||||
fn with_collection(s: &mut AppState, files: &[(&str, &str)]) -> PathBuf {
|
||||
let root = PathBuf::from("/c");
|
||||
with_collection_at(s, "/c", files)
|
||||
}
|
||||
|
||||
/// Loads a collection at `root` with the given files.
|
||||
fn with_collection_at(s: &mut AppState, root: &str, files: &[(&str, &str)]) -> PathBuf {
|
||||
let root = PathBuf::from(root);
|
||||
let c = Collection {
|
||||
root: root.clone(),
|
||||
tree: Node::Folder {
|
||||
@@ -56,7 +61,7 @@ fn with_collection(s: &mut AppState, files: &[(&str, &str)]) -> PathBuf {
|
||||
.collect(),
|
||||
};
|
||||
let fx = update(s, Action::CollectionLoaded(Ok(c)));
|
||||
assert!(fx.iter().any(|e| matches!(e, Effect::Watch(Some(_)))));
|
||||
assert!(fx.iter().any(|e| matches!(e, Effect::Watch(_))));
|
||||
assert!(fx.iter().any(|e| matches!(e, Effect::LoadEnvironments(_))));
|
||||
root
|
||||
}
|
||||
@@ -239,7 +244,13 @@ fn environments_resolve_and_switch() {
|
||||
.unwrap(),
|
||||
private: EnvFile::parse(r#"{"dev": {"token": "t-dev"}, "prod": {"token": "t-prod"}}"#, &root).unwrap(),
|
||||
};
|
||||
update(&mut s, Action::EnvironmentsLoaded(Ok((envs, false))));
|
||||
update(
|
||||
&mut s,
|
||||
Action::EnvironmentsLoaded {
|
||||
root: root.clone(),
|
||||
result: Ok((envs, false)),
|
||||
},
|
||||
);
|
||||
update(
|
||||
&mut s,
|
||||
Action::OpenRequest {
|
||||
@@ -260,7 +271,7 @@ fn environments_resolve_and_switch() {
|
||||
};
|
||||
assert_eq!(request.url, url);
|
||||
assert_eq!(request.headers[0].1, auth);
|
||||
assert!(s.is_private_var("token"));
|
||||
assert!(s.is_private_var(s.tab(id).unwrap(), "token"));
|
||||
let seq = *seq;
|
||||
update(
|
||||
&mut s,
|
||||
@@ -607,7 +618,7 @@ fn create_rename_duplicate_move_delete() {
|
||||
},
|
||||
);
|
||||
assert!(s.tab(copy_tab).unwrap().orphaned);
|
||||
assert_eq!(s.collection.as_ref().unwrap().files[&other].request_count(), 2);
|
||||
assert_eq!(s.collection_of(&other).unwrap().files[&other].request_count(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -710,7 +721,7 @@ fn env_editor_writes_both_files() {
|
||||
assert!(w
|
||||
.iter()
|
||||
.any(|(p, t)| p == &root.join(env::PRIVATE_FILE) && t.contains("\"token\": \"secret\"")));
|
||||
assert_eq!(s.collection.as_ref().unwrap().envs.names(), vec!["dev"]);
|
||||
assert_eq!(s.collection(&root).unwrap().envs.names(), vec!["dev"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -759,3 +770,318 @@ fn concurrency_setting_reaches_the_runner() {
|
||||
let fx = update(&mut s, Action::SettingsChanged(changed));
|
||||
assert!(fx.iter().any(|e| matches!(e, Effect::SetConcurrency(5))));
|
||||
}
|
||||
|
||||
// ------------------------------------------------- several collections
|
||||
|
||||
fn load_envs(s: &mut AppState, root: &Path, public: &str) {
|
||||
let envs = Environments {
|
||||
public: EnvFile::parse(public, root).unwrap(),
|
||||
private: EnvFile::default(),
|
||||
};
|
||||
update(
|
||||
s,
|
||||
Action::EnvironmentsLoaded {
|
||||
root: root.to_path_buf(),
|
||||
result: Ok((envs, false)),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn sent_url(s: &mut AppState, id: TabId) -> String {
|
||||
let fx = update(s, Action::Send(id));
|
||||
let Effect::SendRequest { request, seq, .. } = &fx[0] else {
|
||||
panic!("{fx:?} / {:?}", s.tab(id).unwrap().error)
|
||||
};
|
||||
let (url, seq) = (request.url.clone(), *seq);
|
||||
update(
|
||||
s,
|
||||
Action::ResponseReceived {
|
||||
tab: id,
|
||||
seq,
|
||||
result: Err(HttpError::Timeout),
|
||||
},
|
||||
);
|
||||
url
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_collection_has_its_own_environment() {
|
||||
let mut s = state();
|
||||
let a = with_collection_at(&mut s, "/a", &[("a.http", "### A\nGET {{base}}/a\n")]);
|
||||
let b = with_collection_at(&mut s, "/b", &[("b.http", "### B\nGET {{base}}/b\n")]);
|
||||
assert_eq!(s.collections.len(), 2);
|
||||
load_envs(&mut s, &a, r#"{"dev": {"base": "http://a-dev"}}"#);
|
||||
load_envs(
|
||||
&mut s,
|
||||
&b,
|
||||
r#"{"dev": {"base": "http://b-dev"}, "prod": {"base": "https://b-prod"}}"#,
|
||||
);
|
||||
|
||||
update(
|
||||
&mut s,
|
||||
Action::OpenRequest {
|
||||
file: a.join("a.http"),
|
||||
index: 0,
|
||||
},
|
||||
);
|
||||
let ta = active(&s);
|
||||
update(&mut s, Action::SelectEnv(Some("dev".into())));
|
||||
update(
|
||||
&mut s,
|
||||
Action::OpenRequest {
|
||||
file: b.join("b.http"),
|
||||
index: 0,
|
||||
},
|
||||
);
|
||||
let tb = active(&s);
|
||||
// The picker now acts on /b, which has no environment selected yet.
|
||||
assert_eq!(s.current_collection().unwrap().root, b);
|
||||
assert!(s.current_collection().unwrap().selected_env.is_none());
|
||||
update(&mut s, Action::SelectEnv(Some("prod".into())));
|
||||
|
||||
assert_eq!(sent_url(&mut s, ta), "http://a-dev/a");
|
||||
assert_eq!(sent_url(&mut s, tb), "https://b-prod/b");
|
||||
assert_eq!(s.collection(&a).unwrap().selected_env.as_deref(), Some("dev"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn untitled_tabs_use_the_active_collection() {
|
||||
let mut s = state();
|
||||
let a = with_collection_at(&mut s, "/a", &[]);
|
||||
let b = with_collection_at(&mut s, "/b", &[]);
|
||||
load_envs(&mut s, &a, r#"{"dev": {"base": "http://a"}}"#);
|
||||
load_envs(&mut s, &b, r#"{"dev": {"base": "http://b"}}"#);
|
||||
for root in [&a, &b] {
|
||||
update(&mut s, Action::SetActiveCollection(root.clone()));
|
||||
update(&mut s, Action::SelectEnv(Some("dev".into())));
|
||||
}
|
||||
update(&mut s, Action::NewTab);
|
||||
let id = active(&s);
|
||||
update(&mut s, Action::UrlEdited(id, "{{base}}/x".into()));
|
||||
assert_eq!(sent_url(&mut s, id), "http://b/x", "the last opened/clicked collection");
|
||||
update(&mut s, Action::SetActiveCollection(a.clone()));
|
||||
assert_eq!(sent_url(&mut s, id), "http://a/x");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opening_a_collection_twice_or_nested_is_refused() {
|
||||
let mut s = state();
|
||||
let a = with_collection_at(&mut s, "/work/api", &[]);
|
||||
with_collection_at(&mut s, "/other", &[]);
|
||||
// Already open: just becomes current, nothing is loaded again.
|
||||
assert!(update(&mut s, Action::OpenCollection(a.clone())).is_empty());
|
||||
assert_eq!(s.active_collection.as_ref(), Some(&a));
|
||||
for overlapping in ["/work/api/sub", "/work"] {
|
||||
assert!(update(&mut s, Action::OpenCollection(overlapping.into())).is_empty());
|
||||
assert!(s.status.as_ref().unwrap().is_error);
|
||||
}
|
||||
let fx = update(&mut s, Action::OpenCollection("/work/web".into()));
|
||||
assert!(fx.iter().any(|e| matches!(e, Effect::LoadCollection(_))));
|
||||
assert_eq!(s.settings.open_collections, vec![PathBuf::from("/work/web")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn closing_a_collection_closes_its_clean_tabs_and_keeps_edits() {
|
||||
let mut s = state();
|
||||
let a = with_collection_at(&mut s, "/a", &[("a.http", "### A\nGET /a\n\n### A2\nGET /a2\n")]);
|
||||
let b = with_collection_at(&mut s, "/b", &[("b.http", "### B\nGET /b\n")]);
|
||||
s.settings.open_collections = vec![a.clone(), b.clone()];
|
||||
update(
|
||||
&mut s,
|
||||
Action::OpenRequest {
|
||||
file: a.join("a.http"),
|
||||
index: 0,
|
||||
},
|
||||
);
|
||||
let clean = active(&s);
|
||||
update(
|
||||
&mut s,
|
||||
Action::OpenRequest {
|
||||
file: a.join("a.http"),
|
||||
index: 1,
|
||||
},
|
||||
);
|
||||
let dirty = active(&s);
|
||||
update(&mut s, Action::UrlEdited(dirty, "/edited".into()));
|
||||
update(
|
||||
&mut s,
|
||||
Action::OpenRequest {
|
||||
file: b.join("b.http"),
|
||||
index: 0,
|
||||
},
|
||||
);
|
||||
let other = active(&s);
|
||||
|
||||
let fx = update(&mut s, Action::CloseCollection(a.clone()));
|
||||
assert!(fx.iter().any(|e| matches!(e, Effect::Unwatch(r) if r == &a)));
|
||||
assert!(s.tab(clean).is_none());
|
||||
let t = s.tab(dirty).unwrap();
|
||||
assert!(t.orphaned && t.origin.is_none() && t.request.url == "/edited");
|
||||
assert!(s.tab(other).unwrap().origin.is_some());
|
||||
assert_eq!(s.collections.len(), 1);
|
||||
assert_eq!(s.settings.open_collections, vec![b]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn moving_a_request_between_collections() {
|
||||
let mut s = state();
|
||||
let a = with_collection_at(&mut s, "/a", &[("a.http", "### A\nGET /a\n")]);
|
||||
let b = with_collection_at(&mut s, "/b", &[("b.http", "### B\nGET /b\n")]);
|
||||
let fx = update(
|
||||
&mut s,
|
||||
Action::MoveRequest {
|
||||
from: a.join("a.http"),
|
||||
index: 0,
|
||||
to: b.join("b.http"),
|
||||
},
|
||||
);
|
||||
let w = writes(&fx);
|
||||
assert!(w.contains(&(b.join("b.http"), "### B\nGET /b\n\n### A\nGET /a\n".into())));
|
||||
assert!(w.contains(&(a.join("a.http"), String::new())));
|
||||
assert_eq!(s.collection(&b).unwrap().files[&b.join("b.http")].request_count(), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disk_changes_go_to_the_right_collection() {
|
||||
let mut s = state();
|
||||
let a = with_collection_at(&mut s, "/a", &[("x.http", "GET /a\n")]);
|
||||
let b = with_collection_at(&mut s, "/b", &[("x.http", "GET /b\n")]);
|
||||
update(
|
||||
&mut s,
|
||||
Action::FileChangedOnDisk {
|
||||
path: b.join("x.http"),
|
||||
text: Some("GET /b2\n".into()),
|
||||
},
|
||||
);
|
||||
assert_eq!(s.collection(&a).unwrap().files[&a.join("x.http")].text(), "GET /a\n");
|
||||
assert_eq!(s.collection(&b).unwrap().files[&b.join("x.http")].text(), "GET /b2\n");
|
||||
// Env files reload only their own collection, and only at its root.
|
||||
let fx = update(
|
||||
&mut s,
|
||||
Action::FileChangedOnDisk {
|
||||
path: a.join(env::PUBLIC_FILE),
|
||||
text: Some("{}".into()),
|
||||
},
|
||||
);
|
||||
assert!(matches!(&fx[..], [Effect::LoadEnvironments(r)] if r == &a));
|
||||
let fx = update(
|
||||
&mut s,
|
||||
Action::FileChangedOnDisk {
|
||||
path: a.join("sub").join(env::PUBLIC_FILE),
|
||||
text: Some("{}".into()),
|
||||
},
|
||||
);
|
||||
assert!(fx.is_empty());
|
||||
}
|
||||
|
||||
// ------------------------------------------------- close all, rename tabs
|
||||
|
||||
#[test]
|
||||
fn close_all_closes_clean_tabs_and_asks_once_about_the_rest() {
|
||||
let mut s = state();
|
||||
for url in ["", "http://edited", "", "http://also-edited"] {
|
||||
update(&mut s, Action::NewTab);
|
||||
if !url.is_empty() {
|
||||
let id = active(&s);
|
||||
update(&mut s, Action::UrlEdited(id, url.into()));
|
||||
}
|
||||
}
|
||||
let ids: Vec<TabId> = s.tabs.iter().map(|t| t.id).collect();
|
||||
update(&mut s, Action::CloseTabs(ids.clone()));
|
||||
assert_eq!(s.tabs.len(), 2, "the clean tabs are gone");
|
||||
let dirty = vec![ids[1], ids[3]];
|
||||
assert_eq!(s.dialog, Some(Dialog::ConfirmCloseTabs(dirty.clone())));
|
||||
update(&mut s, Action::DiscardAndCloseTabs(dirty));
|
||||
assert!(s.tabs.is_empty());
|
||||
assert!(s.active.is_none());
|
||||
assert!(s.dialog.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn close_others_keeps_the_chosen_tab() {
|
||||
let mut s = state();
|
||||
for _ in 0..3 {
|
||||
update(&mut s, Action::NewTab);
|
||||
}
|
||||
let keep = s.tabs[1].id;
|
||||
let others = s.tabs.iter().map(|t| t.id).filter(|&t| t != keep).collect();
|
||||
update(&mut s, Action::CloseTabs(others));
|
||||
assert_eq!(s.tabs.len(), 1);
|
||||
assert_eq!(s.active, Some(keep));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renaming_a_clean_tab_renames_the_request_in_its_file() {
|
||||
let mut s = state();
|
||||
let root = with_collection(&mut s, &[("users.http", USERS)]);
|
||||
let file = root.join("users.http");
|
||||
update(
|
||||
&mut s,
|
||||
Action::OpenRequest {
|
||||
file: file.clone(),
|
||||
index: 0,
|
||||
},
|
||||
);
|
||||
let id = active(&s);
|
||||
let fx = update(
|
||||
&mut s,
|
||||
Action::RenameTab {
|
||||
tab: id,
|
||||
title: "All users".into(),
|
||||
},
|
||||
);
|
||||
let w = writes(&fx);
|
||||
assert_eq!(
|
||||
w,
|
||||
vec![(file.clone(), USERS.replace("### List users", "### All users"))]
|
||||
);
|
||||
let t = s.tab(id).unwrap();
|
||||
assert_eq!(t.title(), "All users");
|
||||
assert!(!t.is_dirty());
|
||||
assert_eq!(t.origin.as_ref().unwrap().key.name.as_deref(), Some("All users"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renaming_an_edited_or_untitled_tab_is_an_edit_that_save_writes() {
|
||||
let mut s = state();
|
||||
let root = with_collection(&mut s, &[("users.http", USERS)]);
|
||||
let file = root.join("users.http");
|
||||
// `create-user` has an @name, which follows the new title.
|
||||
update(
|
||||
&mut s,
|
||||
Action::OpenRequest {
|
||||
file: file.clone(),
|
||||
index: 1,
|
||||
},
|
||||
);
|
||||
let id = active(&s);
|
||||
update(&mut s, Action::UrlEdited(id, "{{base}}/v2/users".into()));
|
||||
let fx = update(
|
||||
&mut s,
|
||||
Action::RenameTab {
|
||||
tab: id,
|
||||
title: "Add user".into(),
|
||||
},
|
||||
);
|
||||
assert!(writes(&fx).is_empty(), "nothing is written before Save");
|
||||
assert_eq!(s.tab(id).unwrap().title(), "add-user");
|
||||
let w = writes(&update(&mut s, Action::Save(id)));
|
||||
assert!(
|
||||
w[0].1
|
||||
.contains("### Add user\n# @name add-user\nPOST {{base}}/v2/users"),
|
||||
"{}",
|
||||
w[0].1
|
||||
);
|
||||
|
||||
update(&mut s, Action::NewTab);
|
||||
let untitled = active(&s);
|
||||
update(
|
||||
&mut s,
|
||||
Action::RenameTab {
|
||||
tab: untitled,
|
||||
title: "Scratch".into(),
|
||||
},
|
||||
);
|
||||
assert_eq!(s.tab(untitled).unwrap().title(), "Scratch");
|
||||
assert!(s.tab(untitled).unwrap().source.starts_with("### Scratch\n"));
|
||||
}
|
||||
Reference in new issue
Block a user