58 行
3.1 KiB
Python
58 行
3.1 KiB
Python
"""
|
||
测试首页高端主视觉系统 (Test Premium Home Hero Visual)
|
||
验证宽幅首屏摄影的高清画质、响应式图片源、桌面与移动端一致引用、
|
||
无文字遮挡的渐变处理、响应式断点与减少动态效果适配。
|
||
"""
|
||
|
||
import os
|
||
import unittest
|
||
|
||
from PIL import Image
|
||
|
||
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
|
||
HERO_IMAGE_DIR = os.path.join(ROOT_DIR, "public", "assets", "addons", "official", "images", "home")
|
||
CSS_PATH = os.path.join(ROOT_DIR, "public", "assets", "addons", "official", "css", "home-v3.css")
|
||
PC_HOME_PATH = os.path.join(ROOT_DIR, "addons", "official", "view", "web", "official_home", "index.html")
|
||
M_HOME_PATH = os.path.join(ROOT_DIR, "addons", "official", "view", "web", "official_home", "index_e.html")
|
||
|
||
|
||
class PremiumHeroBannerTest(unittest.TestCase):
|
||
"""验证首页宽幅主视觉"""
|
||
|
||
def test_01_hero_image_high_quality(self):
|
||
"""1. 验证首屏宽幅摄影物理存在、分辨率高、画质饱满"""
|
||
hero_path = os.path.join(HERO_IMAGE_DIR, "river-courtyard-v3.jpg")
|
||
self.assertTrue(os.path.exists(hero_path), "首屏宽幅摄影不存在")
|
||
self.assertGreater(os.path.getsize(hero_path), 150 * 1024, "首屏摄影文件过小")
|
||
|
||
with Image.open(hero_path) as hero:
|
||
width, height = hero.size
|
||
self.assertGreaterEqual(width, 1800, "首屏摄影宽度不足宽幅要求")
|
||
self.assertGreaterEqual(height, 700, "首屏摄影高度不足首屏要求")
|
||
|
||
def test_02_css_uses_responsive_hero_and_accessible_motion(self):
|
||
"""2. 验证专属 CSS 提供首屏布局、响应式断点与减少动态效果适配"""
|
||
with open(CSS_PATH, encoding="utf-8") as stream:
|
||
css_content = stream.read()
|
||
|
||
self.assertIn(".hn-hero-picture", css_content, "CSS 未正确定义首屏图片容器")
|
||
self.assertIn("object-fit", css_content, "CSS 应规范首屏图片的适应展示模式")
|
||
self.assertIn("linear-gradient", css_content, "CSS 应使用渐变为文字保留可读区域")
|
||
self.assertIn("@media(max-width:768px)", css_content, "CSS 缺少移动端首屏适配断点")
|
||
self.assertIn("prefers-reduced-motion", css_content, "CSS 应支持减少动态效果")
|
||
|
||
def test_03_pc_and_mobile_template_integrity(self):
|
||
"""3. 验证 PC 与移动端模板引用同一套响应式首屏图片"""
|
||
for page_path in [PC_HOME_PATH, M_HOME_PATH]:
|
||
with open(page_path, encoding="utf-8") as stream:
|
||
html = stream.read()
|
||
self.assertEqual(html.count("hn-hero-picture"), 1, f"首屏图片容器数量应为 1:{page_path}")
|
||
self.assertIn("river-courtyard-v3.webp", html, f"页面缺少 WebP 首屏图片源:{page_path}")
|
||
self.assertIn("river-courtyard-v3.jpg", html, f"页面缺少 JPEG 首屏图片回退:{page_path}")
|
||
self.assertIn('fetchpriority="high"', html, f"首屏图片应优先加载:{page_path}")
|
||
self.assertRegex(html, r'<img[^>]+alt="[^"]{4,}"', f"首屏图片应包含有效替代文本:{page_path}")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
unittest.main()
|