Track archived tab state transitions
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::error::Error;
|
||||
|
||||
use ely_browser_core::{BrowserCore, CoreError, InitialBrowserConfig};
|
||||
use ely_domain::{CommandIntent, CommandScope, UrlText};
|
||||
use ely_domain::{CommandIntent, CommandScope, TabState, UrlText};
|
||||
|
||||
#[test]
|
||||
fn opens_new_tab_below_active_tab() -> Result<(), Box<dyn Error>> {
|
||||
@@ -38,6 +38,7 @@ fn closes_active_tab_and_selects_next_neighbor() -> Result<(), Box<dyn Error>> {
|
||||
assert_eq!(snapshot.active_tab_id, active_tab_id);
|
||||
assert_eq!(snapshot.archived_tabs.len(), 1);
|
||||
assert_eq!(snapshot.archived_tabs[0].tab().id(), &second_tab_id);
|
||||
assert_eq!(snapshot.archived_tabs[0].tab().state(), &TabState::Archived);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -69,7 +70,12 @@ fn restores_last_archived_tab() -> Result<(), Box<dyn Error>> {
|
||||
assert_eq!(restored_tab_id, closed_tab_id);
|
||||
assert_eq!(snapshot.active_tab_id, closed_tab_id);
|
||||
assert!(snapshot.archived_tabs.is_empty());
|
||||
assert!(snapshot.tabs.iter().any(|tab| tab.id() == &closed_tab_id));
|
||||
let restored_tab = snapshot
|
||||
.tabs
|
||||
.iter()
|
||||
.find(|tab| tab.id() == &closed_tab_id)
|
||||
.ok_or(CoreError::MissingActiveTab)?;
|
||||
assert_eq!(restored_tab.state(), &TabState::Ready);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,8 @@ pub struct ArchivedTab {
|
||||
|
||||
impl ArchivedTab {
|
||||
#[must_use]
|
||||
pub fn new(tab: BrowserTab, source: ArchiveSource) -> Self {
|
||||
pub fn new(mut tab: BrowserTab, source: ArchiveSource) -> Self {
|
||||
tab.mark_archived();
|
||||
Self { tab, archived_at: SystemTime::now(), source }
|
||||
}
|
||||
|
||||
@@ -38,6 +39,8 @@ impl ArchivedTab {
|
||||
|
||||
#[must_use]
|
||||
pub fn into_tab(self) -> BrowserTab {
|
||||
self.tab
|
||||
let mut tab = self.tab;
|
||||
tab.mark_ready();
|
||||
tab
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,14 @@ impl BrowserTab {
|
||||
&self.state
|
||||
}
|
||||
|
||||
pub fn mark_archived(&mut self) {
|
||||
self.state = TabState::Archived;
|
||||
}
|
||||
|
||||
pub fn mark_ready(&mut self) {
|
||||
self.state = TabState::Ready;
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn flags(&self) -> &TabFlags {
|
||||
&self.flags
|
||||
|
||||
Reference in New Issue
Block a user