mobile-cert-segment.test.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import assert from 'node:assert/strict'
  2. import test from 'node:test'
  3. import { readFileSync } from 'node:fs'
  4. import { parse } from '@vue/compiler-sfc'
  5. import ts from 'typescript'
  6. import { computed, ref } from 'vue'
  7. import {
  8. mapLoadFromApi,
  9. mapDeliveriesFromApi,
  10. resolveLoadViewAddress,
  11. resolveDeliveryViewAddress,
  12. resolveStopProductsForView
  13. } from '../src/utils/pl-plan-stop-form'
  14. import { resolvePlanStopsForList } from '../src/utils/pl-plan-list-display-rows'
  15. import { stopProductMeta } from '../src/views/m/pl/plan-cert/model'
  16. function declaration(source: string, name: string) {
  17. const ast = ts.createSourceFile('test.ts', source, ts.ScriptTarget.Latest, true)
  18. return ast.statements
  19. .find((node) =>
  20. ts.isFunctionDeclaration(node)
  21. ? node.name?.text === name
  22. : ts.isVariableStatement(node) &&
  23. node.declarationList.declarations.some((d) => d.name.getText(ast) === name)
  24. )!
  25. .getText(ast)
  26. .replace(/^export /, '')
  27. }
  28. test('actual detail stop mapping retains per-line mobile metadata and explicit empty values', () => {
  29. const loadMeta = {
  30. aliasName: '装货别名',
  31. brandMode: 'required',
  32. brandName: '装货品牌',
  33. brandId: 'b'
  34. }
  35. const deliveryMeta = { aliasName: null, brandMode: 'any', brandName: '', brandId: '' }
  36. const line = {
  37. id: 's',
  38. planProductId: 'p',
  39. productId: 'crm',
  40. productName: '产品',
  41. planQty: 0,
  42. inboundQty: 0,
  43. outboundQty: 0
  44. }
  45. const plan = ref<any>({
  46. id: 'A',
  47. load: { products: [{ ...line, mobileProductMeta: loadMeta }] },
  48. deliveries: [{ products: [{ ...line, mobileProductMeta: deliveryMeta }] }]
  49. })
  50. const products = ref<any[]>([
  51. {
  52. id: 'p',
  53. productId: 'crm',
  54. productName: '根别名',
  55. standardProductName: '标准产品',
  56. aliasName: '根别名',
  57. brandName: '根品牌',
  58. brandMode: 'required',
  59. quantity: 5
  60. }
  61. ])
  62. const source = parse(
  63. readFileSync(new URL('../src/views/m/pl/plan-cert/CertDetail.vue', import.meta.url), 'utf8')
  64. ).descriptor.scriptSetup!.content
  65. const shared = readFileSync(
  66. new URL('../src/composables/usePlPlanViewDetail.ts', import.meta.url),
  67. 'utf8'
  68. )
  69. const code = declaration(shared, 'mapPlanProductToFormRow') + '\n' + declaration(source, 'stops')
  70. const bindings = {
  71. computed,
  72. plan,
  73. products,
  74. resolvePlanStopsForList,
  75. mapLoadFromApi,
  76. mapDeliveriesFromApi,
  77. resolveLoadViewAddress,
  78. resolveDeliveryViewAddress,
  79. resolveStopProductsForView
  80. }
  81. const stops = new Function(
  82. ...Object.keys(bindings),
  83. `${ts.transpile(code, { target: ts.ScriptTarget.ESNext })}; return stops`
  84. )(...Object.values(bindings)).value
  85. assert.deepEqual(stops.load.products[0].mobileProductMeta, loadMeta)
  86. assert.deepEqual(stops.deliveries[0].products[0].mobileProductMeta, deliveryMeta)
  87. assert.equal(stopProductMeta(stops.deliveries[0].products[0], products.value).aliasName, null)
  88. assert.equal(stops.load.products[0].standardProductName, '标准产品')
  89. assert.equal(stops.load.products[0].planQty, 0)
  90. assert.equal(stops.deliveries[0].products[0].outboundQty, 0)
  91. })
  92. test('certificate detail action and teleported preview controls retain 44px targets', () => {
  93. const style = readFileSync(
  94. new URL('../src/views/m/pl/plan-cert/cert.scss', import.meta.url),
  95. 'utf8'
  96. )
  97. const actions = style.slice(
  98. style.indexOf('.cert-detail-actions {'),
  99. style.indexOf('.cert-sheet-content {')
  100. )
  101. assert.match(actions, /min-height:\s*44px/)
  102. const preview = style.slice(style.indexOf('.el-dialog .preview-toolbar .el-button {'))
  103. assert.match(preview, /min-height:\s*44px !important/)
  104. assert.match(preview, /min-width:\s*44px !important/)
  105. })