Add bookmark metadata editor
This commit is contained in:
@@ -63,6 +63,28 @@ impl BrowserCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_bookmark_metadata(
|
||||
&mut self,
|
||||
bookmark_id: &BookmarkId,
|
||||
collection_name: impl Into<String>,
|
||||
tags: Vec<String>,
|
||||
note: Option<String>,
|
||||
) -> Result<(), CoreError> {
|
||||
let bookmark = self.bookmark_mut(bookmark_id)?;
|
||||
let mut updated_bookmark = bookmark.clone();
|
||||
|
||||
updated_bookmark.set_collection_name(collection_name)?;
|
||||
updated_bookmark.set_tags(tags)?;
|
||||
if let Some(note) = note {
|
||||
updated_bookmark.set_note(note)?;
|
||||
} else {
|
||||
updated_bookmark.clear_note();
|
||||
}
|
||||
|
||||
*bookmark = updated_bookmark;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn find_bookmark_match(&self, query: &str) -> Option<UrlText> {
|
||||
let normalized_query = query.trim().to_lowercase();
|
||||
if normalized_query.is_empty() {
|
||||
|
||||
@@ -65,6 +65,29 @@ fn bookmark_metadata_updates_collection_tags_and_note() -> Result<(), Box<dyn Er
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bookmark_metadata_batch_update_is_atomic() -> 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()?;
|
||||
|
||||
let Err(error) = core.update_bookmark_metadata(
|
||||
&bookmark_id,
|
||||
"Research",
|
||||
vec!["rust".to_string(), " ".to_string()],
|
||||
Some("Read later".to_string()),
|
||||
) else {
|
||||
return Err("expected invalid bookmark metadata error".into());
|
||||
};
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert_eq!(error, CoreError::Domain(DomainError::EmptyField { field: "bookmark tag" }));
|
||||
assert_eq!(snapshot.bookmarks[0].collection_name(), "Work");
|
||||
assert!(snapshot.bookmarks[0].tags().is_empty());
|
||||
assert_eq!(snapshot.bookmarks[0].note(), None);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bookmark_metadata_rejects_empty_fields() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user