Skip to content
Merged
Show file tree
Hide file tree
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
59 changes: 59 additions & 0 deletions components/dashboard/StatsCard.mock-integrations.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import StatsCard from './StatsCard';

vi.mock('framer-motion', () => ({
motion: {
div: ({ children, ...props }: any) => <div {...props}>{children}</div>,
},
}));

vi.mock('lucide-react', () => ({
Flame: (props: any) => <div data-testid="icon-flame" {...props} />,
TrendingUp: (props: any) => <div data-testid="icon-trending-up" {...props} />,
GitCommit: (props: any) => <div data-testid="icon-git-commit" {...props} />,
}));

describe('StatsCard mock integrations', () => {
it('renders with mocked Flame icon', () => {
render(<StatsCard title="Active Streak" value="42" description="days in a row" icon="Flame" />);

expect(screen.getByTestId('icon-flame')).toBeDefined();
});

it('renders with mocked TrendingUp icon', () => {
render(
<StatsCard title="Growth" value="100%" description="monthly growth" icon="TrendingUp" />
);

expect(screen.getByTestId('icon-trending-up')).toBeDefined();
});

it('renders with mocked GitCommit icon', () => {
render(<StatsCard title="Commits" value="150" description="this month" icon="GitCommit" />);

expect(screen.getByTestId('icon-git-commit')).toBeDefined();
});

it('falls back to Flame icon when icon is unknown', () => {
render(<StatsCard title="Fallback" value="0" description="fallback test" icon="UnknownIcon" />);

expect(screen.getByTestId('icon-flame')).toBeDefined();
});

it('renders chart bars from provided chartData', () => {
render(
<StatsCard
title="Chart"
value="10"
description="chart test"
icon="Flame"
chartData={[1, 2, 3, 4, 5]}
/>
);

expect(screen.getByText('Chart')).toBeDefined();
});
});
58 changes: 58 additions & 0 deletions components/dashboard/tooltipUtils.type-compiler.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { describe, expectTypeOf, it } from 'vitest';
import type { ActivityData } from '@/types/dashboard';

describe('tooltipUtils type compiler tests', () => {
it('validates ActivityData structure correctly', () => {
const validData: ActivityData = {
date: '2024-01-01',
count: 5,
intensity: 2,
};

expectTypeOf(validData.date).toBeString();
expectTypeOf(validData.count).toBeNumber();
expectTypeOf(validData.intensity).toBeNumber();
});

it('ensures ActivityData array typing works', () => {
const data: ActivityData[] = [
{
date: '2024-01-01',
count: 1,
intensity: 1,
},
];

expectTypeOf(data).toBeArray();
});

it('accepts optional compatible values safely', () => {
const data: ActivityData = {
date: '2024-01-02',
count: 0,
intensity: 0,
};

expectTypeOf(data.count).toEqualTypeOf<number>();
});
it('rejects invalid property types during compilation', () => {
expectTypeOf<ActivityData>().toBeObject();

const invalidCount: ActivityData = {
date: '2024-01-01',
// @ts-expect-error count must be number
count: 'five',
intensity: 2,
};
});

it('rejects missing required properties', () => {
expectTypeOf<ActivityData>().toBeObject();

// @ts-expect-error intensity is required
const invalidData: ActivityData = {
date: '2024-01-01',
count: 5,
};
});
});
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading