dy-dashboard/tests/test_dashboard_cost_tooltips.py
2026-10-28 11:14:17 +08:00

38 lines
1.6 KiB
Python

"""数据概览成本卡片统计逻辑提示回归测试。"""
import unittest
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
APP = (ROOT / 'static' / 'js' / 'app.js').read_text(encoding='utf-8')
CSS = (ROOT / 'static' / 'css' / 'style.css').read_text(encoding='utf-8')
class DashboardCostTooltipTest(unittest.TestCase):
def test_all_nine_cost_rows_render_help_eye(self):
self.assertIn('renderCostLogicEye(label)', APP)
self.assertIn('stat-cost-eye', APP)
cards = [
"renderCostBreakdown(['总成本', '成品成本', '包材成本']",
"renderCostBreakdown(['成品成本', '成品库存成本', '成品在途成本']",
"renderCostBreakdown(['包材成本', '包材库存成本', '包材在途成本']",
]
for card in cards:
self.assertIn(card, APP)
def test_each_unique_field_has_clear_logic(self):
for label in ('总成本', '成品成本', '包材成本', '成品库存成本',
'成品在途成本', '包材库存成本', '包材在途成本'):
self.assertIn("'%s': {" % label, APP)
for section in ('计算公式:', '统计范围:', '特别说明:'):
self.assertIn(section, APP)
def test_tooltip_supports_hover_and_keyboard_focus(self):
self.assertIn('tabindex="0"', APP)
self.assertIn('.stat-cost-help:hover .stat-cost-tooltip', CSS)
self.assertIn('.stat-cost-help:focus .stat-cost-tooltip', CSS)
self.assertIn('role="tooltip"', APP)
if __name__ == '__main__':
unittest.main()