Track tab sort keys
This commit is contained in:
@@ -22,6 +22,39 @@ fn opens_new_tab_below_active_tab() -> Result<(), Box<dyn Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opened_tabs_receive_visible_sort_keys() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let first_tab_id = core.active_tab()?.id().clone();
|
||||
let second_tab_id = core.open_tab(UrlText::parse("https://example.com")?);
|
||||
|
||||
core.select_tab(&first_tab_id)?;
|
||||
let third_tab_id = core.open_tab(UrlText::parse("https://servo.org")?);
|
||||
let snapshot = core.snapshot()?;
|
||||
let ordered =
|
||||
snapshot.tabs.iter().map(|tab| (tab.id().clone(), tab.sort_key())).collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(ordered, vec![(first_tab_id, 0), (third_tab_id, 1), (second_tab_id, 2)]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapshot_orders_tabs_by_sort_key() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
let first_tab_id = core.active_tab()?.id().clone();
|
||||
let second_tab_id = core.open_tab(UrlText::parse("https://example.com")?);
|
||||
let third_tab_id = core.open_tab(UrlText::parse("https://servo.org")?);
|
||||
|
||||
core.set_tab_sort_key(&second_tab_id, 30)?;
|
||||
core.set_tab_sort_key(&third_tab_id, 10)?;
|
||||
core.set_tab_sort_key(&first_tab_id, 20)?;
|
||||
let snapshot = core.snapshot()?;
|
||||
let ordered_ids = snapshot.tabs.iter().map(|tab| tab.id().clone()).collect::<Vec<_>>();
|
||||
|
||||
assert_eq!(ordered_ids, vec![third_tab_id, first_tab_id, second_tab_id]);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn opened_tabs_record_active_tab_as_parent() -> Result<(), Box<dyn Error>> {
|
||||
let mut core = BrowserCore::new(InitialBrowserConfig::ely_defaults()?)?;
|
||||
|
||||
Reference in New Issue
Block a user