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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { act, render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import userEvent from '@testing-library/user-event';
import UserFeedbackComplete from './UserFeedbackComplete';
describe('UserFeedbackComplete', () => {
    it('should render correctly', () => {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12" }));
        expect(screen.getByText('Feedback submitted')).toBeTruthy();
        screen.getByText(/We've received your response. Thank you for sharing your feedback!/i);
        expect(screen.queryByRole('button', { name: /Close/i })).toBeFalsy();
    });
    it('should render different title correctly', () => {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", title: "Thanks!" }));
        expect(screen.getByText('Thanks!')).toBeTruthy();
        screen.getByText(/We've received your response. Thank you for sharing your feedback!/i);
    });
    it('should render different string body correctly', () => {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", body: "Thanks!" }));
        expect(screen.getByText('Feedback submitted')).toBeTruthy();
        expect(screen.getByText('Thanks!')).toBeTruthy();
    });
    it('should render different node body correctly', () => {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", body: _jsx("div", { children: "Thanks!" }) }));
        expect(screen.getByText('Feedback submitted')).toBeTruthy();
        expect(screen.getByText('Thanks!')).toBeTruthy();
    });
    it('should handle onClose correctly', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", onClose: spy }));
        const closeButton = screen.getByRole('button', { name: 'Close feedback for message received at 12/12/12' });
        expect(closeButton).toBeTruthy();
        yield userEvent.click(closeButton);
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should be able to change close button aria label', () => {
        const spy = jest.fn();
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", onClose: spy, closeButtonAriaLabel: "Ima button" }));
        expect(screen.getByRole('button', { name: /Ima button/i })).toBeTruthy();
    });
    it('should handle className', () => __awaiter(void 0, void 0, void 0, function* () {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", className: "test", "data-testid": "card" }));
        expect(screen.getByTestId('card')).toHaveClass('test');
    }));
    it('should apply id', () => __awaiter(void 0, void 0, void 0, function* () {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", id: "test", "data-testid": "card" }));
        expect(screen.getByTestId('card').parentElement).toHaveAttribute('id', 'test');
    }));
    it('renders with no timeout by default', () => {
        jest.useFakeTimers();
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12" }));
        act(() => {
            jest.advanceTimersByTime(8000);
        });
        expect(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();
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true }));
        act(() => {
            jest.advanceTimersByTime(7999);
        });
        expect(screen.getByText('Feedback submitted')).toBeVisible();
        act(() => {
            jest.advanceTimersByTime(1);
        });
        expect(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();
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: 300 }));
        act(() => {
            jest.advanceTimersByTime(299);
        });
        expect(screen.getByText('Feedback submitted')).toBeVisible();
        act(() => {
            jest.advanceTimersByTime(1);
        });
        expect(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 = userEvent.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true, "data-testid": "card" }));
        expect(screen.getByText('Feedback submitted')).toBeTruthy();
        yield user.click(screen.getByTestId('card'));
        act(() => {
            jest.advanceTimersByTime(8000);
        });
        expect(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 = userEvent.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true, "data-testid": "card" }));
        const card = screen.getByTestId('card');
        yield user.hover(card);
        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 = userEvent.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        render(_jsxs("div", { children: [_jsx("input", {}), _jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true, "data-testid": "card" })] }));
        const card = screen.getByTestId('card');
        yield user.click(card);
        act(() => {
            jest.advanceTimersByTime(8000);
        });
        yield user.click(screen.getByRole('textbox'));
        act(() => {
            jest.advanceTimersByTime(3000);
        });
        expect(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 = userEvent.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        render(_jsxs("div", { children: [_jsx("input", {}), _jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true, "data-testid": "card" })] }));
        const card = screen.getByTestId('card');
        yield user.hover(card);
        act(() => {
            jest.advanceTimersByTime(8000);
        });
        yield user.hover(screen.getByRole('textbox'));
        act(() => {
            jest.advanceTimersByTime(3000);
        });
        expect(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 = userEvent.setup({
            advanceTimers: (delay) => jest.advanceTimersByTime(delay)
        });
        jest.useFakeTimers();
        render(_jsxs("div", { children: [_jsx("input", {}), _jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true, "data-testid": "card", timeoutAnimation: 1000 })] }));
        const card = screen.getByTestId('card');
        yield user.hover(card);
        act(() => {
            jest.advanceTimersByTime(8000);
        });
        yield user.hover(screen.getByRole('textbox'));
        act(() => {
            jest.advanceTimersByTime(1000);
        });
        expect(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();
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true, "data-testid": "card", onTimeout: spy }));
        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();
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true, "data-testid": "card", onTimeout: spy }));
        act(() => {
            jest.advanceTimersByTime(8000);
        });
        expect(spy).toHaveBeenCalledTimes(1);
        jest.useRealTimers();
    });
    it('renders without aria-live and aria-atomic attributes by default', () => {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true, "data-testid": "card" }));
        const card = 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', () => {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", timeout: true, "data-testid": "card", isLiveRegion: true }));
        const card = 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 = userEvent.setup();
        render(_jsxs("div", { children: [_jsx("input", {}), _jsx(UserFeedbackComplete, { timestamp: "12/12/12", "data-testid": "card", onMouseEnter: spy })] }));
        const card = 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 = userEvent.setup();
        render(_jsxs("div", { children: [_jsx("input", {}), _jsx(UserFeedbackComplete, { timestamp: "12/12/12", "data-testid": "card", onMouseLeave: spy })] }));
        const card = screen.getByTestId('card');
        expect(spy).toHaveBeenCalledTimes(0);
        yield user.hover(card);
        yield user.hover(screen.getByRole('textbox'));
        expect(spy).toHaveBeenCalledTimes(1);
    }));
    it('should focus on load by default', () => {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", "data-testid": "card" }));
        expect(screen.getByTestId('card').parentElement).toHaveFocus();
    });
    it('should not focus on load if focusOnLoad = false', () => {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", "data-testid": "card", focusOnLoad: false }));
        expect(screen.getByTestId('card').parentElement).not.toHaveFocus();
    });
    it('should handle isCompact', () => {
        render(_jsx(UserFeedbackComplete, { timestamp: "12/12/12", "data-testid": "card", isCompact: true }));
        expect(screen.getByTestId('card')).toHaveClass('pf-m-compact');
    });
});
