detailDrawerRule.test.mjs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. const waterSupplyViewDirs = [
  14. 'src/views/subSystem/waterSupply',
  15. 'src/views/subSystem/basic/pipeInfo',
  16. 'src/views/subSystem/basic/pumpStation',
  17. 'src/views/subSystem/basic/waterPlant',
  18. 'src/views/subSystem/basic/waterSource',
  19. 'src/views/subSystem/basic/waterUserInfo'
  20. ]
  21. test('all read-only detail views use the shared right-side drawer', async () => {
  22. for (const dir of waterSupplyViewDirs) {
  23. const views = await listVueFiles(dir)
  24. for (const view of views) {
  25. const source = await readFile(view, 'utf8')
  26. const detailDialogs = source.match(/<el-dialog\b[^>]*(?:详情|详细|查看|预览|报警位置地图|视频查看|研判分析|催办记录|监测告警联动|全屏监控)[^>]*>/gu) || []
  27. assert.deepEqual(detailDialogs, [], view)
  28. const drawers = source.match(/<el-drawer\b[^>]*>/gu) || []
  29. for (const drawer of drawers) {
  30. assert.match(drawer, /direction=["']rtl["']/u, `${view}: ${drawer}`)
  31. if (!drawer.includes('facility-form-drawer')) {
  32. assert.match(drawer, /class=["'][^"']*detail-drawer/u, `${view}: ${drawer}`)
  33. }
  34. }
  35. }
  36. }
  37. })
  38. test('operation forms remain dialogs instead of being treated as read-only details', async () => {
  39. const devicePage = await readFile('src/views/subSystem/waterSupply/components/WaterDevicePage.vue', 'utf8')
  40. const alarmPage = await readFile('src/views/subSystem/waterSupply/components/WaterAlarmPage.vue', 'utf8')
  41. assert.match(devicePage, /<el-dialog[^>]*title="设备维修派单"/u)
  42. assert.match(alarmPage, /<el-dialog[^>]*title="报警维修派单"/u)
  43. })
  44. test('water facility edit forms and table actions use the shared drawer and action styles', async () => {
  45. const facilityViews = [
  46. 'src/views/subSystem/basic/pipeInfo/index.vue',
  47. 'src/views/subSystem/basic/pumpStation/index.vue',
  48. 'src/views/subSystem/basic/waterPlant/index.vue',
  49. 'src/views/subSystem/basic/waterSource/index.vue',
  50. 'src/views/subSystem/basic/waterUserInfo/index.vue'
  51. ]
  52. for (const view of facilityViews) {
  53. const source = await readFile(view, 'utf8')
  54. assert.match(source, /<el-drawer[^>]*:title="dialogTitle"[^>]*class="facility-form-drawer"[^>]*direction="rtl"/u, view)
  55. assert.match(source, /class="facility-row-actions"/u, view)
  56. assert.match(source, /class="facility-row-action is-detail"/u, view)
  57. assert.match(source, /class="facility-row-action is-edit"/u, view)
  58. assert.match(source, /class="facility-row-action is-delete"/u, view)
  59. }
  60. })