waterAlarmLayout.test.mjs 1.7 KB

12345678910111213141516171819202122232425262728293031323334
  1. import assert from 'node:assert/strict'
  2. import { readFile } from 'node:fs/promises'
  3. import test from 'node:test'
  4. import postcss from 'postcss'
  5. import { parse } from '@vue/compiler-sfc'
  6. const pagePath = new URL('../src/views/subSystem/waterSupply/components/WaterAlarmPage.vue', import.meta.url)
  7. const themePath = new URL('../src/views/subSystem/waterSupply/components/waterSupplyPageTheme.scss', import.meta.url)
  8. async function effectiveDeclarations(selector) {
  9. const { descriptor } = parse(await readFile(pagePath, 'utf8'))
  10. const sharedTheme = await readFile(themePath, 'utf8')
  11. const scopedStyle = descriptor.styles.find(style => style.scoped)?.content || ''
  12. const declarations = {}
  13. // 实际页面在全局共享主题之后加载 scoped 页面样式;同名选择器按顺序覆盖。
  14. postcss.parse(`${sharedTheme}\n${scopedStyle}`).walkRules(rule => {
  15. if (!rule.selectors.some(item => item.trim() === selector)) return
  16. rule.walkDecls(decl => { declarations[decl.prop] = decl.value })
  17. })
  18. return declarations
  19. }
  20. test('alarm metric icon remains in flex flow when the shared page theme is loaded', async () => {
  21. const icon = await effectiveDeclarations('.metric-icon')
  22. const card = await effectiveDeclarations('.metric')
  23. assert.equal(icon.position, 'static', '绝对定位会让图标脱离卡片弹性布局,与数字文字重叠')
  24. assert.match(card.display || '', /flex/u)
  25. })
  26. test('alarm filter title keeps its text adjacent to the search icon', async () => {
  27. const heading = await effectiveDeclarations('.card-title')
  28. assert.equal(heading['justify-content'], 'flex-start', 'space-between 会将标题推到筛选卡片右侧')
  29. assert.ok(Number.parseFloat(heading.gap) > 0)
  30. })