"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 jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = 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"));
const react_icons_1 = require("@patternfly/react-icons");
describe('FileDetailsLabel', () => {
    it('should render file details label', () => {
        const { container } = (0, react_1.render)((0, jsx_runtime_1.jsx)(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_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.txt" }));
        expect(react_1.screen.getByText('test')).toBeTruthy();
        expect(react_1.screen.getByText('TEXT')).toBeTruthy();
    });
    it('should skip language if we do not support an extension', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.joke", languageTestId: "language" }));
        expect(react_1.screen.getByText('test')).toBeTruthy();
        expect(react_1.screen.queryByTestId('language')).toBeFalsy();
    });
    it('should pass file size down', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.svg", fileSize: "100MB" }));
        expect(react_1.screen.getByText('100MB')).toBeTruthy();
    });
    it('should pass truncation prop down as true by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.svg" }));
        expect(react_1.screen.getByText('test')).toBeTruthy();
        expect(react_1.screen.queryByText('test.svg')).toBeFalsy();
    });
    it('should pass truncation prop down when false', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.svg", hasTruncation: false }));
        expect(react_1.screen.getByText('test.svg')).toBeTruthy();
    });
    it('should not show spinner by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.txt", spinnerTestId: "spinner" }));
        expect(react_1.screen.queryByTestId('spinner')).toBeFalsy();
    });
    it('should show spinner if loading', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.txt", isLoading: true, spinnerTestId: "spinner" }));
        expect(react_1.screen.getByText('test')).toBeTruthy();
        expect(react_1.screen.getByText('TEXT')).toBeTruthy();
        expect(react_1.screen.queryByTestId('spinner')).toBeTruthy();
    });
    it('should call onClick prop', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.txt", onClick: spy }));
        yield user_event_1.default.click(react_1.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_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.txt", onClose: spy }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Close test.txt/i }));
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should use closeButtonAriaLabel prop appropriately', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.txt", onClose: jest.fn(), closeButtonAriaLabel: "Delete file" }));
        expect(react_1.screen.getByRole('button', { name: /Delete file/i })).toBeTruthy();
    });
    it('should support custom close icon', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(FileDetailsLabel_1.default, { fileName: "test.txt", onClose: jest.fn(), closeButtonIcon: (0, jsx_runtime_1.jsx)(react_icons_1.BellIcon, { "data-testid": "bell" }) }));
        expect(react_1.screen.getByTestId('bell')).toBeTruthy();
    });
});
