test_nav_dashboard.py
1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Test dashboard navigation link in all pages"""
import pytest
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from app import app as flask_app
@pytest.fixture
def client():
flask_app.config['TESTING'] = True
with flask_app.test_client() as c:
yield c
# Pages that should show the dashboard nav link
PAGES = [
"/",
"/articles",
"/reports",
"/jobs",
"/learn",
"/whitelist",
"/approvals",
"/dashboard",
"/circle",
]
def test_dashboard_nav_in_all_pages(client):
"""Dashboard link appears in all page navigations"""
for page in PAGES:
r = client.get(page)
html = r.data.decode('utf-8')
msg = f"Missing dashboard link on {page}"
assert '📊' in html and '数据看板' in html and 'href="/dashboard"' in html, msg
def test_dashboard_nav_active_on_dashboard(client):
"""Dashboard nav item is active/highlighted on /dashboard page"""
r = client.get('/dashboard')
html = r.data.decode('utf-8')
# Active class should be on the dashboard link
assert '/dashboard' in html
# The dashboard link should have the 'active' class
assert 'dashboard' in html
def test_existing_nav_items_still_present(client):
"""Existing nav items are not broken"""
r = client.get('/')
html = r.data.decode('utf-8')
existing_items = ['消息浏览', '文章列表', '日报列表', '任务监控', '学习审核']
for item in existing_items:
assert item in html, f"Missing existing nav item: {item}"
if __name__ == '__main__':
pytest.main([__file__, '-v'])