import { jsx as _jsx } from "react/jsx-runtime";
// @vitest-environment happy-dom
import { describe, expect, it, vi } from 'vitest';
import { fireEvent, render, screen } from '@testing-library/react';
import { FormsPagination } from '../../components/forms/primitives.js';
describe('FormsPagination', () => {
    it('renders nothing when results fit on a single page', () => {
        const { container } = render(_jsx(FormsPagination, { page: 1, pageSize: 25, total: 10, onPageChange: () => { } }));
        expect(container.firstChild).toBeNull();
    });
    it('shows the result range and page controls across multiple pages', () => {
        render(_jsx(FormsPagination, { page: 1, pageSize: 10, total: 42, onPageChange: () => { }, noun: "submission" }));
        expect(screen.getByText('1–10 of 42 submissions')).toBeTruthy();
        expect(screen.getByRole('button', { name: 'Next page' })).toBeTruthy();
        expect(screen.getByLabelText('Previous page')).toHaveProperty('disabled', true);
    });
    it('advances and clamps page navigation', () => {
        const onPageChange = vi.fn();
        render(_jsx(FormsPagination, { page: 2, pageSize: 10, total: 42, onPageChange: onPageChange, noun: "form" }));
        // Range reflects the current page.
        expect(screen.getByText('11–20 of 42 forms')).toBeTruthy();
        fireEvent.click(screen.getByRole('button', { name: 'Next page' }));
        expect(onPageChange).toHaveBeenCalledWith(3);
        fireEvent.click(screen.getByLabelText('Previous page'));
        expect(onPageChange).toHaveBeenCalledWith(1);
    });
    it('caps the last page so the final partial page shows the true total', () => {
        render(_jsx(FormsPagination, { page: 5, pageSize: 10, total: 42, onPageChange: () => { }, noun: "form" }));
        expect(screen.getByText('41–42 of 42 forms')).toBeTruthy();
        expect(screen.getByRole('button', { name: 'Next page' })).toHaveProperty('disabled', true);
    });
});
//# sourceMappingURL=forms-pagination.render.test.js.map