import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { render, screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import { describe, expect, it } from 'vitest';
import { renderWithForm } from '../../lib/testing.js';
import { Form } from '../form/index.js';
import { CurrencyCodeField } from './currency-code-field.js';
import { currencies } from '../../../ui/components/data-entry/currency-code-picker/utils.js';
describe('CurrencyCodeField', () => {
    it('should match snapshot', () => {
        const { container } = renderWithForm(_jsx(CurrencyCodeField, { name: "currency", label: "Currency", description: "Select a currency", value: "USD", currencies: currencies() }));
        expect(container).toMatchSnapshot();
    });
    it('should render with default props', () => {
        renderWithForm(_jsx(CurrencyCodeField, { name: "currency", label: "Currency", currencies: currencies() }));
        expect(screen.getByRole('combobox')).toBeInTheDocument();
        expect(screen.getByText('Currency')).toBeInTheDocument();
    });
    it('should show an error if trying to submit empty with required enabled', async () => {
        const user = userEvent.setup();
        renderWithForm(_jsxs(_Fragment, { children: [_jsx(CurrencyCodeField, { name: "currency", label: "Currency", required: true, currencies: currencies() }), _jsx("button", { type: "submit", children: "Submit" })] }));
        await user.click(screen.getByText('Submit'));
        expect(screen.getByText('This field is required')).toBeInTheDocument();
    });
    it('should submit the currency code', async () => {
        const onSubmit = vitest.fn();
        const user = userEvent.setup();
        render(_jsxs(Form, { onSubmit: onSubmit, children: [_jsx(CurrencyCodeField, { name: "currency", label: "Currency", value: "USD", currencies: currencies() }), _jsx("button", { type: "submit", children: "Submit" })] }));
        await user.click(screen.getByText('Submit'));
        expect(onSubmit).toHaveBeenCalledWith({ currency: 'USD' });
    });
    it('should handle disabled state', () => {
        renderWithForm(_jsx(CurrencyCodeField, { name: "currency", label: "Currency", disabled: true, currencies: currencies() }));
        expect(screen.getByRole('combobox')).toBeDisabled();
    });
    it('should display custom errors', async () => {
        const errors = ['Please select a valid currency'];
        renderWithForm(_jsx(CurrencyCodeField, { name: "currency", label: "Currency", errors: errors, currencies: currencies() }));
        expect(await screen.findByText(errors[0])).toBeInTheDocument();
    });
    it('should display custom warnings', async () => {
        const warnings = ['This currency may have restrictions'];
        renderWithForm(_jsx(CurrencyCodeField, { name: "currency", label: "Currency", warnings: warnings, currencies: currencies() }));
        expect(await screen.findByText(warnings[0])).toBeInTheDocument();
    });
});
//# sourceMappingURL=currency-code-field.test.js.map