Restore archived tabs from command scope

This commit is contained in:
2026-05-07 19:59:55 -04:00
parent e0eb5b51b2
commit 75e17fc70f
4 changed files with 107 additions and 0 deletions
+41
View File
@@ -84,6 +84,47 @@ fn restore_tab_command_reopens_last_archived_tab() -> Result<(), Box<dyn Error>>
Ok(())
}
#[test]
fn archive_scoped_search_restores_matching_archived_tab() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com")?);
let servo_tab_id = core.open_tab(UrlText::parse("https://servo.org")?);
core.close_active_tab()?;
core.set_command_query("@archive servo");
let intent = core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(
intent,
Some(CommandIntent::ScopedSearch {
scope: ely_domain::CommandScope::Archive,
query: "servo".to_string()
})
);
assert_eq!(snapshot.active_tab_id, servo_tab_id);
assert!(snapshot.archived_tabs.is_empty());
assert_eq!(snapshot.command_query, "");
Ok(())
}
#[test]
fn archive_scoped_search_preserves_query_without_match() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com")?);
core.close_active_tab()?;
let active_tab_id = core.active_tab()?.id().clone();
core.set_command_query("@archive absent");
core.submit_command()?;
let snapshot = core.snapshot()?;
assert_eq!(snapshot.active_tab_id, active_tab_id);
assert_eq!(snapshot.archived_tabs.len(), 1);
assert_eq!(snapshot.command_query, "@archive absent");
Ok(())
}
#[test]
fn unknown_command_preserves_query() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
+36
View File
@@ -73,6 +73,42 @@ fn restores_last_archived_tab() -> Result<(), Box<dyn Error>> {
Ok(())
}
#[test]
fn restores_matching_archived_tab() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
let example_tab_id = core.open_tab(UrlText::parse("https://example.com")?);
let servo_tab_id = core.open_tab(UrlText::parse("https://servo.org")?);
core.close_active_tab()?;
core.select_tab(&example_tab_id)?;
core.close_active_tab()?;
let restored_tab_id = core.restore_archived_tab_match("servo")?;
let snapshot = core.snapshot()?;
assert_eq!(restored_tab_id, Some(servo_tab_id.clone()));
assert_eq!(snapshot.active_tab_id, servo_tab_id);
assert_eq!(snapshot.archived_tabs.len(), 1);
assert_eq!(snapshot.archived_tabs[0].tab().id(), &example_tab_id);
Ok(())
}
#[test]
fn ignores_empty_archived_tab_match_query() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com")?);
core.close_active_tab()?;
let active_tab_id = core.active_tab()?.id().clone();
let restored_tab_id = core.restore_archived_tab_match(" ")?;
let snapshot = core.snapshot()?;
assert_eq!(restored_tab_id, None);
assert_eq!(snapshot.active_tab_id, active_tab_id);
assert_eq!(snapshot.archived_tabs.len(), 1);
Ok(())
}
#[test]
fn restore_without_archived_tabs_returns_error() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;