waterDeviceAssigneeSelector.test.mjs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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(/async function loadAssigneeUsers\(\)[\s\S]*?\nfunction 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\(\) \{ const deptLoaded = await loadDeptTree\(true\); if \(!deptLoaded\) return; await loadAssigneeUsers\(\) \}/)
  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\(\) \{ assigneePageNum\.value = 1; loadAssigneeUsers\(\) \}/)
  31. })
  32. test('assignee pagination is server-backed', () => {
  33. assert.match(source, /buildAssigneeQuery\(\{ deptId: assigneeDeptId\.value, keyword: assigneeKeyword\.value, pageNum: assigneePageNum\.value, pageSize: assigneePageSize\.value \}\)/)
  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\) \{ assigneeDraft\.value = selectSingleAssignee\(\[row\]\) \}/)
  40. assert.match(source, /function confirmAssignee\(\) \{ selectedAssignee\.value = assigneeDraft\.value; dispatchForm\.value\.receiveUserId = assigneeDraft\.value\?\.userId \}/)
  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 requires a valid server order summary and preserves failure state', () => {
  53. assert.match(source, /const summary = normalizeDispatchOrderResponse\(response\)/)
  54. assert.match(source, /服务端未返回有效的待接单工单/)
  55. assert.match(source, /responseData\?\.msg \|\| responseData\?\.message \|\| error\?\.message/)
  56. })
  57. test('does not expose filters unsupported by the device GIS endpoint', () => {
  58. assert.match(source, /<el-form-item v-if="view !== 'gis'" label="设备名称"/)
  59. assert.match(source, /<el-form-item v-if="view !== 'gis'" label="设备编码"/)
  60. assert.match(source, /<el-form-item v-if="view === 'ledger'" label="报警状态"/)
  61. })