import { mount } from '@vue/test-utils' import { describe, expect, it } from 'vitest' import PlateEditor from '../../components/PlateEditor.vue' import PlateEditorBindingInternal from '../../components/internal/PlateEditorBindingInternal.vue' import type { Rack } from '../../types' function rack(id: string): Rack { return { id, name: id, format: 96, slot: 'R', injectionVolume: 5, wells: {} } } function mountBinding(props: { modelValue: Rack[]; activeRackId?: string }) { return mount(PlateEditorBindingInternal, { props, global: { stubs: { teleport: true } } }) } describe('PlateEditorBindingInternal', () => { it('should offer undo once an intent changed the plates', async () => { const wrapper = mountBinding({ modelValue: [rack('r1')] }) wrapper.findComponent(PlateEditor).vm.$emit('update:slot', 'r1', 'B') await wrapper.vm.$nextTick() expect(wrapper.findComponent(PlateEditor).props('canUndo')).toBe(true) }) it('should show the history buttons', () => { const wrapper = mountBinding({ modelValue: [rack('r1')] }) expect(wrapper.findComponent(PlateEditor).props('history')).toBe(true) }) it('should follow a changed activeRackId', async () => { const wrapper = mountBinding({ modelValue: [rack('r1'), rack('r2')], activeRackId: 'r1' }) await wrapper.setProps({ activeRackId: 'r2' }) expect(wrapper.findComponent(PlateEditor).props('activeRackId')).toBe('r2') }) it('should select a rack that arrives with the reloaded plates', async () => { const wrapper = mountBinding({ modelValue: [rack('r1')], activeRackId: 'r1' }) await wrapper.setProps({ modelValue: [rack('r1'), rack('r9')], activeRackId: 'r9' }) expect(wrapper.findComponent(PlateEditor).props('activeRackId')).toBe('r9') }) it('should select a reloaded rack when activeRackId is passed before the plates', async () => { const wrapper = mountBinding({ activeRackId: 'r1', modelValue: [rack('r1')] }) await wrapper.setProps({ modelValue: [rack('r1'), rack('r9')], activeRackId: 'r9' }) expect(wrapper.findComponent(PlateEditor).props('activeRackId')).toBe('r9') }) it('should not undo into the plates of a previous binding', async () => { const wrapper = mountBinding({ modelValue: [rack('r1')] }) wrapper.findComponent(PlateEditor).vm.$emit('update:slot', 'r1', 'B') await wrapper.vm.$nextTick() await wrapper.setProps({ modelValue: [rack('r9')] }) expect(wrapper.findComponent(PlateEditor).props('canUndo')).toBe(false) }) })