Skip to content

Add unit tests for chart-utils formatting and calculation helpers #64

Description

@aruneshwisdm

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

  • At least 5 of the listed functions have tests covering normal cases and edge cases
  • Edge cases tested: zero values, negative numbers, division by zero, empty arrays
  • calculateGrowthRate tested with previous = 0 (should return 100 when current > 0)
  • linearRegression tested with empty array (returns slope: 0, intercept: 0)
  • All tests pass with pnpm vitest run

Getting started

These are all pure functions with no database or API dependencies, so no mocking is needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions