import { describe, expect, it } from 'vitest' import { engineAnatomy, engineQcChips, engineSchemasToCards, experimentLabel, previewValues, } from '../../components/AutoGroupModal.adapter' import { useAutoGroup } from '../../composables/useAutoGroup' const tracingBatch = [ 'LT_13102025_212_WT_Glu_3_20_S_091123_T1_33', 'LT_13102025_213_WT_Glu_3_20_S_091123_T1_34', 'LT_13102025_214_KI_Glu_3_20_S_091123_T1_35', 'LT_13102025_215_KI_Glu_6_40_L_091123_T1_36', 'LT_13102025_216_WT_Glu_6_40_L_091123_T1_37', 'LT_13102025_217_WT_Glu_6_40_L_091123_T2_38', 'LT_13102025_218_KI_Glu_3_20_S_091123_T2_39', 'LT_13102025_219_KI_Glu_6_40_L_091123_T2_40', 'LT_13102025_EQC_Jurkat_1_2', 'LT_13102025_EQC_Jurkat_2_8', 'LT_13102025_IQC_Pool_1_5', ] function anatomyOf(samples: string[]) { const engine = useAutoGroup() engine.rawText.value = samples.join('\n') engine.parseInput() const cards = engineSchemasToCards(engine.schemas.value, engine.activeClassKey.value) return { engine, anatomy: engineAnatomy(engine.classes.value, engine.schemas.value, engine.tokenized.value, cards) } } describe('previewValues', () => { it('should list all values when there are three or fewer', () => { expect(previewValues(['a', 'b', 'c'])).toBe('a, b, c') }) it('should list three values and the rest as a count when there are more', () => { expect(previewValues(['212', '213', '214', '215', '216'])).toBe('212, 213, 214 … +2') }) }) describe('engineAnatomy', () => { it('should show the tokens of one study sample in name order when the batch is parsed', () => { expect(anatomyOf(tracingBatch).anatomy.map(token => token.text)).toEqual( ['212', 'WT', 'Glu', '3', '20', 'S', '091123', 'T1', '33'], ) }) it('should mark a grouped field with its layer when the field is on', () => { expect(anatomyOf(tracingBatch).anatomy[1]).toEqual({ text: 'WT', caption: '1', state: 'on' }) }) it('should mark a field that is off by default with its name when the field is a sample ID', () => { expect(anatomyOf(tracingBatch).anatomy[0]).toEqual({ text: '212', caption: 'Sample ID', state: 'off' }) }) it('should mark a constant token as fixed when it is not a grouping field', () => { expect(anatomyOf(tracingBatch).anatomy[2]).toEqual({ text: 'Glu', caption: 'constant', state: 'fixed' }) }) it('should return no tokens when the batch has no study sample', () => { expect(anatomyOf(['QC_01', 'QC_02']).anatomy).toEqual([]) }) }) describe('engineQcChips', () => { it('should list each QC class with its sample count when the batch has QC samples', () => { expect(engineQcChips(anatomyOf(tracingBatch).engine.classes.value)).toEqual([ { name: 'EQC', count: 2 }, { name: 'IQC', count: 1 }, ]) }) }) describe('experimentLabel', () => { it('should join the header fields when the batch has them', () => { expect(experimentLabel({ code: 'exp157', date: '2025-10-13', operator: 'LT' })).toBe('exp157 · 2025-10-13 · LT') }) it('should return an empty label when the batch has no header', () => { expect(experimentLabel({})).toBe('') }) }) describe('engineSchemasToCards value preview', () => { it('should shorten the value list of a card when the field has more than three values', () => { const { engine } = anatomyOf(tracingBatch) const cards = engineSchemasToCards(engine.schemas.value, engine.activeClassKey.value) expect(cards.fields.find(field => field.key === 'Sample ID')?.vals).toBe('212, 213, 214 … +5') }) })