import { describe, expect, it } from 'vitest' import { createLcmsControlWellEditData, getLcmsDefaultControlWellId, lcmsPlateCellsToRacks, rackToLcmsPlateCells, } from '../../utils/rack' import type { Rack } from '../../types' describe('rack LCMS adapters', () => { it('converts LCMS plate cells into rack wells grouped by slot', () => { const racks = lcmsPlateCellsToRacks([ { row: 'A', column: 1, sample_name: 'S1', sample_type: 'sample', injection_volume: 7, slot: 'G', }, { row: 'H', column: 10, sample_name: 'IQC', sample_type: 'iqc', injection_count: 2, slot: 'R', }, ]) expect(racks.map(rack => rack.slot)).toEqual(['R', 'G']) expect(racks[0]).toMatchObject({ id: 'rack-R', format: 96, wells: { H10: { sampleType: 'iqc', metadata: { label: 'IQC', injectionVolume: 5, injectionCount: 2, }, }, }, }) expect(racks[1].wells.A1?.metadata).toMatchObject({ label: 'S1', injectionVolume: 7, }) }) it('flattens rack wells back to LCMS plate cells with slot metadata', () => { const rack: Rack = { id: 'rack-R', name: 'Rack R', format: 54, slot: 'R', injectionVolume: 5, wells: { A1: { id: 'A1', state: 'filled', sampleType: 'sample', metadata: { label: 'S1', injectionVolume: 7, injectionCount: 3, customMethod: 'C:\\Methods\\custom.meth', }, }, F7: { id: 'F7', state: 'filled', sampleType: 'iqc', metadata: { label: 'IQC', }, }, }, } expect(rackToLcmsPlateCells(rack)).toEqual([ { row: 'A', column: 1, sample_name: 'S1', sample_type: 'sample', injection_volume: 7, injection_count: 3, custom_method: 'C:\\Methods\\custom.meth', slot: 'R', }, { row: 'F', column: 7, sample_name: 'IQC', sample_type: 'iqc', injection_volume: 5, injection_count: 1, custom_method: null, slot: 'R', }, ]) }) it('exposes LCMS default control well edit data', () => { expect(getLcmsDefaultControlWellId('54vial', 'iqc')).toBe('F7') expect(createLcmsControlWellEditData('qc', { plateType: '96well', injectionVolume: 8, })).toEqual({ wellId: 'H11', label: 'QC', sampleType: 'qc', injectionVolume: 8, injectionCount: 1, customMethod: '', }) }) })