"use strict";
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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = __importDefault(require("react"));
const react_2 = require("@testing-library/react");
require("@testing-library/jest-dom");
const user_event_1 = __importDefault(require("@testing-library/user-event"));
const AttachButton_1 = require("./AttachButton");
describe('Attach button', () => {
    it('should render button correctly', () => {
        (0, react_2.render)(react_1.default.createElement(AttachButton_1.AttachButton, null));
        expect(react_2.screen.getByRole('button', { name: 'Attach button' })).toBeTruthy();
    });
    it('should handle isDisabled prop', () => {
        (0, react_2.render)(react_1.default.createElement(AttachButton_1.AttachButton, { isDisabled: true }));
        expect(react_2.screen.getByRole('button', { name: 'Attach button' })).toBeDisabled();
    });
    it('should handle spread props, including aria-label', () => {
        (0, react_2.render)(react_1.default.createElement(AttachButton_1.AttachButton, { "aria-label": "test" }));
        expect(react_2.screen.getByRole('button', { name: 'test' }));
    });
    it('should handle onClick', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_2.render)(react_1.default.createElement(AttachButton_1.AttachButton, { onClick: spy }));
        yield user_event_1.default.click(react_2.screen.getByRole('button', { name: 'Attach button' }));
        expect(react_2.screen.getByRole('tooltip', { name: 'Attach' })).toBeTruthy();
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should handle className prop', () => {
        (0, react_2.render)(react_1.default.createElement(AttachButton_1.AttachButton, { className: "test" }));
        expect(react_2.screen.getByRole('button', { name: 'Attach button' })).toHaveClass('test');
    });
    it('should handle custom tooltip correctly', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_2.render)(react_1.default.createElement(AttachButton_1.AttachButton, { onClick: jest.fn, tooltipContent: "Test" }));
        yield user_event_1.default.click(react_2.screen.getByRole('button', { name: 'Attach button' }));
        expect(react_2.screen.getByRole('tooltip', { name: 'Test' })).toBeTruthy();
    }));
    it('should handle tooltipProps prop', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_2.render)(react_1.default.createElement(AttachButton_1.AttachButton, { tooltipProps: { id: 'test' } }));
        yield user_event_1.default.click(react_2.screen.getByRole('button', { name: 'Attach button' }));
        expect(react_2.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();
        (0, react_2.render)(react_1.default.createElement(AttachButton_1.AttachButton, { onAttachAccepted: spy, inputTestId: "input" }));
        yield user_event_1.default.click(react_2.screen.getByRole('button', { name: 'Attach button' }));
        const file = new File(['test'], 'test.json');
        const input = react_2.screen.getByTestId('input');
        yield user_event_1.default.upload(input, file);
        expect(input.files).toHaveLength(1);
        expect(spy).toHaveBeenCalledTimes(1);
    }));
});
