forked from cardosofelipe/fast-next-template
Remove deprecated middleware and update component tests for branding and auth enhancements
- Deleted `middleware.disabled.ts` as it is no longer needed. - Refactored `HeroSection` and `HomePage` tests to align with updated branding and messaging. - Modified `DemoCredentialsModal` to support auto-filled demo credentials in login links. - Mocked `ThemeToggle`, `LocaleSwitcher`, and `DemoCredentialsModal` in relevant tests. - Updated admin tests to use `QueryClientProvider` and refactored API mocks for `AdminPage`. - Replaced test assertions for stats section and badges with new branding content.
This commit is contained in:
@@ -5,10 +5,26 @@
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import AdminPage from '@/app/[locale]/admin/page';
|
||||
import { useAdminStats } from '@/lib/api/hooks/useAdmin';
|
||||
import { getAdminStats } from '@/lib/api/admin';
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
||||
|
||||
// Mock the API client
|
||||
jest.mock('@/lib/api/admin');
|
||||
|
||||
// Mock the useAdminStats hook
|
||||
jest.mock('@/lib/api/hooks/useAdmin');
|
||||
jest.mock('@/lib/api/hooks/useAdmin', () => ({
|
||||
useAdminStats: () => ({
|
||||
data: {
|
||||
totalUsers: 100,
|
||||
activeUsers: 80,
|
||||
totalOrganizations: 20,
|
||||
totalSessions: 30,
|
||||
},
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
error: null,
|
||||
}),
|
||||
}));
|
||||
|
||||
// Mock chart components
|
||||
jest.mock('@/components/charts', () => ({
|
||||
@@ -22,23 +38,31 @@ jest.mock('@/components/charts', () => ({
|
||||
UserStatusChart: () => <div data-testid="user-status-chart">User Status Chart</div>,
|
||||
}));
|
||||
|
||||
const mockUseAdminStats = useAdminStats as jest.MockedFunction<typeof useAdminStats>;
|
||||
const mockGetAdminStats = getAdminStats as jest.MockedFunction<typeof getAdminStats>;
|
||||
|
||||
// Helper function to render with default mocked stats
|
||||
function renderWithMockedStats() {
|
||||
mockUseAdminStats.mockReturnValue({
|
||||
mockGetAdminStats.mockResolvedValue({
|
||||
data: {
|
||||
totalUsers: 100,
|
||||
activeUsers: 80,
|
||||
totalOrganizations: 20,
|
||||
totalSessions: 30,
|
||||
user_growth: [],
|
||||
organization_distribution: [],
|
||||
user_status: [],
|
||||
},
|
||||
isLoading: false,
|
||||
isError: false,
|
||||
error: null,
|
||||
} as any);
|
||||
|
||||
return render(<AdminPage />);
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
queries: {
|
||||
retry: false,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AdminPage />
|
||||
</QueryClientProvider>
|
||||
);
|
||||
}
|
||||
|
||||
describe('AdminPage', () => {
|
||||
|
||||
@@ -47,6 +47,34 @@ jest.mock('react-syntax-highlighter/dist/esm/styles/prism', () => ({
|
||||
vscDarkPlus: {},
|
||||
}));
|
||||
|
||||
// Mock auth hooks
|
||||
jest.mock('@/lib/api/hooks/useAuth', () => ({
|
||||
useIsAuthenticated: jest.fn(() => false),
|
||||
useLogout: jest.fn(() => ({
|
||||
mutate: jest.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
// Mock Theme components
|
||||
jest.mock('@/components/theme', () => ({
|
||||
ThemeToggle: () => <div data-testid="theme-toggle">Theme Toggle</div>,
|
||||
}));
|
||||
|
||||
// Mock LocaleSwitcher
|
||||
jest.mock('@/components/i18n', () => ({
|
||||
LocaleSwitcher: () => <div data-testid="locale-switcher">Locale Switcher</div>,
|
||||
}));
|
||||
|
||||
// Mock DemoCredentialsModal
|
||||
jest.mock('@/components/home/DemoCredentialsModal', () => ({
|
||||
DemoCredentialsModal: ({ open, onClose }: any) =>
|
||||
open ? (
|
||||
<div data-testid="demo-modal">
|
||||
<button onClick={onClose}>Close</button>
|
||||
</div>
|
||||
) : null,
|
||||
}));
|
||||
|
||||
describe('HomePage', () => {
|
||||
describe('Page Structure', () => {
|
||||
it('renders without crashing', () => {
|
||||
@@ -60,7 +88,6 @@ describe('HomePage', () => {
|
||||
render(<Home />);
|
||||
const header = screen.getByRole('banner');
|
||||
expect(within(header).getByText('PragmaStack')).toBeInTheDocument();
|
||||
expect(within(header).getByText('Template')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders footer with copyright', () => {
|
||||
@@ -79,30 +106,26 @@ describe('HomePage', () => {
|
||||
|
||||
it('renders production-ready messaging', () => {
|
||||
render(<Home />);
|
||||
expect(screen.getByText(/Production-ready FastAPI/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Opinionated, secure, and production-ready/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders test coverage stats', () => {
|
||||
it('renders badges', () => {
|
||||
render(<Home />);
|
||||
const coverageTexts = screen.getAllByText('97%');
|
||||
expect(coverageTexts.length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText(/Test Coverage/i)[0]).toBeInTheDocument();
|
||||
const testCountTexts = screen.getAllByText('743');
|
||||
expect(testCountTexts.length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText(/Passing Tests/i)[0]).toBeInTheDocument();
|
||||
expect(screen.getByText('Comprehensive Tests')).toBeInTheDocument();
|
||||
expect(screen.getByText('Pragmatic by Design')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Context Section', () => {
|
||||
it('renders what you get message', () => {
|
||||
render(<Home />);
|
||||
expect(screen.getByText(/What You Get Out of the Box/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Stop Reinventing the Wheel/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders key features', () => {
|
||||
render(<Home />);
|
||||
expect(screen.getAllByText(/Clone & Deploy in < 5 minutes/i)[0]).toBeInTheDocument();
|
||||
expect(screen.getAllByText(/97% Test Coverage \(743 tests\)/i)[0]).toBeInTheDocument();
|
||||
expect(screen.getAllByText(/Comprehensive Test Suite/i)[0]).toBeInTheDocument();
|
||||
expect(screen.getAllByText(/12\+ Documentation Guides/i)[0]).toBeInTheDocument();
|
||||
expect(screen.getAllByText(/Zero Commercial Dependencies/i)[0]).toBeInTheDocument();
|
||||
});
|
||||
@@ -167,7 +190,7 @@ describe('HomePage', () => {
|
||||
describe('Tech Stack Section', () => {
|
||||
it('renders tech stack heading', () => {
|
||||
render(<Home />);
|
||||
expect(screen.getByText(/Modern, Type-Safe, Production-Grade Stack/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/A Stack You Can Trust/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders all technologies', () => {
|
||||
@@ -186,7 +209,7 @@ describe('HomePage', () => {
|
||||
describe('Philosophy Section', () => {
|
||||
it('renders why this template exists', () => {
|
||||
render(<Home />);
|
||||
expect(screen.getByText(/Why This Template Exists/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Why PragmaStack\?/i)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders what you wont find section', () => {
|
||||
@@ -198,7 +221,7 @@ describe('HomePage', () => {
|
||||
it('renders what you will find section', () => {
|
||||
render(<Home />);
|
||||
expect(screen.getByText(/What You Will Find/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Production patterns that actually work/i)).toBeInTheDocument();
|
||||
expect(screen.getByText(/Pragmatic Speed: Ship features, not config/i)).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user