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 React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import { AttachButton } from './AttachButton';
describe('Attach button', () => {
    it('should render button correctly', () => {
        render(React.createElement(AttachButton, null));
        expect(screen.getByRole('button', { name: 'Attach' })).toBeTruthy();
    });
    it('should handle isDisabled prop', () => {
        render(React.createElement(AttachButton, { isDisabled: true }));
        expect(screen.getByRole('button', { name: 'Attach' })).toBeDisabled();
    });
    it('should handle spread props, including aria-label', () => {
        render(React.createElement(AttachButton, { "aria-label": "test" }));
        expect(screen.getByRole('button', { name: 'test' }));
    });
    it('should handle onClick', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        render(React.createElement(AttachButton, { onClick: spy }));
        yield userEvent.click(screen.getByRole('button', { name: 'Attach' }));
        expect(screen.getByRole('tooltip', { name: 'Attach' })).toBeTruthy();
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should handle className prop', () => {
        render(React.createElement(AttachButton, { className: "test" }));
        expect(screen.getByRole('button', { name: 'Attach' })).toHaveClass('test');
    });
    it('should handle custom tooltip correctly', () => __awaiter(void 0, void 0, void 0, function* () {
        render(React.createElement(AttachButton, { onClick: jest.fn, tooltipContent: "Test" }));
        yield userEvent.click(screen.getByRole('button', { name: 'Attach' }));
        expect(screen.getByRole('tooltip', { name: 'Test' })).toBeTruthy();
    }));
    it('should handle tooltipProps prop', () => __awaiter(void 0, void 0, void 0, function* () {
        render(React.createElement(AttachButton, { tooltipProps: { id: 'test' } }));
        yield userEvent.click(screen.getByRole('button', { name: 'Attach' }));
        expect(screen.getByRole('tooltip', { name: 'Attach' })).toHaveAttribute('id', 'test');
    }));
    // Based on this because I had no idea how to do this and was looking around: https://stackoverflow.com/a/75562651
    // See also https://developer.mozilla.org/en-US/docs/Web/API/File/File for what that file variable is doing
    it('should handle onAttachAccepted prop', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        render(React.createElement(AttachButton, { onAttachAccepted: spy, inputTestId: "input" }));
        yield userEvent.click(screen.getByRole('button', { name: 'Attach' }));
        const file = new File(['test'], 'test.json');
        const input = screen.getByTestId('input');
        yield userEvent.upload(input, file);
        expect(input.files).toHaveLength(1);
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should handle isCompact', () => {
        render(React.createElement(AttachButton, { isCompact: true, "data-testid": "button" }));
        expect(screen.getByTestId('button')).toHaveClass('pf-m-compact');
    });
});
