- Added 5 new reusable chart components (`ChartCard`, `UserGrowthChart`, `OrganizationDistributionChart`, `SessionActivityChart`, and `UserStatusChart`) with full TypeScript definitions, responsive designs, and mock data generators for demo purposes. - Integrated analytics overview section into `AdminDashboard`, displaying all charts in a responsive grid layout with consistent theming and error/loading handling. - Delivered extensive unit tests (32 new tests across 5 files) and E2E tests (16 new tests) ensuring proper rendering, state handling, and accessibility. - Updated `IMPLEMENTATION_PLAN.md` with Phase 9 details and progress, marking it as COMPLETE and ready to move to Phase 10. - Maintained 100% unit test pass rate, with overall code coverage at 95.6%, zero build/lint errors, and production readiness achieved.
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
/**
|
|
* Tests for UserStatusChart Component
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
import { UserStatusChart } from '@/components/charts/UserStatusChart';
|
|
import type { UserStatusData } from '@/components/charts/UserStatusChart';
|
|
|
|
// 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('UserStatusChart', () => {
|
|
const mockData: UserStatusData[] = [
|
|
{ name: 'Active', value: 142, color: 'hsl(var(--chart-1))' },
|
|
{ name: 'Inactive', value: 28, color: 'hsl(var(--chart-2))' },
|
|
{ name: 'Pending', value: 15, color: 'hsl(var(--chart-3))' },
|
|
];
|
|
|
|
it('renders chart card with title and description', () => {
|
|
render(<UserStatusChart data={mockData} />);
|
|
|
|
expect(screen.getByText('User Status Distribution')).toBeInTheDocument();
|
|
expect(screen.getByText('Breakdown of users by status')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders chart with provided data', () => {
|
|
render(<UserStatusChart data={mockData} />);
|
|
|
|
expect(screen.getByTestId('responsive-container')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders with mock data when no data is provided', () => {
|
|
render(<UserStatusChart />);
|
|
|
|
expect(screen.getByText('User Status Distribution')).toBeInTheDocument();
|
|
expect(screen.getByTestId('responsive-container')).toBeInTheDocument();
|
|
});
|
|
|
|
it('shows loading state', () => {
|
|
render(<UserStatusChart data={mockData} loading />);
|
|
|
|
expect(screen.getByText('User Status Distribution')).toBeInTheDocument();
|
|
|
|
// Chart should not be visible when loading
|
|
expect(screen.queryByTestId('responsive-container')).not.toBeInTheDocument();
|
|
});
|
|
|
|
it('shows error state', () => {
|
|
render(<UserStatusChart data={mockData} error="Failed to load chart data" />);
|
|
|
|
expect(screen.getByText('User Status 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(<UserStatusChart data={[]} />);
|
|
|
|
expect(screen.getByText('User Status Distribution')).toBeInTheDocument();
|
|
expect(screen.getByTestId('responsive-container')).toBeInTheDocument();
|
|
});
|
|
});
|