import { describe, expect, it } from 'vitest' import { wellBadge, wellClasses, wellLabel, wellStyle, } from '../../components/WellPlate.rendering' import type { Well } from '../../types' function well(overrides: Partial = {}): Well { return { id: 'A1', row: 0, col: 0, state: 'empty', ...overrides, } } describe('WellPlate rendering helpers', () => { it('derives well classes from selection and drag priority', () => { expect(wellClasses(well({ sampleType: 'sample' }), { wellShape: 'circle', selectionMode: 'drag', selected: true, dragOver: false, hovered: false, disabled: false, readonly: false, dragSource: false, dragTarget: true, })).toEqual([ 'mint-well-plate__well', 'mint-well-plate__well--circle', 'mint-well-plate__well--draggable', 'mint-well-plate__well--drag-target', ]) }) it('suppresses hover styling when readonly and includes disabled/filled states', () => { expect(wellClasses(well({ state: 'filled' }), { wellShape: 'rounded', selectionMode: 'multiple', selected: false, dragOver: false, hovered: true, disabled: true, readonly: true, dragSource: false, dragTarget: false, })).toEqual([ 'mint-well-plate__well', 'mint-well-plate__well--rounded', 'mint-well-plate__well--disabled', 'mint-well-plate__well--filled', ]) }) it('prefers heatmap and custom sample colors before defaults', () => { expect(wellStyle(well({ value: 0.5 }), { heatmap: { enabled: true, colorScale: 'viridis', min: 0, max: 1 }, sampleColors: {}, })).toEqual({ backgroundColor: expect.any(String), border: '1px solid transparent', }) expect(wellStyle(well({ sampleType: 'treated' }), { heatmap: { enabled: false }, sampleColors: { treated: '#123456' }, })).toEqual({ backgroundColor: 'color-mix(in srgb, #123456 15%, transparent)', border: '1px solid color-mix(in srgb, #123456 40%, transparent)', }) expect(wellStyle(well({ sampleType: 'qc' }), { heatmap: { enabled: false }, sampleColors: {}, })).toEqual({ backgroundColor: 'color-mix(in srgb, #8b5cf6 15%, transparent)', border: '1px solid color-mix(in srgb, #8b5cf6 40%, transparent)', }) }) it('should tint a sample well green when no custom color is set', () => { expect(wellStyle(well({ sampleType: 'sample' }), { heatmap: { enabled: false }, sampleColors: {}, }).border).toBe('1px solid color-mix(in srgb, #10b981 40%, transparent)') }) it('should tint a blank well orange when no custom color is set', () => { expect(wellStyle(well({ sampleType: 'blank' }), { heatmap: { enabled: false }, sampleColors: {}, }).border).toBe('1px solid color-mix(in srgb, #f97316 40%, transparent)') }) it('should color a well by its group before its sample type', () => { expect(wellStyle(well({ sampleType: 'iqc', group: 'trt' }), { heatmap: { enabled: false }, sampleColors: { trt: '#123456' }, }).border).toBe('1px solid color-mix(in srgb, #123456 40%, transparent)') }) it('should tint a well with a group color token', () => { expect(wellStyle(well({ sampleType: 'sample', group: 'trt' }), { heatmap: { enabled: false }, sampleColors: { trt: 'var(--mint-sample-3)' }, }).backgroundColor).toBe('color-mix(in srgb, var(--mint-sample-3) 15%, transparent)') }) it('should leave empty wells to the stylesheet when the well has no sample type', () => { expect(wellStyle(well(), { heatmap: { enabled: false }, sampleColors: {}, })).toEqual({}) }) it('should leave filled wells to the stylesheet when the well has no sample type', () => { expect(wellStyle(well({ state: 'filled' }), { heatmap: { enabled: false }, sampleColors: {}, })).toEqual({}) }) it('formats labels and badges for optional overlays', () => { expect(wellLabel(well({ metadata: { label: 'Dose A' } }), true)).toBe('Dose A') expect(wellLabel(well({ metadata: { label: 'Dose A' } }), false)).toBeUndefined() expect(wellBadge(well({ metadata: { injectionCount: 3 } }), true)).toEqual({ text: '3', color: '#6366f1', }) expect(wellBadge(well({ metadata: { customMethod: 'LCMS-2' } }), true)).toEqual({ text: '+', color: '#ec4899', }) expect(wellBadge(well({ metadata: { injectionCount: 1 } }), true)).toBeNull() }) })