"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 FileDetailsLabel_1 = __importDefault(require("./FileDetailsLabel"));
const user_event_1 = __importDefault(require("@testing-library/user-event"));
describe('FileDetailsLabel', () => {
    it('should render file details label', () => {
        const { container } = (0, react_2.render)(react_1.default.createElement(FileDetailsLabel_1.default, { fileName: "test.txt" }));
        expect(container).toMatchSnapshot();
    });
    it('should render file details correctly if an extension we support is passed in', () => {
        (0, react_2.render)(react_1.default.createElement(FileDetailsLabel_1.default, { fileName: "test.txt" }));
        expect(react_2.screen.getByText('test')).toBeTruthy();
        expect(react_2.screen.getByText('TEXT')).toBeTruthy();
    });
    it('should skip language if we do not support an extension', () => {
        (0, react_2.render)(react_1.default.createElement(FileDetailsLabel_1.default, { fileName: "test.joke", languageTestId: "language" }));
        expect(react_2.screen.getByText('test')).toBeTruthy();
        expect(react_2.screen.queryByTestId('language')).toBeFalsy();
    });
    it('should not show spinner by default', () => {
        (0, react_2.render)(react_1.default.createElement(FileDetailsLabel_1.default, { fileName: "test.txt", spinnerTestId: "spinner" }));
        expect(react_2.screen.queryByTestId('spinner')).toBeFalsy();
    });
    it('should show spinner if loading', () => {
        (0, react_2.render)(react_1.default.createElement(FileDetailsLabel_1.default, { fileName: "test.txt", isLoading: true, spinnerTestId: "spinner" }));
        expect(react_2.screen.getByText('test')).toBeTruthy();
        expect(react_2.screen.getByText('TEXT')).toBeTruthy();
        expect(react_2.screen.queryByTestId('spinner')).toBeTruthy();
    });
    it('should call onClick prop', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_2.render)(react_1.default.createElement(FileDetailsLabel_1.default, { fileName: "test.txt", onClick: spy }));
        yield user_event_1.default.click(react_2.screen.getByRole('button'));
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should call onClose prop', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_2.render)(react_1.default.createElement(FileDetailsLabel_1.default, { fileName: "test.txt", onClose: spy }));
        yield user_event_1.default.click(react_2.screen.getByRole('button', { name: /Close test.txt/i }));
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should use closeButtonAriaLabel prop appropriately', () => {
        (0, react_2.render)(react_1.default.createElement(FileDetailsLabel_1.default, { fileName: "test.txt", onClose: jest.fn(), closeButtonAriaLabel: "Delete file" }));
        react_2.screen.getByRole('button', { name: /Delete file/i });
    });
});
