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>
This commit is contained in:
parent
5bd2b92493
commit
0e89dafa43
52
dashboards/tracker-web/src/__tests__/utils.test.ts
Normal file
52
dashboards/tracker-web/src/__tests__/utils.test.ts
Normal file
@ -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');
|
||||
});
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user