Use /admin/settings route and update RequestCard tests

Change the settings navigation in BookDatePage to push to /admin/settings and update the corresponding test to expect the new route. Simplify RequestCard tests by removing manual/interactive search mocks and modal, remove interactiveSearch permission from the mocked AuthContext, and adjust tests to only assert cancel behavior; add a new test ensuring Manual/Interactive Search buttons are not rendered. Misc: clean up related mock resets and removed a failing manual-search failure test.
This commit is contained in:
kikootwo
2026-03-04 19:41:44 -05:00
parent ca02b8b6e7
commit d1ea65a41a
3 changed files with 13 additions and 44 deletions
+1 -1
View File
@@ -300,7 +300,7 @@ export default function BookDatePage() {
Try Again Try Again
</button> </button>
<button <button
onClick={() => router.push('/settings')} onClick={() => router.push('/admin/settings')}
className="px-6 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors" className="px-6 py-2 border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors"
> >
Go to Settings Go to Settings
+1 -1
View File
@@ -216,7 +216,7 @@ describe('BookDatePage', () => {
await screen.findByText(/Could not load recommendations/); await screen.findByText(/Could not load recommendations/);
fireEvent.click(screen.getByRole('button', { name: 'Go to Settings' })); fireEvent.click(screen.getByRole('button', { name: 'Go to Settings' }));
expect(routerMock.push).toHaveBeenCalledWith('/settings'); expect(routerMock.push).toHaveBeenCalledWith('/admin/settings');
}); });
it('shows empty state and triggers recommendation generation', async () => { it('shows empty state and triggers recommendation generation', async () => {
+11 -42
View File
@@ -10,23 +10,9 @@ import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
const cancelRequestMock = vi.hoisted(() => vi.fn()); const cancelRequestMock = vi.hoisted(() => vi.fn());
const manualSearchMock = vi.hoisted(() => vi.fn());
vi.mock('@/lib/hooks/useRequests', () => ({ vi.mock('@/lib/hooks/useRequests', () => ({
useCancelRequest: () => ({ cancelRequest: cancelRequestMock, isLoading: false }), useCancelRequest: () => ({ cancelRequest: cancelRequestMock, isLoading: false }),
useManualSearch: () => ({ triggerManualSearch: manualSearchMock, isLoading: false }),
}));
vi.mock('@/components/requests/InteractiveTorrentSearchModal', () => ({
InteractiveTorrentSearchModal: ({
isOpen,
requestId,
}: {
isOpen: boolean;
requestId?: string;
}) => (
<div data-testid="interactive-modal" data-open={String(isOpen)} data-request-id={requestId} />
),
})); }));
vi.mock('next/image', () => ({ vi.mock('next/image', () => ({
@@ -40,7 +26,7 @@ vi.mock('@/contexts/PreferencesContext', () => ({
vi.mock('@/contexts/AuthContext', () => ({ vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({ useAuth: () => ({
user: { id: 'user-1', role: 'user', permissions: { interactiveSearch: true } }, user: { id: 'user-1', role: 'user' },
accessToken: 'test-token', accessToken: 'test-token',
isLoading: false, isLoading: false,
login: vi.fn(), login: vi.fn(),
@@ -66,7 +52,6 @@ const baseRequest = {
describe('RequestCard', () => { describe('RequestCard', () => {
beforeEach(() => { beforeEach(() => {
cancelRequestMock.mockReset(); cancelRequestMock.mockReset();
manualSearchMock.mockReset();
}); });
afterEach(() => { afterEach(() => {
@@ -109,29 +94,29 @@ describe('RequestCard', () => {
expect(await screen.findByText('Failure details')).toBeInTheDocument(); expect(await screen.findByText('Failure details')).toBeInTheDocument();
}); });
it('triggers manual search, interactive search, and cancel actions', async () => { it('triggers cancel action', async () => {
const { RequestCard } = await import('@/components/requests/RequestCard'); const { RequestCard } = await import('@/components/requests/RequestCard');
manualSearchMock.mockResolvedValueOnce(undefined);
cancelRequestMock.mockResolvedValueOnce(undefined); cancelRequestMock.mockResolvedValueOnce(undefined);
vi.spyOn(window, 'confirm').mockReturnValue(true); vi.spyOn(window, 'confirm').mockReturnValue(true);
render(<RequestCard request={baseRequest} />); render(<RequestCard request={baseRequest} />);
fireEvent.click(screen.getByRole('button', { name: 'Manual Search' }));
await waitFor(() => {
expect(manualSearchMock).toHaveBeenCalledWith('req-1');
});
fireEvent.click(screen.getByRole('button', { name: 'Interactive Search' }));
expect(screen.getByTestId('interactive-modal')).toHaveAttribute('data-open', 'true');
fireEvent.click(screen.getByRole('button', { name: 'Cancel' })); fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
await waitFor(() => { await waitFor(() => {
expect(cancelRequestMock).toHaveBeenCalledWith('req-1'); expect(cancelRequestMock).toHaveBeenCalledWith('req-1');
}); });
}); });
it('does not show manual search or interactive search buttons', async () => {
const { RequestCard } = await import('@/components/requests/RequestCard');
render(<RequestCard request={baseRequest} />);
expect(screen.queryByRole('button', { name: 'Manual Search' })).toBeNull();
expect(screen.queryByRole('button', { name: 'Interactive Search' })).toBeNull();
});
it('shows setup indicator when progress is zero', async () => { it('shows setup indicator when progress is zero', async () => {
const { RequestCard } = await import('@/components/requests/RequestCard'); const { RequestCard } = await import('@/components/requests/RequestCard');
@@ -153,25 +138,9 @@ describe('RequestCard', () => {
render(<RequestCard request={baseRequest} showActions={false} />); render(<RequestCard request={baseRequest} showActions={false} />);
expect(screen.queryByRole('button', { name: 'Manual Search' })).toBeNull();
expect(screen.queryByRole('button', { name: 'Cancel' })).toBeNull(); expect(screen.queryByRole('button', { name: 'Cancel' })).toBeNull();
}); });
it('alerts when manual search fails', async () => {
const { RequestCard } = await import('@/components/requests/RequestCard');
manualSearchMock.mockRejectedValueOnce(new Error('Search failed'));
const alertSpy = vi.spyOn(window, 'alert').mockImplementation(() => {});
render(<RequestCard request={baseRequest} />);
fireEvent.click(screen.getByRole('button', { name: 'Manual Search' }));
await waitFor(() => {
expect(alertSpy).toHaveBeenCalledWith('Search failed');
});
});
it('does not cancel when confirmation is declined', async () => { it('does not cancel when confirmation is declined', async () => {
const { RequestCard } = await import('@/components/requests/RequestCard'); const { RequestCard } = await import('@/components/requests/RequestCard');