import { parseSeedsText } from '@/utils/indicatorSeeds' describe('parseSeedsText', () => { test('empty/null/undefined → []', () => { expect(parseSeedsText('')).toEqual([]) expect(parseSeedsText(null)).toEqual([]) expect(parseSeedsText(undefined)).toEqual([]) }) test('JSON array with definitionId', () => { const input = '[{"rawName":"乳酸菌","definitionId":3},{"rawName":"双歧杆菌"}]' const res = parseSeedsText(input) expect(res).toHaveLength(2) expect(res[0]).toEqual({ rawName: '乳酸菌', definitionId: 3 }) expect(res[1]).toEqual({ rawName: '双歧杆菌', definitionId: null }) }) test('CSV two columns', () => { const input = '乳酸菌,3\n双歧杆菌\n' const res = parseSeedsText(input) expect(res).toHaveLength(2) expect(res[0]).toEqual({ rawName: '乳酸菌', definitionId: 3 }) expect(res[1]).toEqual({ rawName: '双歧杆菌', definitionId: null }) }) test('skip empty rawName', () => { const input = '乳酸菌,3\n ,\n双歧杆菌' const res = parseSeedsText(input) expect(res).toHaveLength(2) expect(res[0].rawName).toBe('乳酸菌') expect(res[1].rawName).toBe('双歧杆菌') }) test('skip blank lines', () => { const input = '乳酸菌,3\n\n\n双歧杆菌\n' const res = parseSeedsText(input) expect(res).toHaveLength(2) }) test('invalid JSON falls back to CSV row parsing', () => { const input = 'not json at all\n乳酸菌,3\n' const res = parseSeedsText(input) expect(res).toEqual([{ rawName: '乳酸菌', definitionId: 3 }]) }) test('non-numeric definitionId in CSV → null', () => { const input = '乳酸菌,abc\n' const res = parseSeedsText(input) expect(res).toEqual([{ rawName: '乳酸菌', definitionId: null }]) }) test('Chinese comma delimiter', () => { const input = '乳酸菌,3\n' const res = parseSeedsText(input) expect(res).toEqual([{ rawName: '乳酸菌', definitionId: 3 }]) }) })