Files
klp-oa/klp-ui/src/utils/validate.test.js
砂糖 7feaf8021b feat: 新增规格校验功能并优化钢卷号输入处理
1. 新增validSpecification规格校验函数,校验格式为数字.两位小数*数字的钢卷规格
2. 为多个页面的钢卷号输入框添加trim修饰符自动去除首尾空格
3. 在API层统一对钢卷号字段做trim预处理
4. 为原料和产品表单添加规格必填校验和格式校验
5. 新增钢卷信息修正页面,添加生产耗时自动计算功能
6. 优化部分页面的UI和代码冗余
2026-06-15 10:56:28 +08:00

89 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { expect, test, describe } from '@jest/globals';
import { validSpecification } from './validate.js';
const callValidator = (value) => {
let err = null;
validSpecification(null, value, (e) => { err = e; });
return !err;
};
describe('validSpecification - 规格校验', () => {
describe('正常情况', () => {
test('1.50*1000', () => {
expect(callValidator('1.50*1000')).toBe(true);
});
test('0.35*1250.5', () => {
expect(callValidator('0.35*1250.5')).toBe(true);
});
test('2.385*1500', () => {
expect(callValidator('2.385*1500')).toBe(true);
});
test('10.00*500', () => {
expect(callValidator('10.00*500')).toBe(true);
});
test('0.25*2000', () => {
expect(callValidator('0.25*2000')).toBe(true);
});
});
describe('异常情况 - 厚度小数不足两位', () => {
test('1.5*1000 只有一位小数', () => {
expect(callValidator('1.5*1000')).toBe(false);
});
test('10*1000 没有小数', () => {
expect(callValidator('10*1000')).toBe(false);
});
test('5.*1000 0位小数', () => {
expect(callValidator('5.*1000')).toBe(false);
});
});
describe('异常情况 - 缺少星号分隔符', () => {
test('1.501000 无星号', () => {
expect(callValidator('1.501000')).toBe(false);
});
test('1.50 只有厚度', () => {
expect(callValidator('1.50')).toBe(false);
});
});
describe('异常情况 - 缺少厚度或宽度', () => {
test('*1000 缺厚度', () => {
expect(callValidator('*1000')).toBe(false);
});
test('1.50* 缺宽度', () => {
expect(callValidator('1.50*')).toBe(false);
});
});
describe('异常情况 - 非数字输入', () => {
test('abc*1000 厚度为字母', () => {
expect(callValidator('abc*1000')).toBe(false);
});
test('1.50*abc 宽度为字母', () => {
expect(callValidator('1.50*abc')).toBe(false);
});
test('一点五*一千 纯中文', () => {
expect(callValidator('一点五*一千')).toBe(false);
});
});
describe('异常情况 - 格式错误', () => {
test('1.50*1000*extra 多星号', () => {
expect(callValidator('1.50*1000*extra')).toBe(false);
});
test('空字符串通过必填之外校验', () => {
expect(callValidator('')).toBe(true);
});
test('星号在前', () => {
expect(callValidator('*1.50*1000')).toBe(false);
});
test('含空格', () => {
expect(callValidator(' 1.50*1000 ')).toBe(false);
});
test('中文×分隔符', () => {
expect(callValidator('1.50×1000')).toBe(false);
});
});
});