detailDrawerRule.test.mjs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import assert from 'node:assert/strict'
  2. import { readdir, readFile } from 'node:fs/promises'
  3. import { join } from 'node:path'
  4. import test from 'node:test'
  5. async function listVueFiles(directory) {
  6. const entries = await readdir(directory, { withFileTypes: true })
  7. const files = await Promise.all(entries.map(entry => {
  8. const path = join(directory, entry.name)
  9. return entry.isDirectory() ? listVueFiles(path) : path.endsWith('.vue') ? [path] : []
  10. }))
  11. return files.flat()
  12. }
  13. test('all read-only detail views use the shared right-side drawer', async () => {
  14. const views = await listVueFiles('src/views')
  15. for (const view of views) {
  16. const source = await readFile(view, 'utf8')
  17. const detailDialogs = source.match(/<el-dialog\b[^>]*(?:详情|详细|查看|预览|报警位置地图|视频查看|研判分析|催办记录|监测告警联动|全屏监控)[^>]*>/gu) || []
  18. assert.deepEqual(detailDialogs, [], view)
  19. const drawers = source.match(/<el-drawer\b[^>]*>/gu) || []
  20. for (const drawer of drawers) {
  21. assert.match(drawer, /direction=["']rtl["']/u, `${view}: ${drawer}`)
  22. if (!drawer.includes('facility-form-drawer')) {
  23. assert.match(drawer, /class=["'][^"']*detail-drawer/u, `${view}: ${drawer}`)
  24. }
  25. }
  26. }
  27. })
  28. test('operation forms remain dialogs instead of being treated as read-only details', async () => {
  29. const devicePage = await readFile('src/views/subSystem/waterSupply/components/WaterDevicePage.vue', 'utf8')
  30. const alarmPage = await readFile('src/views/subSystem/waterSupply/components/WaterAlarmPage.vue', 'utf8')
  31. assert.match(devicePage, /<el-dialog[^>]*title="设备维修派单"/u)
  32. assert.match(alarmPage, /<el-dialog[^>]*title="报警维修派单"/u)
  33. })
  34. test('water facility edit forms and table actions use the shared drawer and action styles', async () => {
  35. const facilityViews = [
  36. 'src/views/subSystem/basic/pipeInfo/index.vue',
  37. 'src/views/subSystem/basic/pumpStation/index.vue',
  38. 'src/views/subSystem/basic/waterPlant/index.vue',
  39. 'src/views/subSystem/basic/waterSource/index.vue',
  40. 'src/views/subSystem/basic/waterUserInfo/index.vue'
  41. ]
  42. for (const view of facilityViews) {
  43. const source = await readFile(view, 'utf8')
  44. assert.match(source, /<el-drawer[^>]*:title="dialogTitle"[^>]*class="facility-form-drawer"[^>]*direction="rtl"/u, view)
  45. assert.match(source, /class="facility-row-actions"/u, view)
  46. assert.match(source, /class="facility-row-action is-detail"/u, view)
  47. assert.match(source, /class="facility-row-action is-edit"/u, view)
  48. assert.match(source, /class="facility-row-action is-delete"/u, view)
  49. }
  50. })