import { mount } from '@vue/test-utils' import { describe, expect, it } from 'vitest' import FitPanel from '../../components/FitPanel.vue' import type { FitResultSummary, FitSeries } from '../../types' const results: FitResultSummary[] = [ { label: 'IC50 (nM)', value: '42.7' }, { label: 'Hill slope', value: '-1.12', variant: 'success' }, { label: 'R²', value: '0.982', variant: 'success', verdict: true }, ] function mountCompleted() { return mount(FitPanel, { props: { state: 'completed', results } }) } describe('FitPanel', () => { it('should list results as table rows when they carry no verdict, even with a variant', () => { expect(mountCompleted().findAll('.mint-fit-panel__result-row').map(row => row.text())) .toEqual(['IC50 (nM)42.7', 'Hill slope-1.12']) }) it('should move a result into the check row when it is marked as a verdict', () => { expect(mountCompleted().get('.mint-fit-panel__check--success').text()).toBe('R² 0.982') }) }) const parameters: FitResultSummary[] = [ { label: 'IC50', unit: 'nM', value: '631', ci: '512 – 778' }, { label: 'Hill slope', value: '1.10', ci: '0.94 – 1.26' }, ] const series: FitSeries[] = [ { label: 'Control', results: parameters }, { label: 'Treatment A', color: 'var(--mint-sample-4)', results: [{ label: 'IC50', unit: 'nM', value: '39.8' }] }, ] describe('FitPanel parameter table (9b)', () => { it('should render the unit in its own element when a result has a unit', () => { const wrapper = mount(FitPanel, { props: { state: 'completed', results: parameters } }) expect(wrapper.get('.mint-fit-panel__result-unit').text()).toBe('nM') }) it('should render a header row when results are shown', () => { const wrapper = mount(FitPanel, { props: { state: 'completed', results: parameters } }) expect(wrapper.get('.mint-fit-panel__result-head').text()).toBe('ParameterValue95% CI') }) it('should render the confidence interval when a result has one', () => { const wrapper = mount(FitPanel, { props: { state: 'completed', results: parameters } }) expect(wrapper.get('.mint-fit-panel__result-ci').text()).toBe('512 – 778') }) it('should omit the CI column when no result has a confidence interval', () => { expect(mountCompleted().get('.mint-fit-panel__result-head').text()).toBe('ParameterValue') }) it('should use custom column labels when columnLabels is set', () => { const wrapper = mount(FitPanel, { props: { state: 'completed', results: parameters, columnLabels: { parameter: '参数', value: '值' } }, }) expect(wrapper.get('.mint-fit-panel__result-head').text()).toBe('参数值95% CI') }) }) describe('FitPanel series switch (9b)', () => { it('should show the first series when series are given', () => { const wrapper = mount(FitPanel, { props: { state: 'completed', series } }) expect(wrapper.findAll('.mint-fit-panel__result-row')).toHaveLength(2) }) it('should show another series when its segment is selected', async () => { const wrapper = mount(FitPanel, { props: { state: 'completed', series } }) await wrapper.findAll('[role="radio"]')[1].trigger('click') expect(wrapper.findAll('.mint-fit-panel__result-row')).toHaveLength(1) }) it('should emit the selected series index when a segment is selected', async () => { const wrapper = mount(FitPanel, { props: { state: 'completed', series } }) await wrapper.findAll('[role="radio"]')[1].trigger('click') expect(wrapper.emitted('update:activeSeries')?.[0]).toEqual([1]) }) it('should color a series segment with the group palette when the series has no color', () => { const wrapper = mount(FitPanel, { props: { state: 'completed', series } }) expect(wrapper.get('.mint-segmented-control__swatch').attributes('style')).toContain('var(--mint-sample-1)') }) it('should render no series switch when series are not given', () => { expect(mountCompleted().find('.mint-fit-panel__series').exists()).toBe(false) }) it('should keep the series switch when the active series has no results', () => { const wrapper = mount(FitPanel, { props: { state: 'completed', series: [{ label: 'Empty', results: [] }, ...series] } }) expect(wrapper.find('.mint-fit-panel__series').exists()).toBe(true) }) })