"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 UserFeedback_1 = __importDefault(require("./UserFeedback"));
const MOCK_RESPONSES = [
    { id: '1', content: 'Helpful information', onClick: () => alert('Clicked helpful information') },
    { id: '2', content: 'Easy to understand', onClick: () => alert('Clicked easy to understand') },
    { id: '3', content: 'Resolved my issue', onClick: () => alert('Clicked resolved my issue') }
];
describe('UserFeedback', () => {
    it('should render correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, timestamp: "12/12/12" }));
        expect(react_1.screen.getByRole('heading', { name: /Why did you choose this rating?/i })).toBeTruthy();
        expect(react_1.screen.getByRole('list', { name: 'Quick feedback for message received at 12/12/12' })).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: /Helpful information/i })).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: /Easy to understand/i })).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: /Resolved my issue/i })).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: /Submit/i })).toBeTruthy();
        expect(react_1.screen.getByRole('button', { name: 'Close feedback for message received at 12/12/12' })).toBeTruthy();
        expect(react_1.screen.queryByRole('textbox', { name: /Provide optional additional feedback/i })).toBeFalsy();
    });
    it('should render different title correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, title: "Thanks! Why?" }));
        expect(react_1.screen.getByText('Thanks! Why?')).toBeTruthy();
    });
    it('should render different submit button text correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, submitWord: "Give feedback" }));
        expect(react_1.screen.getByRole('button', { name: /Give feedback/i })).toBeTruthy();
    });
    it('should render text area correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, hasTextArea: true }));
        expect(react_1.screen.getByRole('textbox', { name: /Provide optional additional feedback/i })).toBeTruthy();
    });
    it('should call onTextAreaChange correctly', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, hasTextArea: true, onTextAreaChange: spy }));
        const textbox = react_1.screen.getByRole('textbox', { name: /Provide optional additional feedback/i });
        yield user_event_1.default.type(textbox, 'test');
        expect(spy).toHaveBeenCalledTimes(4);
    }));
    it('should render different placeholder correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, hasTextArea: true, textAreaPlaceholder: "Provide any other information" }));
        expect(react_1.screen.getByRole('textbox', { name: /Provide optional additional feedback/i })).toHaveAttribute('placeholder', 'Provide any other information');
    });
    it('should render different text area label correctly', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, hasTextArea: true, textAreaAriaLabel: "Provide more details" }));
        expect(react_1.screen.getByRole('textbox', { name: /Provide more details/i })).toBeTruthy();
    });
    it('should handle onClose correctly when close button is clicked', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, onClose: spy, timestamp: "12/12/12" }));
        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)(UserFeedback_1.default, { timestamp: "12/12/12", onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, 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)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, 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)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, id: "test", "data-testid": "card" }));
        expect(react_1.screen.getByTestId('card').parentElement).toHaveAttribute('id', 'test');
    }));
    it('should handle submit correctly when nothing is selected', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: spy, quickResponses: MOCK_RESPONSES }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Submit/i }));
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy).toHaveBeenCalledWith(undefined, '');
    }));
    it('should handle submit correctly when item is selected', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: spy, quickResponses: MOCK_RESPONSES }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Easy to understand/i }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Submit/i }));
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy).toHaveBeenCalledWith('2', '');
    }));
    it('should handle submit correctly when there is just text input', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: spy, quickResponses: MOCK_RESPONSES, hasTextArea: true }));
        yield user_event_1.default.type(react_1.screen.getByRole('textbox', { name: /Provide optional additional feedback/i }), 'What a great experience!');
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Submit/i }));
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy).toHaveBeenCalledWith(undefined, 'What a great experience!');
    }));
    it('should handle submit correctly when item is selected and there is text input', () => __awaiter(void 0, void 0, void 0, function* () {
        const spy = jest.fn();
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: spy, quickResponses: MOCK_RESPONSES, hasTextArea: true }));
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Easy to understand/i }));
        yield user_event_1.default.type(react_1.screen.getByRole('textbox', { name: /Provide optional additional feedback/i }), 'What a great experience!');
        yield user_event_1.default.click(react_1.screen.getByRole('button', { name: /Submit/i }));
        expect(spy).toHaveBeenCalledTimes(1);
        expect(spy).toHaveBeenCalledWith('2', 'What a great experience!');
    }));
    it('should default title heading level to h1', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES }));
        expect(react_1.screen.getByRole('heading', { level: 1, name: /Why did you choose this rating?/i })).toBeTruthy();
    });
    it('should be able to change title heading level', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, headingLevel: "h6" }));
        expect(react_1.screen.getByRole('heading', { level: 6, name: /Why did you choose this rating?/i })).toBeTruthy();
    });
    it('should focus on load by default', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, "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)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, "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)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, "data-testid": "card", isCompact: true }));
        expect(react_1.screen.getByTestId('card')).toHaveClass('pf-m-compact');
    });
    it('should pass buttonProps to submit button', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, submitButtonProps: { variant: 'secondary', isDisabled: true } }));
        const submitButton = react_1.screen.getByRole('button', { name: /Submit/i });
        expect(submitButton).toHaveClass('pf-v6-c-button pf-m-secondary');
        expect(submitButton).toBeDisabled();
    });
    it('should pass cardHeaderProps to card header', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, cardHeaderProps: { 'data-testid': 'card-header', className: 'custom-header' } }));
        const cardHeader = react_1.screen.getByTestId('card-header');
        expect(cardHeader).toHaveClass('custom-header');
    });
    it('should pass cardBodyProps to card body', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, cardBodyProps: { 'data-testid': 'card-body', className: 'custom-body' } }));
        const cardBody = react_1.screen.getByTestId('card-body');
        expect(cardBody).toHaveClass('custom-body');
    });
    it('should pass headingLevelProps to title heading', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, headingLevelProps: { className: 'custom-heading', id: 'feedback-title' } }));
        const heading = react_1.screen.getByRole('heading', { level: 1, name: /Why did you choose this rating?/i });
        expect(heading).toHaveClass('custom-heading');
        expect(heading).toHaveAttribute('id', 'feedback-title');
    });
    it('should pass formProps to form', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, formProps: { 'data-testid': 'feedback-form', className: 'custom-form' } }));
        const form = react_1.screen.getByTestId('feedback-form');
        expect(form).toHaveClass('custom-form');
    });
    it('should pass textAreaProps to text area when hasTextArea is true', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, hasTextArea: true, textAreaProps: { 'data-testid': 'custom-textarea', rows: 5 } }));
        const textArea = react_1.screen.getByTestId('custom-textarea');
        expect(textArea).toHaveAttribute('rows', '5');
        expect(textArea).toHaveAttribute('data-testid', 'custom-textarea');
    });
    it('should pass actionGroupProps to action group', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsx)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, actionGroupProps: { 'data-testid': 'action-group', className: 'custom-actions' } }));
        const actionGroup = react_1.screen.getByTestId('action-group');
        expect(actionGroup).toHaveClass('custom-actions');
    });
    it('should render children', () => {
        (0, react_1.render)((0, jsx_runtime_1.jsxs)(UserFeedback_1.default, { timestamp: "12/12/12", onClose: jest.fn, onSubmit: jest.fn, quickResponses: MOCK_RESPONSES, children: [(0, jsx_runtime_1.jsx)("div", { "data-testid": "custom-content", children: "Custom feedback content" }), (0, jsx_runtime_1.jsx)("p", { children: "Additional paragraph" })] }));
        expect(react_1.screen.getByTestId('custom-content')).toBeInTheDocument();
        expect(react_1.screen.getByText('Custom feedback content')).toBeInTheDocument();
        expect(react_1.screen.getByText('Additional paragraph')).toBeInTheDocument();
    });
});
