import { shallowMount } from '@vue/test-utils' import { describe, expect, it } from 'vitest' import SmartGroupFieldRecipe from '../../components/SmartGroupFieldRecipe.vue' import SmartGroupManual from '../../components/SmartGroupManual.vue' import SmartGroupModal from '../../components/SmartGroupModal.vue' describe('SmartGroupModal', () => { it('should open in auto mode with the Field Recipe', () => { const wrapper = shallowMount(SmartGroupModal) expect(wrapper.findComponent(SmartGroupFieldRecipe).exists()).toBe(true) }) it('should render the manual cohort builder when mode is manual', () => { const wrapper = shallowMount(SmartGroupModal, { props: { mode: 'manual' } }) expect(wrapper.findComponent(SmartGroupManual).exists()).toBe(true) }) it('should forward the auto prop bag to the Field Recipe', () => { const wrapper = shallowMount(SmartGroupModal, { props: { auto: { experimentLabel: 'EXP-001' } } }) expect(wrapper.findComponent(SmartGroupFieldRecipe).props('experimentLabel')).toBe('EXP-001') }) it('should emit update:mode when the Field Recipe asks for manual mode', async () => { const wrapper = shallowMount(SmartGroupModal) wrapper.findComponent(SmartGroupFieldRecipe).vm.$emit('manual') await wrapper.vm.$nextTick() expect(wrapper.emitted('update:mode')).toEqual([['manual']]) }) it('should switch back to auto when the cohort builder asks for it', async () => { const wrapper = shallowMount(SmartGroupModal, { props: { mode: 'manual' } }) wrapper.findComponent(SmartGroupManual).vm.$emit('auto') await wrapper.vm.$nextTick() expect(wrapper.emitted('update:mode')).toEqual([['auto']]) }) it('should re-emit apply from the Field Recipe unchanged', () => { const wrapper = shallowMount(SmartGroupModal) const payload = { groups: [] } wrapper.findComponent(SmartGroupFieldRecipe).vm.$emit('apply', payload) expect(wrapper.emitted('apply')).toEqual([[payload]]) }) it('should re-emit done from the cohort builder unchanged', () => { const wrapper = shallowMount(SmartGroupModal, { props: { mode: 'manual' } }) const payload = { samples: [] } wrapper.findComponent(SmartGroupManual).vm.$emit('done', payload) expect(wrapper.emitted('done')).toEqual([[payload]]) }) it('should re-emit close from the Field Recipe', () => { const wrapper = shallowMount(SmartGroupModal) wrapper.findComponent(SmartGroupFieldRecipe).vm.$emit('close') expect(wrapper.emitted('close')).toHaveLength(1) }) })