"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 user_event_1 = __importDefault(require("@testing-library/user-event"));
const UserFeedbackComplete_1 = __importDefault(require("./UserFeedbackComplete"));
describe('UserFeedbackComplete', () => {
    it('should render correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12" }));
        expect(react_1.screen.getByText('Feedback submitted')).toBeTruthy();
        react_1.screen.getByText(/We've received your response. Thank you for sharing your feedback!/i);
        expect(react_1.screen.queryByRole('button', { name: /Close/i })).toBeFalsy();
    });
    it('should render different title correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", title: "Thanks!" }));
        expect(react_1.screen.getByText('Thanks!')).toBeTruthy();
        react_1.screen.getByText(/We've received your response. Thank you for sharing your feedback!/i);
    });
    it('should render different string body correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", body: "Thanks!" }));
        expect(react_1.screen.getByText('Feedback submitted')).toBeTruthy();
        expect(react_1.screen.getByText('Thanks!')).toBeTruthy();
    });
    it('should render different node body correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", body: (0, jsx_runtime_1.jsx)("div", { children: "Thanks!" }) }));
        expect(react_1.screen.getByText('Feedback submitted')).toBeTruthy();
        expect(react_1.screen.getByText('Thanks!')).toBeTruthy();
    });
    it('should handle onClose correctly', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", onClose: spy }));
        const closeButton = react_1.screen.getByRole('button', { name: 'Close feedback for message received at 12/12/12' });
        expect(closeButton).toBeTruthy();
        yield user_event_1.default.click(closeButton);
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should be able to change close button aria label', () => {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", onClose: spy, closeButtonAriaLabel: "Ima button" }));
        expect(react_1.screen.getByRole('button', { name: /Ima button/i })).toBeTruthy();
    });
    it('should handle className', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", className: "test", "data-testid": "card" }));
        expect(react_1.screen.getByTestId('card')).toHaveClass('test');
    }));
    it('should apply id', () => __awaiter(void 0, void 0, void 0, function* () {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", id: "test", "data-testid": "card" }));
        expect(react_1.screen.getByTestId('card').parentElement).toHaveAttribute('id', 'test');
    }));
    it('renders with no timeout by default', () => {
        jest.useFakeTimers();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12" }));
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(8000);
        });
        expect(react_1.screen.getByText('Feedback submitted')).toBeVisible();
        jest.useRealTimers();
    });
    it('should handle timeout correctly after 8000ms when timeout = true', () => __awaiter(void 0, void 0, void 0, function* () {
        jest.useFakeTimers();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true }));
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(7999);
        });
        expect(react_1.screen.getByText('Feedback submitted')).toBeVisible();
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(1);
        });
        expect(react_1.screen.queryByText('Feedback submitted')).not.toBeInTheDocument();
        jest.useRealTimers();
    }));
    it('should handle timeout correctly when timeout = numeric value', () => __awaiter(void 0, void 0, void 0, function* () {
        jest.useFakeTimers();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: 300 }));
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(299);
        });
        expect(react_1.screen.getByText('Feedback submitted')).toBeVisible();
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(1);
        });
        expect(react_1.screen.queryByText('Feedback submitted')).not.toBeInTheDocument();
        jest.useRealTimers();
    }));
    it('does not get removed on timeout if the user is focused on the card', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = user_event_1.default.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true, "data-testid": "card" }));
        expect(react_1.screen.getByText('Feedback submitted')).toBeTruthy();
        yield user.click(react_1.screen.getByTestId('card'));
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(8000);
        });
        expect(react_1.screen.getByText('Feedback submitted')).toBeTruthy();
        jest.useRealTimers();
    }));
    it('does not remove the card on timeout if the user is hovered over it', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = user_event_1.default.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true, "data-testid": "card" }));
        const card = react_1.screen.getByTestId('card');
        yield user.hover(card);
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(8000);
        });
        expect(card).toBeVisible();
        jest.useRealTimers();
    }));
    it('removes the card after the user removes focus from the card and 3000ms have passed', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = user_event_1.default.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        (0, react_1.render)((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("input", {}), (0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true, "data-testid": "card" })] }));
        const card = react_1.screen.getByTestId('card');
        yield user.click(card);
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(8000);
        });
        yield user.click(react_1.screen.getByRole('textbox'));
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(3000);
        });
        expect(react_1.screen.queryByText('Feedback submitted')).not.toBeInTheDocument();
        jest.useRealTimers();
    }));
    it('removes the card after the user removes hover from the card and 3000ms have passed', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = user_event_1.default.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        (0, react_1.render)((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("input", {}), (0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true, "data-testid": "card" })] }));
        const card = react_1.screen.getByTestId('card');
        yield user.hover(card);
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(8000);
        });
        yield user.hover(react_1.screen.getByRole('textbox'));
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(3000);
        });
        expect(react_1.screen.queryByText('Feedback submitted')).not.toBeInTheDocument();
        jest.useRealTimers();
    }));
    it('removes the card after the user removes hover from the card and timeoutAnimation time has passed', () => __awaiter(void 0, void 0, void 0, function* () {
        const user = user_event_1.default.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        (0, react_1.render)((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("input", {}), (0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true, "data-testid": "card", timeoutAnimation: 1000 })] }));
        const card = react_1.screen.getByTestId('card');
        yield user.hover(card);
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(8000);
        });
        yield user.hover(react_1.screen.getByRole('textbox'));
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(1000);
        });
        expect(react_1.screen.queryByText('Feedback submitted')).not.toBeInTheDocument();
        jest.useRealTimers();
    }));
    it('does not call the onTimeout callback before the timeout period has expired', () => {
        const spy = jest.fn();
        jest.useFakeTimers();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true, "data-testid": "card", onTimeout: spy }));
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(7999);
        });
        expect(spy).not.toHaveBeenCalled();
        jest.useRealTimers();
    });
    it('calls the onTimeout callback after the timeout period has expired', () => {
        jest.useFakeTimers();
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true, "data-testid": "card", onTimeout: spy }));
        (0, react_1.act)(() => {
            jest.advanceTimersByTime(8000);
        });
        expect(spy).toHaveBeenCalledTimes(1);
        jest.useRealTimers();
    });
    it('renders without aria-live and aria-atomic attributes by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true, "data-testid": "card" }));
        const card = react_1.screen.getByTestId('card').parentElement;
        expect(card).not.toHaveAttribute('aria-live');
        expect(card).not.toHaveAttribute('aria-atomic');
    });
    it('has an aria-live value of polite and aria-atomic value of false when isLiveRegion = true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", timeout: true, "data-testid": "card", isLiveRegion: true }));
        const card = react_1.screen.getByTestId('card').parentElement;
        expect(card).toHaveAttribute('aria-live', 'polite');
        expect(card).toHaveAttribute('aria-atomic', 'false');
    });
    it('calls onMouseEnter appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        const user = user_event_1.default.setup();
        (0, react_1.render)((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("input", {}), (0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", "data-testid": "card", onMouseEnter: spy })] }));
        const card = react_1.screen.getByTestId('card');
        expect(spy).toHaveBeenCalledTimes(0);
        yield user.hover(card);
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('calls onMouseLeave appropriately', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        const user = user_event_1.default.setup();
        (0, react_1.render)((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("input", {}), (0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", "data-testid": "card", onMouseLeave: spy })] }));
        const card = react_1.screen.getByTestId('card');
        expect(spy).toHaveBeenCalledTimes(0);
        yield user.hover(card);
        yield user.hover(react_1.screen.getByRole('textbox'));
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should focus on load by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", "data-testid": "card" }));
        expect(react_1.screen.getByTestId('card').parentElement).toHaveFocus();
    });
    it('should not focus on load if focusOnLoad = false', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", "data-testid": "card", focusOnLoad: false }));
        expect(react_1.screen.getByTestId('card').parentElement).not.toHaveFocus();
    });
    it('should handle isCompact', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedbackComplete_1.default, { timestamp: "12/12/12", "data-testid": "card", isCompact: true }));
        expect(react_1.screen.getByTestId('card')).toHaveClass('pf-m-compact');
    });
});
