From 0e89dafa436f16c930b15a0fa0f760d6b8bceb81 Mon Sep 17 00:00:00 2001 From: saravanakumardb1 Date: Thu, 28 May 2026 18:49:04 -0700 Subject: [PATCH] test(tracker-web): add unit tests for src/lib/utils.ts - Add comprehensive tests for cn utility function - Cover empty input, single/multiple classes, conflicting Tailwind classes - Test conditional classes, arrays, objects, and complex mixed inputs - 10 assertions total, exceeding minimum requirement of 4 Generated with [Devin](https://cli.devin.ai/docs) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../tracker-web/src/__tests__/utils.test.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 dashboards/tracker-web/src/__tests__/utils.test.ts diff --git a/dashboards/tracker-web/src/__tests__/utils.test.ts b/dashboards/tracker-web/src/__tests__/utils.test.ts new file mode 100644 index 00000000..55492161 --- /dev/null +++ b/dashboards/tracker-web/src/__tests__/utils.test.ts @@ -0,0 +1,52 @@ +/** + * Tests for src/lib/utils.ts utility functions + */ + +import { describe, it, expect } from 'vitest'; +import { cn } from '@/lib/utils'; + +describe('cn utility function', () => { + it('should handle empty input', () => { + expect(cn()).toBe(''); + }); + + it('should handle single class string', () => { + expect(cn('px-4')).toBe('px-4'); + }); + + it('should handle multiple class strings', () => { + expect(cn('px-4', 'py-2', 'bg-blue-500')).toBe('px-4 py-2 bg-blue-500'); + }); + + it('should merge conflicting Tailwind classes (last one wins)', () => { + expect(cn('px-4', 'px-2')).toBe('px-2'); + expect(cn('bg-red-500', 'bg-blue-500')).toBe('bg-blue-500'); + }); + + it('should handle conditional classes with null/undefined', () => { + expect(cn('px-4', null, 'py-2', undefined)).toBe('px-4 py-2'); + }); + + it('should handle arrays of classes', () => { + expect(cn(['px-4', 'py-2'])).toBe('px-4 py-2'); + }); + + it('should handle objects with boolean values', () => { + expect(cn({ 'px-4': true, 'py-2': false, 'bg-blue-500': true })).toBe('px-4 bg-blue-500'); + }); + + it('should handle complex mixed inputs', () => { + expect( + cn('base-class', ['array-class'], { 'conditional-class': true, 'removed-class': false }, null) + ).toBe('base-class array-class conditional-class'); + }); + + it('should handle empty arrays and objects', () => { + expect(cn([])).toBe(''); + expect(cn({})).toBe(''); + }); + + it('should handle conflicting classes in complex scenarios', () => { + expect(cn('text-sm', ['text-lg'], { 'text-xl': false })).toBe('text-lg'); + }); +});