Files
fast-next-template/frontend/tests/components/charts/OrganizationDistributionChart.test.tsx
Felipe Cardoso acfe59c8b3 Refactor admin stats API and charts data models for consistency
- Updated `AdminStatsResponse` with streamlined type annotations and added `AdminStatsData` type definition.
- Renamed chart data model fields (`totalUsers` → `total_users`, `activeUsers` → `active_users`, `members` → `value`, etc.) for alignment with backend naming conventions.
- Adjusted related test files to reflect updated data model structure.
- Improved readability of `AdminPage` component by reformatting destructuring in `useQuery`.
2025-11-24 12:44:45 +01:00

73 lines
2.6 KiB
TypeScript

/**
* Tests for OrganizationDistributionChart Component
*/
import { render, screen } from '@testing-library/react';
import { OrganizationDistributionChart } from '@/components/charts/OrganizationDistributionChart';
import type { OrganizationDistributionData } from '@/components/charts/OrganizationDistributionChart';
// Mock recharts to avoid rendering issues in tests
jest.mock('recharts', () => {
const OriginalModule = jest.requireActual('recharts');
return {
...OriginalModule,
ResponsiveContainer: ({ children }: { children: React.ReactNode }) => (
<div data-testid="responsive-container">{children}</div>
),
};
});
describe('OrganizationDistributionChart', () => {
const mockData: OrganizationDistributionData[] = [
{ name: 'Engineering', value: 45 },
{ name: 'Marketing', value: 28 },
{ name: 'Sales', value: 35 },
];
it('renders chart card with title and description', () => {
render(<OrganizationDistributionChart data={mockData} />);
expect(screen.getByText('Organization Distribution')).toBeInTheDocument();
expect(screen.getByText('Member count by organization')).toBeInTheDocument();
});
it('renders chart with provided data', () => {
render(<OrganizationDistributionChart data={mockData} />);
expect(screen.getByTestId('responsive-container')).toBeInTheDocument();
});
it('renders with mock data when no data is provided', () => {
render(<OrganizationDistributionChart />);
expect(screen.getByText('Organization Distribution')).toBeInTheDocument();
expect(screen.getByTestId('responsive-container')).toBeInTheDocument();
});
it('shows loading state', () => {
render(<OrganizationDistributionChart data={mockData} loading />);
expect(screen.getByText('Organization Distribution')).toBeInTheDocument();
// Chart should not be visible when loading
expect(screen.queryByTestId('responsive-container')).not.toBeInTheDocument();
});
it('shows error state', () => {
render(<OrganizationDistributionChart data={mockData} error="Failed to load chart data" />);
expect(screen.getByText('Organization Distribution')).toBeInTheDocument();
expect(screen.getByText('Failed to load chart data')).toBeInTheDocument();
// Chart should not be visible when error
expect(screen.queryByTestId('responsive-container')).not.toBeInTheDocument();
});
it('renders with empty data array', () => {
render(<OrganizationDistributionChart data={[]} />);
expect(screen.getByText('Organization Distribution')).toBeInTheDocument();
expect(screen.getByTestId('responsive-container')).toBeInTheDocument();
});
});