yeg
2026-09-08 cfd4511378aefa04d4e06058cee628b6edd8e9c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import assert from 'node:assert/strict'
import fs from 'node:fs'
import test from 'node:test'
import { buildBatteryGroupPayload } from '../src/api/batteryGroupPayload.ts'
 
test('battery group payload contains the entered battery numbers', () => {
  const payload = buildBatteryGroupPayload({
    name: ' 样品组 ',
    model: ' M-01 ',
    purpose: ' 容量验证 ',
    remark: ' 首批 ',
    status: '启用',
    specs: { z: 'Z1', h: '', f: '', a: '', b: '' },
    batteries: [{ value: ' BAT-01 ' }, { value: '' }, { value: 'BAT-02' }],
  }, null, [])
 
  assert.deepEqual(payload, {
    groupName: '样品组',
    model: 'M-01',
    purpose: '容量验证',
    remark: '首批',
    status: '0',
    z: 'Z1',
    h: '',
    f: '',
    a: '',
    b: '',
    batteryNos: ['BAT-01', 'BAT-02'],
    templateId: null,
    templateFieldRelations: undefined,
  })
})
 
test('battery group payload preserves template field values', () => {
  const payload = buildBatteryGroupPayload({
    name: '样品组', model: 'M-01', purpose: '验证', remark: '', status: '禁用',
    specs: {}, batteries: [{ value: 'BAT-01' }],
  }, 7, [{ batteryGroupFieldId: 3, fieldValue: '72Ah' }])
 
  assert.equal(payload.status, '1')
  assert.equal(payload.templateId, 7)
  assert.deepEqual(payload.templateFieldRelations, [{ batteryGroupFieldId: 3, fieldValue: '72Ah' }])
})
 
test('shared field store uses the backend as its source of truth', () => {
  const source = fs.readFileSync(new URL('../src/stores/batteryGroupFields.ts', import.meta.url), 'utf8')
  assert.doesNotMatch(source, /localStorage\./)
  assert.match(source, /getBatteryGroupFields/)
})
 
test('battery group columns include backend-defined shared fields', () => {
  const source = fs.readFileSync(new URL('../src/views/BatteryGroup.vue', import.meta.url), 'utf8')
  assert.match(source, /getBatteryGroupFields/)
  assert.match(source, /field-\$\{field\.id\}/)
  assert.match(source, /customFieldValue/)
})
 
test('template editor submits the editable template name', () => {
  const source = fs.readFileSync(new URL('../src/views/BatteryGroupForm.vue', import.meta.url), 'utf8')
  assert.match(source, /currentTemplateName/)
  assert.match(source, /updateBatteryGroupTemplate\(form\.templateId, name, selectedFieldIds\.value\)/)
  assert.match(source, /createdResult\.data\?\.templateId/)
  assert.doesNotMatch(source, /find\(item => item\.name === name\)/)
  assert.doesNotMatch(source, /<el-option label="自定义" :value="0"/)
  assert.match(source, /<el-option label="默认" :value="0"/)
})