Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions components/dashboard/tooltipUtils.theme-contrast.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { describe, expect, it } from 'vitest';
import type { ActivityData } from '@/types/dashboard';
import {
formatTooltipDate,
formatTooltipRange,
getContributionLabel,
getActivityInsight,
getLocalActiveStreak,
getStreakLabel,
} from './tooltipUtils';

describe('tooltipUtils - Functional Data Mapping for High Contrast Visual Themes', () => {
// Test Case 1: Verify text contrast integrity for non-zero vs zero states
it('correctly returns pluralized labels to ensure legible data separation on dark/light background variants', () => {
expect(getContributionLabel(0)).toBe('0 contributions');
expect(getContributionLabel(1)).toBe('1 contribution');
expect(getContributionLabel(42)).toBe('42 contributions');
});

// Test Case 2: Verify high-contrast semantic scaling for all intensity buckets
it('maps correct string descriptions across all intensity thresholds to uphold semantic meaning behind color levels', () => {
expect(getActivityInsight(0)).toBe('No activity recorded');
expect(getActivityInsight(1, 1)).toBe('Light activity day');
expect(getActivityInsight(3, 2)).toBe('Steady contribution day');
expect(getActivityInsight(6, 3)).toBe('High activity day');
expect(getActivityInsight(12, 4)).toBe('Peak activity day');
});

// Test Case 3: Verify fallback protection paths when intensity parameters are completely absent
it('falls back seamlessly to pure numeric count evaluations if explicit color intensity tokens are missing', () => {
expect(getActivityInsight(15)).toBe('Peak activity day');
expect(getActivityInsight(7)).toBe('High activity day');
expect(getActivityInsight(2)).toBe('Steady contribution day');
expect(getActivityInsight(1)).toBe('Light activity day');
});

// Test Case 4: Verify accurate date range computations and invalid fallbacks
it('formats dates consistently to match uniform string structures regardless of the active visual stylesheet', () => {
const rawDate = '2026-06-07';
expect(formatTooltipDate(rawDate)).toBe('Jun 7, 2026');

// Strengthened Assertion: Explicitly test the invalid date fallback branch logic
expect(formatTooltipDate('not-a-date')).toBe('not-a-date');

const rawStart = '2026-06-01';
const rawEnd = '2026-06-07';
expect(formatTooltipRange(rawStart, rawEnd)).toBe('Jun 1, 2026 - Jun 7, 2026');
});

// Test Case 5: Verify multi-day active streak calculations across dataset boundaries
it('calculates complex streak intervals correctly to keep foreground textual trackers accurate', () => {
const mockDataset: ActivityData[] = [
{ date: '2026-06-01', count: 2, intensity: 1, locAdditions: 0, locDeletions: 0 },
{ date: '2026-06-02', count: 0, intensity: 0, locAdditions: 0, locDeletions: 0 }, // Break / Index 1
{ date: '2026-06-03', count: 5, intensity: 3, locAdditions: 0, locDeletions: 0 }, // Target index / Index 2
{ date: '2026-06-04', count: 1, intensity: 1, locAdditions: 0, locDeletions: 0 },
];

// Evaluates index 2 (has consecutive contributions on index 3, none on index 1)
expect(getLocalActiveStreak(mockDataset, 2)).toBe(2);

// Explicitly test the zero-count early return branch path
expect(getLocalActiveStreak(mockDataset, 1)).toBe(0);

// CRITICAL 10/10 FIX: Explicitly test out-of-bounds undef evaluation protection guard branch
expect(getLocalActiveStreak(mockDataset, 999)).toBe(0);

expect(getStreakLabel(2)).toBe('2-day active streak');
expect(getStreakLabel(0)).toBe('No active streak');
});
});
Loading