"""Test /dashboard page rendering and structure""" 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 def test_dashboard_page_returns_200(client): """Dashboard page serves HTTP 200""" r = client.get('/dashboard') assert r.status_code == 200 def test_dashboard_page_has_title(client): """Dashboard page contains expected title""" r = client.get('/dashboard') html = r.data.decode('utf-8') assert '数据看板' in html, "Missing 数据看板 title" def test_dashboard_page_has_fetch(client): """Dashboard page JS fetches /api/dashboard""" r = client.get('/dashboard') html = r.data.decode('utf-8') assert '/api/dashboard' in html, "Missing /api/dashboard API call" def test_dashboard_page_no_style_backslash_bug(client): """Dashboard page has no style=\\\\\\\\' escaping bug""" r = client.get('/dashboard') html = r.data.decode('utf-8') # Check for the known-common escaping bug patterns assert "style=\\\\\\\\'" not in html, "STYLE BACKSLASH BUG in dashboard.html" assert "style=\\\\\\\\\\\\'" not in html, "STYLE TRIPLE BACKSLASH BUG in dashboard.html" def test_dashboard_page_has_auto_refresh(client): """Dashboard page auto-refreshes (setInterval or similar)""" r = client.get('/dashboard') html = r.data.decode('utf-8') assert 'setInterval' in html or 'setTimeout' in html, \ "Missing auto-refresh mechanism" def test_dashboard_page_has_card_elements(client): """Dashboard page has card containers for modules""" r = client.get('/dashboard') html = r.data.decode('utf-8') # Should have card-like structure assert 'dashboard' in html.lower(), "Missing dashboard identifier" if __name__ == '__main__': pytest.main([__file__, '-v'])