feat: 优化页面信息展示
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
from app.models import Comment, ContentItem, Hotspot, Report, Task
|
||||
from tests.helpers import make_test_client
|
||||
from sqlalchemy.exc import OperationalError
|
||||
@@ -59,6 +61,58 @@ def test_index_page_lists_existing_tasks():
|
||||
assert "DOMContentLoaded" in response.text
|
||||
|
||||
|
||||
def test_index_page_uses_short_task_numbers_compact_fields_and_friendly_error_copy():
|
||||
first_id = "11111111-1111-4111-8111-111111111111"
|
||||
second_id = "22222222-2222-4222-8222-222222222222"
|
||||
with make_test_client() as (client, engine):
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
with Session(engine) as session:
|
||||
session.add(
|
||||
Task(
|
||||
id=first_id,
|
||||
platform="xiaohongshu",
|
||||
status="failed",
|
||||
created_at=datetime(2026, 7, 3, 10, 30, tzinfo=UTC),
|
||||
hotspot_limit=5,
|
||||
item_limit_per_hotspot=5,
|
||||
comment_limit_per_item=50,
|
||||
error_stage="system",
|
||||
error_type="unexpected_restart",
|
||||
error_message="系统重启,任务被中断",
|
||||
)
|
||||
)
|
||||
session.add(
|
||||
Task(
|
||||
id=second_id,
|
||||
platform="douyin",
|
||||
status="success",
|
||||
created_at=datetime(2026, 7, 3, 10, 35, tzinfo=UTC),
|
||||
hotspot_limit=1,
|
||||
item_limit_per_hotspot=1,
|
||||
comment_limit_per_item=10,
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
|
||||
response = client.get("/")
|
||||
|
||||
assert response.status_code == 200
|
||||
visible_text = BeautifulSoup(response.text, "html.parser").get_text(" ")
|
||||
assert "#1" in visible_text
|
||||
assert "#2" in visible_text
|
||||
assert first_id not in visible_text
|
||||
assert second_id not in visible_text
|
||||
assert "2026-07-03 10:30" in visible_text
|
||||
assert "2026-07-03 10:35" in visible_text
|
||||
assert "小红书 · 5热点 × 5内容 × 50评论" in visible_text
|
||||
assert "抖音 · 1热点 × 1内容 × 10评论" in visible_text
|
||||
assert "系统重启,任务被中断" in visible_text
|
||||
assert "system / unexpected_restart" not in visible_text
|
||||
assert "unexpected_restart" not in visible_text
|
||||
assert "内部演示工具 | 仅供学习参考" not in visible_text
|
||||
|
||||
|
||||
def test_index_page_does_not_auto_poll_without_running_tasks():
|
||||
with make_test_client() as (client, engine):
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -117,6 +171,37 @@ def test_running_task_detail_page_auto_polls_current_task():
|
||||
assert "AI 成功率 100%" in response.text
|
||||
|
||||
|
||||
def test_task_detail_uses_short_number_title_and_keeps_full_uuid_for_diagnostics():
|
||||
task_id = "33333333-3333-4333-8333-333333333333"
|
||||
with make_test_client() as (client, engine):
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
with Session(engine) as session:
|
||||
session.add(
|
||||
Task(
|
||||
id=task_id,
|
||||
platform="xiaohongshu",
|
||||
status="running",
|
||||
created_at=datetime(2026, 7, 3, 10, 30, tzinfo=UTC),
|
||||
hotspot_limit=5,
|
||||
item_limit_per_hotspot=5,
|
||||
comment_limit_per_item=50,
|
||||
)
|
||||
)
|
||||
session.commit()
|
||||
|
||||
response = client.get(f"/tasks/{task_id}")
|
||||
|
||||
assert response.status_code == 200
|
||||
visible_text = BeautifulSoup(response.text, "html.parser").get_text(" ")
|
||||
assert "<title>任务 #1 - 热榜评论分析工具</title>" in response.text
|
||||
assert "任务 #1" in visible_text
|
||||
assert "完整 ID" in visible_text
|
||||
assert task_id in visible_text
|
||||
assert "任务 #33333333-3333-4333-8333-333333333333" not in visible_text
|
||||
assert "创建时间 2026-07-03 10:30" in visible_text
|
||||
|
||||
|
||||
def test_running_task_detail_page_keeps_polling_after_hotspots_exist():
|
||||
with make_test_client() as (client, engine):
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -241,7 +326,8 @@ def test_failed_task_detail_page_shows_failure_reason_without_loading_copy():
|
||||
|
||||
assert response.status_code == 200
|
||||
assert "失败" in response.text
|
||||
assert "recover / interrupted:系统重启,任务被中断" in response.text
|
||||
assert "系统重启,任务被中断" in response.text
|
||||
assert "recover / interrupted" not in response.text
|
||||
assert "正在抓取热点数据" not in response.text
|
||||
assert "pollTaskDetailStatus" not in response.text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user