97 lines
3.5 KiB
Python
97 lines
3.5 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
# -*- coding: utf-8 -*-
|
||
|
|
"""
|
||
|
|
验证二级节点region_name标签隐藏逻辑
|
||
|
|
"""
|
||
|
|
|
||
|
|
from playwright.sync_api import sync_playwright
|
||
|
|
import time
|
||
|
|
|
||
|
|
def test_region_name_hiding():
|
||
|
|
with sync_playwright() as p:
|
||
|
|
browser = p.chromium.launch(headless=True)
|
||
|
|
page = browser.new_page()
|
||
|
|
|
||
|
|
try:
|
||
|
|
# 访问超级管理员页面
|
||
|
|
print("正在访问超级管理员页面...")
|
||
|
|
page.goto('http://127.0.0.1:8000/static/super_admin.html', wait_until='networkidle', timeout=30000)
|
||
|
|
time.sleep(2)
|
||
|
|
|
||
|
|
# 切换到组织架构标签页
|
||
|
|
print("切换到组织架构标签页...")
|
||
|
|
org_tab = page.locator('button.tab-button[data-tab="org-chart-tab"]')
|
||
|
|
if org_tab.is_visible():
|
||
|
|
org_tab.click()
|
||
|
|
time.sleep(3)
|
||
|
|
|
||
|
|
# 检查是否有数据加载
|
||
|
|
loading_text = page.locator('.loading')
|
||
|
|
if loading_text.is_visible():
|
||
|
|
print("加载中...")
|
||
|
|
# 等待数据加载完成
|
||
|
|
time.sleep(5)
|
||
|
|
|
||
|
|
print("\n=== 检查二级节点标签显示情况 ===")
|
||
|
|
|
||
|
|
# 查找所有二级节点
|
||
|
|
level1_nodes = page.locator('.org-node[data-level="1"]').all()
|
||
|
|
print(f"找到 {len(level1_nodes)} 个二级节点")
|
||
|
|
|
||
|
|
for i, node in enumerate(level1_nodes):
|
||
|
|
node_name = node.locator('.node-name').text_content()
|
||
|
|
region_tags = node.locator('.node-region').all()
|
||
|
|
has_region_tag = len(region_tags) > 0
|
||
|
|
|
||
|
|
# 检查名称是否包含"区"字
|
||
|
|
has_district_char = '区' in node_name
|
||
|
|
|
||
|
|
status = "隐藏" if (has_district_char and not has_region_tag) else "显示"
|
||
|
|
expected = "隐藏" if has_district_char else "显示"
|
||
|
|
|
||
|
|
print(f"\n{i+1}. {node_name}:")
|
||
|
|
print(f" - 名称包含'区'字: {has_district_char}")
|
||
|
|
print(f" - region_name标签: {status}")
|
||
|
|
print(f" - 预期: {expected}")
|
||
|
|
|
||
|
|
if status == expected:
|
||
|
|
print(f" [OK] 符合预期")
|
||
|
|
else:
|
||
|
|
print(f" [ERROR] 不符合预期!")
|
||
|
|
|
||
|
|
# 检查顺德区节点
|
||
|
|
print("\n=== 重点检查顺德区服务部门 ===")
|
||
|
|
shunde_node = None
|
||
|
|
for node in level1_nodes:
|
||
|
|
if '顺德' in node.locator('.node-name').text_content():
|
||
|
|
shunde_node = node
|
||
|
|
break
|
||
|
|
|
||
|
|
if shunde_node:
|
||
|
|
node_name = shunde_node.locator('.node-name').text_content()
|
||
|
|
region_tags = shunde_node.locator('.node-region').all()
|
||
|
|
has_region_tag = len(region_tags) > 0
|
||
|
|
|
||
|
|
print(f"节点名称: {node_name}")
|
||
|
|
print(f"是否显示'顺德区'标签: {has_region_tag}")
|
||
|
|
|
||
|
|
if not has_region_tag:
|
||
|
|
print("[OK] 顺德区服务部门不再显示冗余的'顺德区'标签!")
|
||
|
|
else:
|
||
|
|
print("[ERROR] 顺德区服务部门仍显示冗余标签!")
|
||
|
|
|
||
|
|
# 截图查看效果
|
||
|
|
page.screenshot(path='/tmp/org_chart_fixed.png', full_page=True)
|
||
|
|
print("\n截图已保存到 /tmp/org_chart_fixed.png")
|
||
|
|
|
||
|
|
except Exception as e:
|
||
|
|
print(f"测试过程中出现错误: {e}")
|
||
|
|
import traceback
|
||
|
|
traceback.print_exc()
|
||
|
|
|
||
|
|
finally:
|
||
|
|
browser.close()
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
test_region_name_hiding()
|