import { describe, expect, it } from 'vitest' import { basenameFromWindowsPath, extractLcmsCommonPrefix, extractLcmsSampleName, inferLcmsPlateTypeFromWellIds, lcmsWellIdFromPosition, reconstructLcmsPlateCellsFromSequenceItems, } from '../../lcms' describe('lcms utilities', () => { it('extracts common prefixes and sample names from Xcalibur file names', () => { const prefix = extractLcmsCommonPrefix([ 'Batch_01_NEG_S1_001', 'Batch_01_NEG_S2_002', 'Batch_01_NEG_QC_003', ]) expect(prefix).toBe('Batch_01') expect(extractLcmsSampleName('Batch_01_NEG_S1_001', prefix)).toBe('S1') }) it('infers plate type from well geometry', () => { expect(lcmsWellIdFromPosition('R:A1')).toBe('A1') expect(inferLcmsPlateTypeFromWellIds(['A1', 'F9'])).toBe('54vial') expect(inferLcmsPlateTypeFromWellIds(['A1', 'H12'])).toBe('96well') }) it('reconstructs plate cells from sequence items while skipping controls', () => { const result = reconstructLcmsPlateCellsFromSequenceItems([ { sample_type: 'Unknown', file_name: 'Batch_NEG_S1_001', sample_id: 'R:A1', path: '', instrument_method: 'C:\\Methods\\neg.meth', position: 'R:A1', injection_volume: 5, }, { sample_type: 'Unknown', file_name: 'Batch_NEG_S2_002', sample_id: 'R:H12', path: '', instrument_method: 'C:\\Methods\\neg.meth', position: 'R:H12', injection_volume: 5, }, { sample_type: 'Blank', file_name: 'Batch_NEG_Blank_003', sample_id: 'R:F9', path: '', instrument_method: 'C:\\Methods\\neg.meth', position: 'R:F9', injection_volume: 5, }, ]) expect(result).toEqual({ plateType: '96well', cells: [ { row: 'A', column: 1, sample_name: 'S1' }, { row: 'H', column: 12, sample_name: 'S2' }, ], }) }) it('extracts basenames from Windows and POSIX paths', () => { expect(basenameFromWindowsPath('C:\\Methods\\neg.meth')).toBe('neg.meth') expect(basenameFromWindowsPath('/methods/pos.meth')).toBe('pos.meth') }) })