Files
daniel156161 a9071abc9a
Package Extension / package-extension (push) Successful in 24s
Build & Publish Package / publish (push) Successful in 31s
Testing / test (push) Successful in 26s
cleanup tests
2026-05-02 01:48:13 +02:00

191 lines
5.9 KiB
Python

"""Tests for group.* commands."""
import pytest
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
def test_group_move_forward_swaps_adjacent_group_blocks(browser):
group_a = browser("group.open", {"name": "__move_group_a__"})
group_b = browser("group.open", {"name": "__move_group_b__"})
gid_a = group_a["id"]
gid_b = group_b["id"]
created_tab_ids = set()
try:
extra_a = browser("group.add_tab", {"group": str(gid_a), "url": "https://example.com/?group=a"})
extra_b = browser("group.add_tab", {"group": str(gid_b), "url": "https://example.com/?group=b"})
created_tab_ids.update([extra_a["tabId"], extra_b["tabId"]])
tabs_before = browser("tabs.list")
block_order_before = [
t["groupId"] for t in tabs_before
if t.get("groupId") in {gid_a, gid_b}
]
assert block_order_before
assert block_order_before[0] == gid_a
browser("group.move", {"group": str(gid_a), "forward": True})
tabs_after = browser("tabs.list")
grouped_after = [
t for t in tabs_after
if t.get("groupId") in {gid_a, gid_b}
]
assert grouped_after
assert grouped_after[0]["groupId"] == gid_b
assert grouped_after[-1]["groupId"] == gid_a
group_ids_after = {t["id"]: t["groupId"] for t in grouped_after}
for t in browser("group.tabs", {"groupId": gid_a}):
assert group_ids_after[t["id"]] == gid_a
for t in browser("group.tabs", {"groupId": gid_b}):
assert group_ids_after[t["id"]] == gid_b
finally:
for gid in (gid_a, gid_b):
try:
group_tabs = browser("group.tabs", {"groupId": gid})
except Exception:
group_tabs = []
try:
browser("group.close", {"groupId": gid})
except Exception:
pass
for t in group_tabs:
created_tab_ids.add(t["id"])
for tab_id in created_tab_ids:
try:
browser("tabs.close", {"tabId": tab_id})
except Exception:
pass