Files
halo-ops-audit/plugin-operation-audit/ui/src/views/AuditLogList.mobile.spec.ts
T
836061373 34764c7641 fix: 操作审计移动端改为题头+横向滚动,修复 :deep 作用域失配
上一轮「隐藏题头 + 数据行纵向堆叠」在真机上整批失效:VEntity 是
多根 Fragment 组件(tr + 可选 footer tr),其 <tr> 拿不到本组件的
scoped 作用域 ID,所有锚定 .audit-row 的 :deep 规则永远无法匹配
(Vue 仅在元素为组件 subTree 根时附加父作用域 ID),窄屏下字段仍按
固定列宽横排并被视口截断,且横向滑动也被控制台裁剪。

改为窄屏保持「题头 + 固定列宽」的表格形态:
- 题头与数据行置于同一横向滚动容器 .audit-list(overflow-x: auto,
  同官方 EntityList 的 w-full overflow-x-auto 模式),整体左右
  滑动看全六列,列对齐关系与桌面一致;容器够宽时无滚动条
- .audit-header 增加 min-width: max-content(下划线随内容延伸,
  滑动后不断裂)、.header-col 增加 flex-shrink: 0(列不被压缩)
- 行悬停手型改为锚定自身元素 .audit-list 经 :deep 穿透到
  entity-wrapper,并移除永远失配的 .audit-row 选择器
- 筛选栏窄屏 2 列(≤480px 单列)、分页条换行等此前已生效的
  适配保持不变

重写 AuditLogList.mobile.spec.ts:新增滚动容器/题头可见/列不收缩/
无失效堆叠规则等断言,防止失效方案回归;并在浏览器中于 390×844、
1280×800 与 1024px+侧栏三种宽度下验证横向滑动与列对齐。
2026-11-22 16:27:43 +08:00

129 lines
5.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { readFileSync } from 'node:fs'
import { fileURLToPath } from 'node:url'
import { describe, expect, it } from 'vitest'
// 移动端适配结构性回归测试:不渲染组件,仅检查 SFC 源码。
// 固定列宽列表合计约 69.5rem,窄屏(≤1023px:手机横竖屏 / 平板竖屏 / 半屏小窗口)
// 下必然超出视口:题头与数据行置于同一横向滚动容器(.audit-list)整体左右滑动,
// 列对齐关系与桌面一致;筛选栏窄屏 2 列(≤480px 手机竖屏单列)、分页条允许换行;
// ≥1024px 维持桌面布局不变。
// 特别注意:VEntity 是多根 Fragment 组件(tr + 可选 footer tr),其 <tr> 拿不到
// 本组件的 scoped 作用域 ID,所有锚定 .audit-row / 行内元素 :deep 的 scoped 规则
// 永远失配(历史上「隐藏题头 + 数据行纵向堆叠」方案因此整批失效——窄屏下字段
// 仍按固定列宽横排并被视口截断),行内样式必须锚定自身元素 .audit-list 穿透,
// 本测试防止该失效方案被重新引入。
const sfc = readFileSync(fileURLToPath(new URL('./AuditLogList.vue', import.meta.url)), 'utf-8')
const MOBILE_QUERY = '@media (max-width: 1023px)'
/** 提取 max-width: 1023px 媒体查询块全文(大括号配平)。 */
function mobileBlock(): string {
const start = sfc.indexOf(MOBILE_QUERY)
expect(start, `缺少 ${MOBILE_QUERY} 媒体查询`).toBeGreaterThan(-1)
let depth = 0
let end = -1
for (let i = sfc.indexOf('{', start); i < sfc.length; i++) {
if (sfc[i] === '{') depth++
else if (sfc[i] === '}') {
depth--
if (depth === 0) {
end = i
break
}
}
}
return sfc.slice(start, end)
}
/** 在指定文本块内取某选择器的规则体(自 from 起首个匹配)。 */
function ruleIn(block: string, selector: string, from = 0): string {
const start = block.indexOf(`${selector} {`, from)
expect(start, `块中缺少 ${selector} 规则`).toBeGreaterThan(-1)
const end = block.indexOf('}', start)
return block.slice(start, end)
}
/** 取全局(非媒体查询)样式中某选择器的规则体。 */
function styleRule(selector: string): string {
const start = sfc.indexOf(`${selector} {`)
expect(start, `缺少 ${selector} 样式规则`).toBeGreaterThan(-1)
const end = sfc.indexOf('}', start)
return sfc.slice(start, end)
}
describe('AuditLogList 移动端适配', () => {
it('存在 ≤1023px 窄屏断点,且位于桌面规则之后(同特异性按顺序覆盖才生效)', () => {
const mediaStart = sfc.indexOf(MOBILE_QUERY)
const desktopGrid = sfc.indexOf('.filter-grid {')
expect(desktopGrid).toBeGreaterThan(-1)
expect(mediaStart).toBeGreaterThan(desktopGrid)
})
it('窄屏筛选栏改为 2 列,操作按钮独占整行并拉伸铺满', () => {
const grid = ruleIn(mobileBlock(), '.filter-grid')
expect(grid).toMatch(/grid-template-columns:\s*repeat\(2,\s*minmax\(0,\s*1fr\)\)/)
const actions = ruleIn(mobileBlock(), '.filter-actions')
expect(actions).toMatch(/grid-column:\s*1\s*\/\s*-1/)
const stretch = ruleIn(mobileBlock(), '.filter-actions > :deep(*)')
expect(stretch).toMatch(/flex:\s*1/)
})
it('手机竖屏(≤480px)筛选栏单列,datetime-local 不被压扁', () => {
const start = sfc.indexOf('@media (max-width: 480px)')
expect(start, '缺少 ≤480px 单列断点').toBeGreaterThan(-1)
expect(sfc.slice(start)).toMatch(
/grid-template-columns:\s*minmax\(0,\s*1fr\)/,
)
})
it('题头与数据行置于同一横向滚动容器(.audit-list overflow-x: auto)', () => {
// 模板顺序:.audit-list 包裹 .audit-header 与全部 VEntity 数据行,
// 滑动时题头与数据列保持对齐
const listStart = sfc.indexOf('<div class="audit-list">')
expect(listStart, '缺少 .audit-list 滚动容器').toBeGreaterThan(-1)
const headerStart = sfc.indexOf('<div class="audit-header">')
const entityStart = sfc.indexOf('<VEntity')
const listEnd = sfc.indexOf('</div>\n </template>', listStart)
expect(headerStart).toBeGreaterThan(listStart)
expect(entityStart).toBeGreaterThan(headerStart)
expect(listEnd).toBeGreaterThan(entityStart)
const rule = styleRule('.audit-list')
expect(rule).toMatch(/overflow-x:\s*auto/)
})
it('窄屏不隐藏列题头(题头随容器滑动,列对齐关系不变)', () => {
// 历史方案曾在窄屏 display: none 隐藏题头,导致用户失去列语义,防止回归
const headerRule = styleRule('.audit-header')
expect(headerRule).not.toMatch(/display:\s*none/)
expect(mobileBlock()).not.toContain('.audit-header')
})
it('题头在滚动容器内随内容延伸且列宽不收缩(滑动后下划线不断裂、不与数据列错位)', () => {
const header = styleRule('.audit-header')
expect(header).toMatch(/min-width:\s*max-content/)
const col = styleRule('.header-col')
expect(col).toMatch(/flex-shrink:\s*0/)
})
it('数据行保持固定列宽表格形态,无失效的行内堆叠样式', () => {
// VEntity 的 <tr> 拿不到本组件 scoped 作用域 ID,锚定 .audit-row 的规则永远失配;
// 窄屏块内不得出现任何 entity 行内 :deep 规则,全文件不得再有 .audit-row 选择器
// (选择器须位于行首或上一规则之后,注释中的历史说明不受限)
expect(mobileBlock()).not.toContain('entity-')
expect(sfc).not.toMatch(/(?:^|[},;])\s*\.audit-row[\s:{]/)
})
it('行悬停手型经自身元素 .audit-list 穿透到 VEntity 行', () => {
const rule = styleRule('.audit-list :deep(.entity-wrapper)')
expect(rule).toMatch(/cursor:\s*pointer/)
})
it('窄屏分页条允许换行(总数与翻页控制器不横向溢出)', () => {
const rule = ruleIn(
mobileBlock(),
'.audit-pagination :deep(.pagination),\n .audit-pagination :deep(.pagination__controller)',
)
expect(rule).toMatch(/flex-wrap:\s*wrap/)
})
})