Refactor Admin Organizations tests and enhance useAdmin hooks with session stats

- Simplified `AdminOrganizationsPage` tests by mocking `OrganizationManagementContent` and focusing on essential structure and content rendering.
- Updated `useAdmin` hooks to integrate `adminListSessions` and accommodate session statistics in superuser scenarios.
- Added relevant test coverage for session data fetching and validation.
This commit is contained in:
Felipe Cardoso
2025-11-06 20:10:38 +01:00
parent ff758f5d10
commit 234c197ee1
2 changed files with 27 additions and 49 deletions

View File

@@ -1,59 +1,17 @@
/**
* Tests for Admin Organizations Page
* Verifies rendering of organization management placeholder
* Basic structural tests - full component testing in E2E tests
*/
import { render, screen } from '@testing-library/react';
import AdminOrganizationsPage from '@/app/admin/organizations/page';
// Mock the entire OrganizationManagementContent component
jest.mock('@/components/admin/organizations/OrganizationManagementContent', () => ({
OrganizationManagementContent: () => <div data-testid="organization-management">Organization Management</div>,
}));
describe('AdminOrganizationsPage', () => {
it('renders page title', () => {
render(<AdminOrganizationsPage />);
expect(screen.getByText('Organizations')).toBeInTheDocument();
});
it('renders page description', () => {
render(<AdminOrganizationsPage />);
expect(
screen.getByText('Manage organizations and their members')
).toBeInTheDocument();
});
it('renders back button link', () => {
render(<AdminOrganizationsPage />);
const backLink = screen.getByRole('link', { name: '' });
expect(backLink).toHaveAttribute('href', '/admin');
});
it('renders coming soon message', () => {
render(<AdminOrganizationsPage />);
expect(
screen.getByText('Organization Management Coming Soon')
).toBeInTheDocument();
});
it('renders feature list', () => {
render(<AdminOrganizationsPage />);
expect(
screen.getByText(/Organization list with search and filtering/)
).toBeInTheDocument();
expect(
screen.getByText(/View organization details and members/)
).toBeInTheDocument();
expect(
screen.getByText(/Manage organization memberships/)
).toBeInTheDocument();
expect(
screen.getByText(/Organization statistics and activity/)
).toBeInTheDocument();
expect(screen.getByText(/Bulk operations/)).toBeInTheDocument();
});
it('renders with proper container structure', () => {
const { container } = render(<AdminOrganizationsPage />);
@@ -61,4 +19,10 @@ describe('AdminOrganizationsPage', () => {
expect(containerDiv).toBeInTheDocument();
expect(containerDiv).toHaveClass('mx-auto', 'px-6', 'py-8');
});
it('renders organization management content', () => {
render(<AdminOrganizationsPage />);
expect(screen.getByTestId('organization-management')).toBeInTheDocument();
});
});