var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { jsx as _jsx } from "react/jsx-runtime";
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import FileDropZone from './FileDropZone';
import userEvent from '@testing-library/user-event';
describe('FileDropZone', () => {
    it('should render file drop zone', () => {
        const { container } = render(_jsx(FileDropZone, { onFileDrop: jest.fn() }));
        expect(container).toMatchSnapshot();
    });
    it('should render children', () => {
        render(_jsx(FileDropZone, { onFileDrop: jest.fn(), children: "Hi" }));
        expect(screen.getByText('Hi')).toBeTruthy();
    });
    it('should call onFileDrop when file type is accepted', () => __awaiter(void 0, void 0, void 0, function* () {
        const onFileDrop = jest.fn();
        const { container } = render(_jsx(FileDropZone, { "data-testid": "input", allowedFileTypes: { 'text/plain': ['.txt'] }, onFileDrop: onFileDrop }));
        const file = new File(['Test'], 'example.text', { type: 'text/plain' });
        const fileInput = container.querySelector('input[type="file"]');
        yield userEvent.upload(fileInput, file);
        expect(onFileDrop).toHaveBeenCalled();
    }));
    it('should not call onFileDrop when file type is not accepted', () => __awaiter(void 0, void 0, void 0, function* () {
        const onFileDrop = jest.fn();
        const { container } = render(_jsx(FileDropZone, { "data-testid": "input", allowedFileTypes: { 'text/plain': ['.txt'] }, onFileDrop: onFileDrop }));
        const file = new File(['[]'], 'example.json', { type: 'application/json' });
        const fileInput = container.querySelector('input[type="file"]');
        yield userEvent.upload(fileInput, file);
        expect(onFileDrop).not.toHaveBeenCalled();
    }));
    it('should respect minSize restriction', () => __awaiter(void 0, void 0, void 0, function* () {
        const onAttachRejected = jest.fn();
        const { container } = render(_jsx(FileDropZone, { onFileDrop: jest.fn(), minSize: 1000, onAttachRejected: onAttachRejected }));
        const file = new File(['Test'], 'example.txt', { type: 'text/plain' });
        const fileInput = container.querySelector('input[type="file"]');
        yield userEvent.upload(fileInput, file);
        expect(onAttachRejected).toHaveBeenCalled();
    }));
    it('should respect maxSize restriction', () => __awaiter(void 0, void 0, void 0, function* () {
        const onAttachRejected = jest.fn();
        const { container } = render(_jsx(FileDropZone, { onFileDrop: jest.fn(), maxSize: 100, onAttachRejected: onAttachRejected }));
        const largeContent = 'x'.repeat(200);
        const file = new File([largeContent], 'example.txt', { type: 'text/plain' });
        const fileInput = container.querySelector('input[type="file"]');
        yield userEvent.upload(fileInput, file);
        expect(onAttachRejected).toHaveBeenCalled();
    }));
    it('should respect maxFiles restriction', () => __awaiter(void 0, void 0, void 0, function* () {
        const onAttachRejected = jest.fn();
        const { container } = render(_jsx(FileDropZone, { onFileDrop: jest.fn(), maxFiles: 1, onAttachRejected: onAttachRejected }));
        const files = [
            new File(['Test1'], 'example1.txt', { type: 'text/plain' }),
            new File(['Test2'], 'example2.txt', { type: 'text/plain' })
        ];
        const fileInput = container.querySelector('input[type="file"]');
        yield userEvent.upload(fileInput, files);
        expect(onAttachRejected).toHaveBeenCalled();
    }));
    it('should be disabled when isAttachmentDisabled is true', () => __awaiter(void 0, void 0, void 0, function* () {
        const onFileDrop = jest.fn();
        const { container } = render(_jsx(FileDropZone, { onFileDrop: onFileDrop, isAttachmentDisabled: true }));
        const file = new File(['Test'], 'example.text', { type: 'text/plain' });
        const fileInput = container.querySelector('input[type="file"]');
        yield userEvent.upload(fileInput, file);
        expect(onFileDrop).not.toHaveBeenCalled();
    }));
    it('should call onAttach when files are attached', () => __awaiter(void 0, void 0, void 0, function* () {
        const onAttach = jest.fn();
        const { container } = render(_jsx(FileDropZone, { onFileDrop: jest.fn(), onAttach: onAttach }));
        const file = new File(['Test'], 'example.txt', { type: 'text/plain' });
        const fileInput = container.querySelector('input[type="file"]');
        yield userEvent.upload(fileInput, file);
        expect(onAttach).toHaveBeenCalled();
    }));
    it('should use custom validator when provided', () => __awaiter(void 0, void 0, void 0, function* () {
        const validator = jest.fn().mockReturnValue({ message: 'Custom error' });
        const onAttachRejected = jest.fn();
        const onFileDrop = jest.fn();
        const { container } = render(_jsx(FileDropZone, { onFileDrop: onFileDrop, validator: validator, onAttachRejected: onAttachRejected }));
        const file = new File(['Test'], 'example.txt', { type: 'text/plain' });
        const fileInput = container.querySelector('input[type="file"]');
        yield userEvent.upload(fileInput, file);
        expect(validator).toHaveBeenCalledWith(file);
        expect(onAttachRejected).toHaveBeenCalled();
    }));
});
