Add bookmark thumbnail metadata

This commit is contained in:
2026-05-08 11:47:38 -04:00
parent 2410e71006
commit b4355d0f82
5 changed files with 78 additions and 0 deletions
@@ -63,6 +63,23 @@ impl BrowserCore {
Ok(())
}
pub fn set_bookmark_thumbnail_key(
&mut self,
bookmark_id: &BookmarkId,
thumbnail_key: impl Into<String>,
) -> Result<(), CoreError> {
self.bookmark_mut(bookmark_id)?.set_thumbnail_key(thumbnail_key)?;
Ok(())
}
pub fn clear_bookmark_thumbnail_key(
&mut self,
bookmark_id: &BookmarkId,
) -> Result<(), CoreError> {
self.bookmark_mut(bookmark_id)?.clear_thumbnail_key();
Ok(())
}
pub fn update_bookmark_metadata(
&mut self,
bookmark_id: &BookmarkId,
@@ -25,6 +25,7 @@ fn bookmark_active_tab_records_current_context() -> Result<(), Box<dyn Error>> {
assert_eq!(bookmark.url().as_str(), "https://example.com/research");
assert!(bookmark.tags().is_empty());
assert_eq!(bookmark.note(), None);
assert_eq!(bookmark.thumbnail_key(), None);
Ok(())
}
@@ -65,6 +66,22 @@ fn bookmark_metadata_updates_collection_tags_and_note() -> Result<(), Box<dyn Er
Ok(())
}
#[test]
fn bookmark_thumbnail_key_can_be_set_and_cleared() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
core.open_tab(UrlText::parse("https://example.com/research")?);
let bookmark_id = core.bookmark_active_tab()?;
core.set_bookmark_thumbnail_key(&bookmark_id, " screenshots/example.avif ")?;
let snapshot = core.snapshot()?;
assert_eq!(snapshot.bookmarks[0].thumbnail_key(), Some("screenshots/example.avif"));
core.clear_bookmark_thumbnail_key(&bookmark_id)?;
let snapshot = core.snapshot()?;
assert_eq!(snapshot.bookmarks[0].thumbnail_key(), None);
Ok(())
}
#[test]
fn bookmark_metadata_batch_update_is_atomic() -> Result<(), Box<dyn Error>> {
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
@@ -111,6 +128,13 @@ fn bookmark_metadata_rejects_empty_fields() -> Result<(), Box<dyn Error>> {
return Err("expected empty bookmark note error".into());
};
assert_eq!(note_error, CoreError::Domain(DomainError::EmptyField { field: "bookmark note" }));
let Err(thumbnail_error) = core.set_bookmark_thumbnail_key(&bookmark_id, " ") else {
return Err("expected empty bookmark thumbnail key error".into());
};
assert_eq!(
thumbnail_error,
CoreError::Domain(DomainError::EmptyField { field: "bookmark thumbnail key" })
);
Ok(())
}