import { mount } from '@vue/test-utils' import { createPinia } from 'pinia' import { describe, expect, it } from 'vitest' import { nextTick } from 'vue' import AutoGroupModal from '../../components/AutoGroupModal.vue' import SmartGroupFieldRecipe from '../../components/SmartGroupFieldRecipe.vue' const replicated = ['WT', 'KO'].flatMap(genotype => ['Vehicle', 'Drug'].flatMap(treatment => ['1', '2', '3'].map(rep => `exp031_250318_SU_${genotype}_${treatment}_${rep}`)), ) // One sample for each animal and time point: no replicate in the name. const unreplicated = ['m1', 'm2', 'm3'].flatMap(animal => ['0min', '20min'].map(time => `${animal}_${time}`)) function recipeFor(samples: string[]) { const wrapper = mount(AutoGroupModal, { props: { modelValue: true, samples }, global: { plugins: [createPinia()], stubs: { Teleport: true } }, }) return wrapper.findComponent(SmartGroupFieldRecipe) } describe('AutoGroupModal field recipe wiring', () => { it('should pass the tokens of an example name when samples are pasted', () => { const anatomy = recipeFor(replicated).props('anatomy') as { text: string }[] expect(anatomy.map(token => token.text)).toEqual(['WT', 'Vehicle', '1']) }) it('should show the experiment header in the label when all names share it', () => { expect(recipeFor(replicated).props('experimentLabel')).toBe('exp031 · 2025-03-18 · SU') }) it('should rename the field when the recipe emits rename', async () => { const recipe = recipeFor(replicated) recipe.vm.$emit('rename', 0, 'Genotype') await nextTick() expect((recipe.props('fields') as { key: string }[])[0].key).toBe('Genotype') }) it('should give no hints when the groups have replicates', () => { expect((recipeFor(replicated).props('hints') as (string | null)[]).every(hint => hint === null)).toBe(true) }) it('should hint how many groups remain for each field when every group has one sample', () => { expect(recipeFor(unreplicated).props('hints')).toEqual(['off → 2 groups', 'off → 3 groups']) }) }) describe('AutoGroupModal reserved names', () => { it('should reserve the name of a column that is not a field when samples are pasted', () => { const recipe = recipeFor(['Liver_A_rep1', 'Liver_A_rep2', 'Liver_B_rep1', 'Liver_B_rep2']) expect(recipe.props('reservedNames')).toContain('Matrix') }) })