134 lines
3.9 KiB
Python
134 lines
3.9 KiB
Python
"""Tests for group.* commands."""
|
|
import pytest
|
|
from browser_cli.client import send_command
|
|
|
|
|
|
def test_group_list(browser):
|
|
groups = browser("group.list")
|
|
assert isinstance(groups, list)
|
|
|
|
|
|
def test_group_count_is_int(browser):
|
|
count = browser("group.count")
|
|
assert isinstance(count, int)
|
|
assert count >= 0
|
|
|
|
|
|
def test_group_count_matches_list(browser):
|
|
groups = browser("group.list")
|
|
count = browser("group.count")
|
|
assert count == len(groups)
|
|
|
|
|
|
def test_group_create_and_close(browser):
|
|
result = browser("group.open", {"name": "__test_group__"})
|
|
assert isinstance(result, dict)
|
|
gid = result["id"]
|
|
|
|
# Verify it appears in the list
|
|
groups = browser("group.list")
|
|
assert any(g["id"] == gid for g in groups)
|
|
|
|
# Get tabs inside so we can clean them up after ungrouping
|
|
tabs_in_group = browser("group.tabs", {"groupId": gid})
|
|
|
|
# Close (ungroup) the group
|
|
browser("group.close", {"groupId": gid})
|
|
|
|
# Group should be gone
|
|
groups_after = browser("group.list")
|
|
assert gid not in [g["id"] for g in groups_after]
|
|
|
|
# Clean up the ungrouped tabs
|
|
for t in tabs_in_group:
|
|
try:
|
|
browser("tabs.close", {"tabId": t["id"]})
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
def test_group_create_has_title(browser):
|
|
result = browser("group.open", {"name": "__titled_group__"})
|
|
gid = result["id"]
|
|
tabs_in_group = browser("group.tabs", {"groupId": gid})
|
|
|
|
try:
|
|
groups = browser("group.list")
|
|
match = next((g for g in groups if g["id"] == gid), None)
|
|
assert match is not None
|
|
assert match.get("title") == "__titled_group__"
|
|
assert match.get("tabCount", 0) >= 1
|
|
finally:
|
|
browser("group.close", {"groupId": gid})
|
|
for t in tabs_in_group:
|
|
try:
|
|
browser("tabs.close", {"tabId": t["id"]})
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
def test_group_query(browser):
|
|
result = browser("group.open", {"name": "__query_test__"})
|
|
gid = result["id"]
|
|
tabs_in_group = browser("group.tabs", {"groupId": gid})
|
|
|
|
try:
|
|
found = browser("group.query", {"search": "__query_test__"})
|
|
assert isinstance(found, list)
|
|
assert any(g["id"] == gid for g in found)
|
|
finally:
|
|
browser("group.close", {"groupId": gid})
|
|
for t in tabs_in_group:
|
|
try:
|
|
browser("tabs.close", {"tabId": t["id"]})
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
def test_group_query_no_match(browser):
|
|
result = browser("group.query", {"search": "zzz_no_such_group_zzz"})
|
|
assert isinstance(result, list)
|
|
assert len(result) == 0
|
|
|
|
|
|
def test_group_add_tab(browser):
|
|
grp = browser("group.open", {"name": "__add_tab_test__"})
|
|
gid = grp["id"]
|
|
initial_tabs = browser("group.tabs", {"groupId": gid})
|
|
|
|
try:
|
|
tab_result = browser("group.add_tab", {"group": str(gid), "url": "https://example.com"})
|
|
assert isinstance(tab_result, dict)
|
|
new_tab_id = tab_result["tabId"]
|
|
|
|
tabs = browser("group.tabs", {"groupId": gid})
|
|
assert any(t["id"] == new_tab_id for t in tabs)
|
|
finally:
|
|
all_tabs = browser("group.tabs", {"groupId": gid})
|
|
browser("group.close", {"groupId": gid})
|
|
for t in all_tabs + initial_tabs:
|
|
try:
|
|
browser("tabs.close", {"tabId": t["id"]})
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
def test_group_tabs_returns_list(browser):
|
|
grp = browser("group.open", {"name": "__tabs_list_test__"})
|
|
gid = grp["id"]
|
|
tabs_in_group = browser("group.tabs", {"groupId": gid})
|
|
|
|
try:
|
|
assert isinstance(tabs_in_group, list)
|
|
assert len(tabs_in_group) >= 1
|
|
for t in tabs_in_group:
|
|
assert "id" in t
|
|
assert "url" in t
|
|
finally:
|
|
browser("group.close", {"groupId": gid})
|
|
for t in tabs_in_group:
|
|
try:
|
|
browser("tabs.close", {"tabId": t["id"]})
|
|
except Exception:
|
|
pass
|