Add reading list internal page
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
use std::error::Error;
|
||||
|
||||
use ely_browser_core::{BrowserCore, InitialBrowserConfig};
|
||||
use ely_domain::{CommandIntent, CommandScope, ProfileKind, ReadingProgress, UrlText};
|
||||
|
||||
#[test]
|
||||
fn save_active_tab_records_reading_list_context() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let tab_id = core.open_tab(UrlText::parse("https://example.com/long-read")?);
|
||||
let active_profile_id = core.active_tab()?.profile_id().clone();
|
||||
let active_space_id = core.active_tab()?.space_id().clone();
|
||||
|
||||
let entry_id = core.save_active_tab_to_reading_list()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
let [entry] = snapshot.reading_list.as_slice() else {
|
||||
return Err(
|
||||
format!("expected 1 reading list entry, got {}", snapshot.reading_list.len()).into()
|
||||
);
|
||||
};
|
||||
|
||||
assert_eq!(snapshot.active_tab_id, tab_id);
|
||||
assert_eq!(entry.id(), &entry_id);
|
||||
assert_eq!(entry.profile_id(), &active_profile_id);
|
||||
assert_eq!(entry.space_id(), &active_space_id);
|
||||
assert_eq!(entry.title(), "example.com");
|
||||
assert_eq!(entry.source_url().as_str(), "https://example.com/long-read");
|
||||
assert_eq!(entry.progress(), &ReadingProgress::Unread);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_active_tab_reuses_existing_reading_list_entry() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
core.open_tab(UrlText::parse("https://example.com/long-read")?);
|
||||
|
||||
let first_id = core.save_active_tab_to_reading_list()?;
|
||||
let second_id = core.save_active_tab_to_reading_list()?;
|
||||
|
||||
assert_eq!(first_id, second_id);
|
||||
assert_eq!(core.snapshot()?.reading_list.len(), 1);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reading_list_scoped_search_opens_matching_entry() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
core.open_tab(UrlText::parse("https://example.com/long-read")?);
|
||||
core.save_active_tab_to_reading_list()?;
|
||||
|
||||
core.set_command_query("@reading-list long-read");
|
||||
let intent = core.submit_command()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
let active_tab = core.active_tab()?;
|
||||
|
||||
assert_eq!(
|
||||
intent,
|
||||
Some(CommandIntent::ScopedSearch {
|
||||
scope: CommandScope::ReadingList,
|
||||
query: "long-read".to_string()
|
||||
})
|
||||
);
|
||||
assert_eq!(active_tab.url().as_str(), "https://example.com/long-read");
|
||||
assert_eq!(snapshot.command_query, "");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reading_list_stays_with_active_profile() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let default_profile_id = core.active_tab()?.profile_id().clone();
|
||||
let personal_profile_id = core.create_profile("Personal", 0xf54e00, ProfileKind::Standard)?;
|
||||
|
||||
core.open_tab(UrlText::parse("https://example.com/personal")?);
|
||||
core.save_active_tab_to_reading_list()?;
|
||||
core.select_profile(&default_profile_id)?;
|
||||
|
||||
core.set_command_query("@reading-list personal");
|
||||
let intent = core.submit_command()?;
|
||||
let snapshot = core.snapshot()?;
|
||||
|
||||
assert_eq!(
|
||||
intent,
|
||||
Some(CommandIntent::ScopedSearch {
|
||||
scope: CommandScope::ReadingList,
|
||||
query: "personal".to_string()
|
||||
})
|
||||
);
|
||||
assert_eq!(core.active_tab()?.profile_id(), &default_profile_id);
|
||||
assert_ne!(core.active_tab()?.profile_id(), &personal_profile_id);
|
||||
assert!(snapshot.reading_list.is_empty());
|
||||
assert_eq!(snapshot.command_query, "@reading-list personal");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn open_reading_list_command_opens_reading_list_page() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
core.set_command_query(">open-reading-list");
|
||||
let intent = core.submit_command()?;
|
||||
let active_tab = core.active_tab()?;
|
||||
|
||||
assert_eq!(intent, Some(CommandIntent::Command("open-reading-list".to_string())));
|
||||
assert_eq!(active_tab.title(), "Reading List");
|
||||
assert_eq!(active_tab.url().as_str(), "ely://reading-list");
|
||||
assert_eq!(core.snapshot()?.command_query, "");
|
||||
Ok(())
|
||||
}
|
||||
@@ -9,6 +9,7 @@ fn default_sync_status_reflects_local_browser_state() -> Result<(), Box<dyn Erro
|
||||
core.create_space("Research", "R", 0xf54e00)?;
|
||||
core.open_tab(UrlText::parse("https://example.com/research")?);
|
||||
core.bookmark_active_tab()?;
|
||||
core.save_active_tab_to_reading_list()?;
|
||||
|
||||
let snapshot = core.snapshot()?;
|
||||
let status = &snapshot.sync_status;
|
||||
@@ -22,6 +23,7 @@ fn default_sync_status_reflects_local_browser_state() -> Result<(), Box<dyn Erro
|
||||
SyncObjectStatus::new(SyncObjectKind::Spaces, 2, SyncObjectState::LocalOnly),
|
||||
SyncObjectStatus::new(SyncObjectKind::Tabs, 3, SyncObjectState::LocalOnly),
|
||||
SyncObjectStatus::new(SyncObjectKind::Bookmarks, 1, SyncObjectState::LocalOnly),
|
||||
SyncObjectStatus::new(SyncObjectKind::ReadingList, 1, SyncObjectState::LocalOnly),
|
||||
SyncObjectStatus::new(SyncObjectKind::Profiles, 1, SyncObjectState::LocalOnly),
|
||||
SyncObjectStatus::new(SyncObjectKind::History, 1, SyncObjectState::PrivacyControlled),
|
||||
SyncObjectStatus::new(SyncObjectKind::PluginSettings, 0, SyncObjectState::LocalOnly),
|
||||
|
||||
Reference in New Issue
Block a user