feat: add seed helpers for gist, news, and project comment hierarchies in e2e tests

Introduce `_seed_gist_with_comments`, `_seed_news_with_comments`, and `_seed_project_with_comments` helper functions that create a user, a parent entity, and four comments (excluded, flat, parent, reply) with a shared marker prefix and timestamps, enabling consistent comment tree seeding across test modules.
This commit is contained in:
2026-06-16 04:06:16 +00:00
parent 15bd4ad87c
commit 1934dd5727
3 changed files with 210 additions and 0 deletions
+73
View File
@@ -313,3 +313,76 @@ def test_news_detail_image_has_alt_text(page, app_server):
page.goto(f"{BASE_URL}/news/{slug}", wait_until="domcontentloaded")
alt = page.locator(".news-detail-image img").get_attribute("alt")
assert alt and alt.strip()
def _seed_news_with_comments():
owner = str(uuid4())
get_table("users").insert(
{
"uid": owner,
"username": f"ncseed_{owner[:8]}",
"email": f"{owner[:8]}@nc.seed",
"password_hash": "x",
"role": "Member",
"is_active": True,
"created_at": datetime.now(timezone.utc).isoformat(),
}
)
uid = str(uuid4())
marker = f"newscom-{uid[:8]}"
get_table("news").insert(
{
"deleted_at": None,
"deleted_by": None,
"uid": uid,
"slug": make_combined_slug(marker, uid),
"title": marker,
"description": "News with comment hierarchy.",
"content": "Body.",
"url": "https://example.com/nc",
"source_name": "NCSource",
"external_id": f"nc_{uid[:8]}",
"status": "published",
"show_on_landing": 0,
"grade": 10,
"synced_at": datetime.now(timezone.utc).isoformat(),
}
)
parent = str(uuid4())
base = datetime.now(timezone.utc)
rows = [
(f"{marker}-excluded", str(uuid4()), None, -2),
(f"{marker}-flat", str(uuid4()), None, -1),
(f"{marker}-parent", parent, None, 0),
(f"{marker}-reply", str(uuid4()), parent, 1),
]
comments = get_table("comments")
for content, cuid, par, off in rows:
comments.insert(
{
"deleted_at": None,
"deleted_by": None,
"uid": cuid,
"target_type": "news",
"target_uid": uid,
"user_uid": owner,
"content": content,
"parent_uid": par,
"created_at": (base + timedelta(seconds=off)).isoformat(),
}
)
return marker
def test_news_list_preserves_comment_hierarchy(page, app_server):
from playwright.sync_api import expect
marker = _seed_news_with_comments()
page.goto(f"{BASE_URL}/news", wait_until="domcontentloaded")
card = page.locator(".news-card").filter(has_text=marker).first
card.wait_for(state="visible")
previews = card.locator(".post-card-comments .comment-text")
expect(previews).to_have_count(3)
expect(card.locator(".post-card-comments")).not_to_contain_text(f"{marker}-excluded")
nested = card.locator(".post-card-comments .comment-replies .comment-text")
expect(nested).to_contain_text(f"{marker}-reply")