waterDeviceAssigneeSelector.test.mjs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import fs from 'node:fs'
  4. const source = fs.readFileSync(new URL('../src/views/subSystem/waterSupply/components/WaterDevicePage.vue', import.meta.url), 'utf8')
  5. test('device dispatch uses a department tree and paged single-assignee table', () => {
  6. assert.match(source, /<el-tree[\s\S]*@node-click="handleDeptClick"/)
  7. assert.match(source, /搜索用户名、昵称或手机号/)
  8. assert.match(source, /<el-pagination[\s\S]*assigneeTotal/)
  9. assert.match(source, /selectSingleAssignee\(\[row\]\)/)
  10. assert.match(source, /:disabled="!assigneeDraft"/)
  11. })
  12. test('assignee loading failure remains in place with a retry action', () => {
  13. assert.match(source, /userLoadError/)
  14. assert.match(source, /责任人列表加载失败,请点击重试/)
  15. assert.match(source, /@click="retryAssigneeLoading"/)
  16. })
  17. test('assignee loading failure preserves existing rows and total', () => {
  18. const loadFn = source.match(new RegExp("async function loadAssigneeUsers\\(\\)[\\s\\S]*?\\n\\s*function searchAssigneeUsers"))?.[0] || ""
  19. assert.doesNotMatch(loadFn, /users\.value = \[\]/)
  20. assert.doesNotMatch(loadFn, /assigneeTotal\.value = 0/)
  21. assert.match(loadFn, /userLoadError\.value = '责任人列表加载失败,请点击重试'/)
  22. })
  23. test('retry path force reloads the department tree before users', () => {
  24. assert.match(source, /async function loadDeptTree\(force = false\)/)
  25. assert.match(source, /async function retryAssigneeLoading\(\)\s*\{[\s\S]*?await loadDeptTree\(true\)[\s\S]*?await loadAssigneeUsers\(\)[\s\S]*?\}/)
  26. })
  27. test('assignee keyword search resets to the first result page', () => {
  28. assert.match(source, /@keyup\.enter="searchAssigneeUsers"/)
  29. assert.match(source, /@click="searchAssigneeUsers"/)
  30. assert.match(source, /function searchAssigneeUsers\(\)\s*\{[\s\S]*?assigneePageNum\.value = 1;?\s*loadAssigneeUsers\(\)[\s\S]*?\}/)
  31. })
  32. test('assignee pagination is server-backed', () => {
  33. assert.match(source, /buildAssigneeQuery\(\{\s*deptId:\s*assigneeDeptId\.value,\s*keyword:\s*assigneeKeyword\.value,\s*pageNum:\s*assigneePageNum\.value,\s*pageSize:\s*assigneePageSize\.value\s*\}\)/)
  34. assert.match(source, /@current-change="loadAssigneeUsers"/)
  35. assert.match(source, /@size-change="handleAssigneeSizeChange"/)
  36. })
  37. test('uses draft assignee state until confirmation in the split dispatch dialog', () => {
  38. assert.match(source, /const assigneeDraft = ref\(null\)/)
  39. assert.match(source, /function chooseAssignee\(row\)\s*\{[\s\S]*?assigneeDraft\.value = selectSingleAssignee\(\[row\]\)[\s\S]*?\}/)
  40. assert.match(source, /function confirmAssignee\(\)\s*\{[\s\S]*?selectedAssignee\.value = assigneeDraft\.value;?\s*dispatchForm\.value\.receiveUserId = assigneeDraft\.value\?\.userId[\s\S]*?\}/)
  41. assert.match(source, /<div class="dispatch-layout">/)
  42. assert.match(source, /<el-form class="dispatch-form"/)
  43. assert.match(source, /:current-row-key="assigneeDraft\?\.userId"/)
  44. })
  45. test('opens the split dispatch dialog with a fresh assignee query', () => {
  46. assert.match(source, /async function openOrder\(row\)/)
  47. assert.match(source, /assigneeDeptId\.value = undefined/)
  48. assert.match(source, /assigneeKeyword\.value = ''/)
  49. assert.match(source, /dispatchVisible\.value = true/)
  50. assert.match(source, /await retryAssigneeLoading\(\)/)
  51. })
  52. test('dispatch form exposes fixed fault type and editable priority', () => {
  53. assert.match(source, /<el-form-item label="工单类型">\s*<span>1-故障维修<\/span>\s*<\/el-form-item>/)
  54. assert.match(source, /<el-form-item label="优先级" required>\s*<el-select v-model="dispatchForm\.orderLevel"/)
  55. assert.match(source, /<el-option\s+label="紧急"\s+:value="1"\s*\/?>/)
  56. })
  57. test('dispatch requires a valid server order summary and preserves failure state', () => {
  58. assert.match(source, /const summary = normalizeDispatchOrderResponse\(response\)/)
  59. assert.match(source, /服务端未返回有效的待接单工单/)
  60. assert.match(source, /responseData\?\.msg \|\| responseData\?\.message \|\| error\?\.message/)
  61. })
  62. test('does not expose filters unsupported by the device GIS endpoint', () => {
  63. assert.match(source, /<el-form-item v-if="view !== 'gis'" label="设备名称"/)
  64. assert.match(source, /<el-form-item v-if="view !== 'gis'" label="设备编码"/)
  65. assert.match(source, /<el-form-item v-if="view === 'ledger'" label="报警状态"/)
  66. })