import { describe, expect, it } from 'vitest' import type { Reagent } from '../../types' import { formatReagentExpiresIn, formatReagentExpiryDate, getReagentColumnValue, getReagentRowClasses, getReagentStockLevel, isReagentExpired, isReagentExpiringSoon, isReagentLowStock, } from '../../components/ReagentList.presentation' describe('ReagentList presentation helpers', () => { const reagent: Reagent = { id: 'reagent-1', name: 'Glucose', catalogNumber: 'G-7528', lotNumber: 'LOT-A', supplier: 'Sigma', expiryDate: '2026-06-01T00:00:00.000Z', stockLevel: 12, } it('extracts sortable values for table columns', () => { expect(getReagentColumnValue(reagent, 'name')).toBe('Glucose') expect(getReagentColumnValue(reagent, 'catalog')).toBe('G-7528') expect(getReagentColumnValue(reagent, 'expiry')).toBe(new Date(reagent.expiryDate!).getTime()) expect(getReagentColumnValue({ id: 'empty', name: 'Empty' }, 'stock')).toBeUndefined() }) it('classifies expiry states relative to a supplied date', () => { const now = new Date('2026-05-22T00:00:00.000Z') expect(isReagentExpired(reagent, now)).toBe(false) expect(isReagentExpiringSoon(reagent, 30, now)).toBe(true) expect(isReagentExpired({ ...reagent, expiryDate: '2026-05-01T00:00:00.000Z' }, now)).toBe(true) }) it('should count whole days left when a reagent expires soon', () => { expect(formatReagentExpiresIn(reagent, new Date('2026-05-29T12:00:00.000Z'))).toBe('3 days left') }) it('should use the singular when one day is left', () => { expect(formatReagentExpiresIn(reagent, new Date('2026-05-31T12:00:00.000Z'))).toBe('1 day left') }) it('classifies low stock', () => { expect(isReagentLowStock(reagent, 15)).toBe(true) expect(getReagentStockLevel({ id: 'missing', name: 'Missing' })).toBe(0) }) it('formats missing and present expiry dates', () => { expect(formatReagentExpiryDate(undefined)).toBe('-') expect(formatReagentExpiryDate('2026-06-01T00:00:00.000Z')).toBe('Jun 2026') }) it('builds row state classes without mixing expired and expiring-soon', () => { expect( getReagentRowClasses(reagent, { lowStockThreshold: 15, draggedId: 'reagent-1', dragOverId: 'reagent-2', now: new Date('2026-05-22T00:00:00.000Z'), }) ).toEqual([ 'mint-reagent-list__row', 'mint-reagent-list__row--expiring-soon', 'mint-reagent-list__row--low-stock', 'mint-reagent-list__row--dragging', ]) }) })