Add reading list removal
This commit is contained in:
@@ -36,6 +36,12 @@ impl BrowserCore {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn remove_reading_list_entry(&mut self, entry_id: &ReadingListId) -> Result<(), CoreError> {
|
||||
let index = self.reading_list_entry_index(entry_id)?;
|
||||
self.reading_list.remove(index);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn find_reading_list_match(&self, query: &str) -> Option<UrlText> {
|
||||
let normalized_query = query.trim().to_lowercase();
|
||||
if normalized_query.is_empty() {
|
||||
@@ -62,9 +68,14 @@ impl BrowserCore {
|
||||
&mut self,
|
||||
entry_id: &ReadingListId,
|
||||
) -> Result<&mut ReadingListEntry, CoreError> {
|
||||
let index = self.reading_list_entry_index(entry_id)?;
|
||||
Ok(&mut self.reading_list[index])
|
||||
}
|
||||
|
||||
fn reading_list_entry_index(&self, entry_id: &ReadingListId) -> Result<usize, CoreError> {
|
||||
self.reading_list
|
||||
.iter_mut()
|
||||
.find(|entry| entry.id() == entry_id)
|
||||
.iter()
|
||||
.position(|entry| entry.id() == entry_id)
|
||||
.ok_or_else(|| CoreError::ReadingListEntryNotFound { id: entry_id.clone() })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,32 @@ fn missing_reading_list_progress_update_returns_error() -> Result<(), Box<dyn Er
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_reading_list_entry_removes_saved_entry() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
core.open_tab(UrlText::parse("https://example.com/long-read")?);
|
||||
let entry_id = core.save_active_tab_to_reading_list()?;
|
||||
|
||||
core.remove_reading_list_entry(&entry_id)?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert!(snapshot.reading_list.is_empty());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_reading_list_remove_returns_error() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let missing_id = ReadingListId::new();
|
||||
|
||||
let Err(error) = core.remove_reading_list_entry(&missing_id) else {
|
||||
return Err("expected missing reading list entry error".into());
|
||||
};
|
||||
|
||||
assert_eq!(error, ely_browser_core::CoreError::ReadingListEntryNotFound { id: missing_id });
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reading_list_scoped_search_opens_matching_entry() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user