Summary
apps/web/lib/dashboard/chart-utils.ts contains many pure utility functions (currency formatting, date range calculation, growth rate, linear regression) that currently have no unit tests.
Functions to test (pick at least 5)
formatChartCurrency(value, currency) — formats numbers with K/M suffixes
formatFullCurrency(value, currency) — full currency formatting for tooltips
formatPercentage(value, decimals) — percentage formatting
formatCompactNumber(value) — compact number formatting (K/M)
calculateGrowthRate(current, previous) — growth rate between two values
calculateConversionRate(converted, total) — conversion rate calculation
linearRegression(data) — simple linear regression (slope + intercept)
generateForecast(historicalData, forecastPeriods, confidenceInterval) — forecast generation
getStatusLabel(status) — status string to display label
calculateTotal(counts) — sum of status counts
Files
- Source:
apps/web/lib/dashboard/chart-utils.ts
- Test file to create:
apps/web/__tests__/lib/dashboard/chart-utils.test.ts
Acceptance criteria
Getting started
These are all pure functions with no database or API dependencies, so no mocking is needed.
Summary
apps/web/lib/dashboard/chart-utils.tscontains many pure utility functions (currency formatting, date range calculation, growth rate, linear regression) that currently have no unit tests.Functions to test (pick at least 5)
formatChartCurrency(value, currency)— formats numbers with K/M suffixesformatFullCurrency(value, currency)— full currency formatting for tooltipsformatPercentage(value, decimals)— percentage formattingformatCompactNumber(value)— compact number formatting (K/M)calculateGrowthRate(current, previous)— growth rate between two valuescalculateConversionRate(converted, total)— conversion rate calculationlinearRegression(data)— simple linear regression (slope + intercept)generateForecast(historicalData, forecastPeriods, confidenceInterval)— forecast generationgetStatusLabel(status)— status string to display labelcalculateTotal(counts)— sum of status countsFiles
apps/web/lib/dashboard/chart-utils.tsapps/web/__tests__/lib/dashboard/chart-utils.test.tsAcceptance criteria
calculateGrowthRatetested withprevious = 0(should return 100 when current > 0)linearRegressiontested with empty array (returns slope: 0, intercept: 0)pnpm vitest runGetting started
These are all pure functions with no database or API dependencies, so no mocking is needed.