- Replaced static paths with dynamic locale subpaths (`/[locale]/*`) in imports, URLs, and assertions across tests. - Updated `next-intl` mocks for improved compatibility with `locale`-aware components. - Standardized `page.goto` and navigation tests with `/en` as the base locale for consistency.
64 lines
2.1 KiB
TypeScript
64 lines
2.1 KiB
TypeScript
/**
|
|
* Tests for Admin Organization Members Page
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
import OrganizationMembersPage from '@/app/[locale]/admin/organizations/[id]/members/page';
|
|
|
|
// Mock Next.js Link
|
|
jest.mock('next/link', () => ({
|
|
__esModule: true,
|
|
default: ({ children, href, ...props }: any) => {
|
|
return (
|
|
<a href={href} {...props}>
|
|
{children}
|
|
</a>
|
|
);
|
|
},
|
|
}));
|
|
|
|
// Mock OrganizationMembersContent component
|
|
jest.mock('@/components/admin/organizations/OrganizationMembersContent', () => ({
|
|
OrganizationMembersContent: ({ organizationId }: { organizationId: string }) => (
|
|
<div data-testid="organization-members-content">Organization ID: {organizationId}</div>
|
|
),
|
|
}));
|
|
|
|
describe('OrganizationMembersPage', () => {
|
|
it('renders back button to organizations', async () => {
|
|
const params = Promise.resolve({ id: 'org-123' });
|
|
render(await OrganizationMembersPage({ params }));
|
|
|
|
const backLink = screen.getByRole('link');
|
|
expect(backLink).toHaveAttribute('href', '/admin/organizations');
|
|
});
|
|
|
|
it('renders organization members content with correct ID', async () => {
|
|
const params = Promise.resolve({ id: 'org-456' });
|
|
render(await OrganizationMembersPage({ params }));
|
|
|
|
expect(screen.getByTestId('organization-members-content')).toBeInTheDocument();
|
|
expect(screen.getByText('Organization ID: org-456')).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders container with proper styling', async () => {
|
|
const params = Promise.resolve({ id: 'org-789' });
|
|
const { container } = render(await OrganizationMembersPage({ params }));
|
|
|
|
const mainContainer = container.querySelector('.container');
|
|
expect(mainContainer).toBeInTheDocument();
|
|
});
|
|
|
|
it('handles different organization IDs', async () => {
|
|
const testIds = ['org-001', 'org-abc-123', 'test-org'];
|
|
|
|
for (const testId of testIds) {
|
|
const params = Promise.resolve({ id: testId });
|
|
const { unmount } = render(await OrganizationMembersPage({ params }));
|
|
|
|
expect(screen.getByText(`Organization ID: ${testId}`)).toBeInTheDocument();
|
|
unmount();
|
|
}
|
|
});
|
|
});
|