Files
ReadMeABook/tests/app/setup/steps/ProwlarrStep.test.tsx
T
kikootwo 411b5f88a4 Add per-indexer ratio-based seeding policy
Introduce a per-indexer ratioLimit alongside seedingTimeMinutes to control torrent cleanup. Updates include: documentation (scheduler and settings pages), types and API (saved indexer config now includes ratioLimit), setup and management UI (new TorrentSeedingFields component, modal wiring, validation and handlers), and processor logic (cleanup-seeded-torrents now requires AND-semantics between time and ratio; 0 disables a criterion, both 0 = never cleaned, undefined client ratio with ratioLimit>0 = not met). Tests were added/updated to cover ratio-only, time+ratio, missing-ratio, and UI interactions. Default behavior: ratioLimit defaults to 0 (no ratio requirement).
2026-05-18 15:07:50 -04:00

78 lines
2.0 KiB
TypeScript

/**
* Component: Setup Prowlarr Step Tests
* Documentation: documentation/setup-wizard.md
*/
// @vitest-environment jsdom
import React from 'react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
const indexersMock = [
{
id: 1,
name: 'Indexer',
priority: 10,
seedingTimeMinutes: 0,
ratioLimit: 1.5,
rssEnabled: true,
categories: [],
},
];
vi.mock('@/components/admin/indexers/IndexerManagement', () => ({
IndexerManagement: ({ onIndexersChange }: { onIndexersChange: (indexers: any[]) => void }) => (
<button type="button" onClick={() => onIndexersChange(indexersMock)}>
Set Indexers
</button>
),
}));
describe('ProwlarrStep', () => {
it('shows validation errors when required fields are missing', async () => {
const { ProwlarrStep } = await import('@/app/setup/steps/ProwlarrStep');
const onNext = vi.fn();
render(
<ProwlarrStep
prowlarrUrl=""
prowlarrApiKey=""
onUpdate={vi.fn()}
onNext={onNext}
onBack={vi.fn()}
/>
);
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
expect(screen.getByText('Please enter Prowlarr URL and API key')).toBeInTheDocument();
expect(onNext).not.toHaveBeenCalled();
});
it('updates indexers and proceeds when valid', async () => {
const { ProwlarrStep } = await import('@/app/setup/steps/ProwlarrStep');
const onUpdate = vi.fn();
const onNext = vi.fn();
render(
<ProwlarrStep
prowlarrUrl="http://localhost:9696"
prowlarrApiKey="key"
onUpdate={onUpdate}
onNext={onNext}
onBack={vi.fn()}
/>
);
fireEvent.click(screen.getByRole('button', { name: 'Set Indexers' }));
await waitFor(() => {
expect(onUpdate).toHaveBeenCalledWith('prowlarrIndexers', indexersMock);
});
fireEvent.click(screen.getByRole('button', { name: 'Next' }));
expect(onNext).toHaveBeenCalled();
});
});