52 lines
1.3 KiB
JavaScript
52 lines
1.3 KiB
JavaScript
import { describe, expect, it } from 'vitest'
|
|
import { createMaterialForm, toMaterialPayload } from './materialForm'
|
|
|
|
const categories = [
|
|
{ id: 1, code: 'A01', name: '标准件', parent_id: null },
|
|
{ id: 12, code: 'A01-01', name: '标准件·通用型', parent_id: 1 }
|
|
]
|
|
|
|
describe('material master-data form', () => {
|
|
it('contains only material master-data fields', () => {
|
|
expect(createMaterialForm()).toEqual({
|
|
material_code: '',
|
|
name: '',
|
|
spec: '',
|
|
category: '',
|
|
unit: 'pcs',
|
|
material_image: '',
|
|
major_category_id: null,
|
|
category_id: null,
|
|
base_unit_id: null
|
|
})
|
|
})
|
|
|
|
it('restores category selections and submits their persisted ids', () => {
|
|
const form = createMaterialForm({
|
|
material_code: 'MAT-001',
|
|
name: '轴承',
|
|
spec: '6205',
|
|
category: 'A01-01',
|
|
category_id: 12,
|
|
base_unit_id: 3,
|
|
unit: '件',
|
|
material_image: '',
|
|
total_on_hand: 99,
|
|
warning_stock: 10
|
|
}, categories)
|
|
|
|
expect(form.major_category_id).toBe(1)
|
|
expect(form.category_id).toBe(12)
|
|
expect(toMaterialPayload(form)).toEqual({
|
|
material_code: 'MAT-001',
|
|
name: '轴承',
|
|
spec: '6205',
|
|
category: 'A01-01',
|
|
category_id: 12,
|
|
base_unit_id: 3,
|
|
unit: '件',
|
|
material_image: ''
|
|
})
|
|
})
|
|
})
|