hikvisionSplitIcons.test.mjs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import assert from 'node:assert/strict'
  2. import { readFileSync } from 'node:fs'
  3. import { fileURLToPath } from 'node:url'
  4. import test from 'node:test'
  5. const icons = [
  6. ['grid-one', 1],
  7. ['grid-four', 2],
  8. ['grid-nine', 3],
  9. ['grid-16', 4]
  10. ]
  11. const page = readFileSync(
  12. new URL('../src/views/pms/video_center/haikang/index.vue', import.meta.url),
  13. 'utf8'
  14. )
  15. assert.match(page, /mask:\s*var\(--split-icon\)/, 'the split icons are rendered as CSS alpha masks')
  16. test('the SVG data URL is quoted before becoming a CSS mask URL', () => {
  17. const splitStyle = page.split('\n').find((line) => line.includes("'--split-icon':")) ?? ''
  18. assert.match(splitStyle, /'--split-icon':\s*toSplitIconUrl\(option\.icon\)/)
  19. assert.match(
  20. page,
  21. /function toSplitIconUrl\(icon: string\)\s*\{\s*return `url\("\$\{icon\}"\)`/,
  22. 'unquoted Vite SVG data URLs contain quotes and invalidate the mask declaration'
  23. )
  24. })
  25. for (const [iconName, columns] of icons) {
  26. test(`${iconName} draws ${columns}×${columns} hollow cells instead of solid blocks`, () => {
  27. const iconPath = new URL(`../src/assets/icons/${iconName}.svg`, import.meta.url)
  28. const svg = readFileSync(fileURLToPath(iconPath), 'utf8')
  29. const frame = svg.match(/<rect\b[^>]*>/g) ?? []
  30. const dividers = svg.match(/<line\b[^>]*>/g) ?? []
  31. assert.equal(frame.length, 1, 'the grid needs one outlined outer frame')
  32. assert.match(frame[0], /\bfill="none"/, 'the panel interiors must remain transparent')
  33. assert.match(frame[0], /\bstroke="currentColor"/, 'the frame must be visible in the mask')
  34. assert.equal(dividers.length, 2 * (columns - 1), 'each row and column needs a divider')
  35. for (const divider of dividers) assert.match(divider, /\bstroke="currentColor"/)
  36. assert.doesNotMatch(svg, /<path\b/, 'filled paths turn the mask back into solid tiles')
  37. })
  38. }