import { describe, expect, it } from 'vitest'; import { filterRowsBySkuThenName } from '../src/services/weighStationService'; describe('filterRowsBySkuThenName', () => { const items = [ { id: '1', sku_code: 'S1', item_name: '小白菜' }, { id: '2', sku_code: 'S2', item_name: '大白菜' }, { id: '3', sku_code: 'S3', item_name: '小 白 菜' }, ]; it('hits by sku when present', () => { const hit = filterRowsBySkuThenName(items, { sku: 'S2', name: '小白菜' }); expect(hit.map((r) => r.id)).toEqual(['2']); }); it('falls back to normalized name when sku misses', () => { const hit = filterRowsBySkuThenName(items, { sku: 'WRONG', name: '小白菜' }); expect(hit.map((r) => r.id).sort()).toEqual(['1', '3']); }); it('name-only still works', () => { const hit = filterRowsBySkuThenName(items, { name: '大白菜' }); expect(hit.map((r) => r.id)).toEqual(['2']); }); it('wrong sku without name returns empty', () => { expect(filterRowsBySkuThenName(items, { sku: 'WRONG' })).toEqual([]); }); });