technicianSelect.helpers.test.mjs 2.92 KB
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
  buildSelectArr,
  buildRatioMap,
  mapArtificerList,
  calcShowMainShareRatio,
  buildConfirmPayload
} from '../components/TechnicianSelectPopup/technicianSelect.helpers.js'

describe('technicianSelect.helpers', () => {
  it('TECH-01 technicianId 模式 selectArr', () => {
    const arr = buildSelectArr(
      [{ technicianId: 1, id: 10 }, { id: 20 }],
      'technicianId'
    )
    assert.deepEqual(arr, [1, 20])
  })

  it('TECH-02 uuid 模式 selectArr', () => {
    const arr = buildSelectArr([{ uuid: 'a' }, { uuid: 'b' }], 'uuid')
    assert.deepEqual(arr, ['a', 'b'])
  })

  it('TECH-03 active 映射', () => {
    const list = mapArtificerList(
      [
        { id: 1, uuid: 'u1', staffName: 'A' },
        { id: 2, uuid: 'u2', staffName: 'B' }
      ],
      {
        artificerSelectObj: { id: 1, uuid: 'u1' },
        selectArr: [1],
        ratioMap: { 1: 30 },
        idKey: 'technicianId',
        disabledSelectObj: [],
        deputyFlag: false
      }
    )
    assert.equal(list[0].active, true)
    assert.equal(list[0].shareRatio, 30)
    assert.equal(list[1].active, false)
  })

  it('TECH-04 disabled 映射', () => {
    const list = mapArtificerList(
      [{ id: 1, uuid: 'u1' }, { id: 2, uuid: 'u2' }],
      {
        artificerSelectObj: null,
        selectArr: [],
        ratioMap: {},
        idKey: 'technicianId',
        disabledSelectObj: [{ uuid: 'u2' }],
        deputyFlag: false
      }
    )
    assert.equal(list[0].disabled, false)
    assert.equal(list[1].disabled, true)
  })

  it('TECH-05 shareRatio 映射', () => {
    const ratioMap = buildRatioMap([{ id: 5, shareRatio: 40 }], 'technicianId')
    assert.equal(ratioMap[5], 40)
    assert.equal(calcShowMainShareRatio([{ active: true, shareRatio: 40 }]), 60)
  })

  it('TECH-06 副手选满 2 个置灰', () => {
    const list = mapArtificerList(
      [
        { id: 1, uuid: 'u1' },
        { id: 2, uuid: 'u2' },
        { id: 3, uuid: 'u3' }
      ],
      {
        artificerSelectObj: [{ id: 1 }, { id: 2 }],
        selectArr: [1, 2],
        ratioMap: { 1: 30, 2: 20 },
        idKey: 'technicianId',
        disabledSelectObj: [],
        deputyFlag: true
      }
    )
    assert.equal(list[2].disabled, true)
  })

  it('TECH-07 confirm technicianId 含 technicianId 字段', () => {
    const result = buildConfirmPayload({
      artificerSelectObj: {},
      activeArr: [{ uuid: 'u1', id: 99, staffName: 'T' }],
      idKey: 'technicianId',
      deputyFlag: false
    })
    assert.equal(result.ok, true)
    assert.equal(result.payload.technicianId, 99)
  })

  it('TECH-08 confirm uuid 模式 deputy 空选放行', () => {
    const result = buildConfirmPayload({
      artificerSelectObj: { foo: 1 },
      activeArr: [],
      idKey: 'uuid',
      deputyFlag: true
    })
    assert.equal(result.ok, true)
    assert.equal(result.payload.technicianUuid, '')
  })
})