diff --git a/packages/module/src/AttachmentEdit/AttachmentEdit.test.tsx b/packages/module/src/AttachmentEdit/AttachmentEdit.test.tsx index 96e74b5f3..f49d8d266 100644 --- a/packages/module/src/AttachmentEdit/AttachmentEdit.test.tsx +++ b/packages/module/src/AttachmentEdit/AttachmentEdit.test.tsx @@ -1,4 +1,5 @@ -import { fireEvent, render, screen } from '@testing-library/react'; +import { fireEvent, render, screen, within } from '@testing-library/react'; +import '@testing-library/jest-dom'; import AttachmentEdit, { AttachmentEditProps } from './AttachmentEdit'; describe('AttachmentEdit', () => { @@ -51,4 +52,48 @@ describe('AttachmentEdit', () => { fireEvent.click(screen.getByText('Cancel')); expect(onCancelHandler).toHaveBeenCalled(); }); + + it('should render custom button text for footer actions buttons', () => { + render( + + ); + + expect(screen.getByText('Save')).toBeInTheDocument(); + expect(screen.getByText('Close')).toBeInTheDocument(); + }); + + it('should render AttachmentEdit with custom classNames', async () => { + render( + + ); + + const modal = screen.getByRole('dialog'); + const modalHeader = within(modal).getByRole('banner'); + expect(modalHeader).toHaveClass('custom-header-class'); + const modalBody = modal.querySelector('#code-modal-body'); + expect(modalBody).toHaveClass('custom-body-class'); + const modalfooter = within(modal).getByRole('contentinfo'); + expect(modalfooter).toHaveClass('custom-footer-class'); + }); }); diff --git a/packages/module/src/AttachmentEdit/AttachmentEdit.tsx b/packages/module/src/AttachmentEdit/AttachmentEdit.tsx index 7893e0a78..b4722f3d4 100644 --- a/packages/module/src/AttachmentEdit/AttachmentEdit.tsx +++ b/packages/module/src/AttachmentEdit/AttachmentEdit.tsx @@ -24,6 +24,16 @@ export interface AttachmentEditProps { displayMode?: ChatbotDisplayMode; /** Sets modal to compact styling. */ isCompact?: boolean; + /** Primary action button text */ + primaryActionButtonText?: string; + /** Secondary action button text */ + secondaryActionButtonText?: string; + /** Class applied to modal header */ + modalHeaderClassName?: string; + /** Class applied to modal body */ + modalBodyClassName?: string; + /** Class applied to modal footer */ + modalFooterClassName?: string; } export const AttachmentEdit: FunctionComponent = ({ @@ -35,7 +45,12 @@ export const AttachmentEdit: FunctionComponent = ({ onSave, title = 'Edit attachment', displayMode = ChatbotDisplayMode.default, - isCompact + isCompact, + modalHeaderClassName, + modalBodyClassName, + modalFooterClassName, + primaryActionButtonText = 'Save', + secondaryActionButtonText = 'Cancel' }: AttachmentEditProps) => { const handleSave = (_event: ReactMouseEvent | MouseEvent | KeyboardEvent, code) => { handleModalToggle(_event); @@ -55,11 +70,14 @@ export const AttachmentEdit: FunctionComponent = ({ isModalOpen={isModalOpen} onPrimaryAction={handleSave} onSecondaryAction={handleCancel} - primaryActionBtn="Save" - secondaryActionBtn="Cancel" + primaryActionBtn={primaryActionButtonText} + secondaryActionBtn={secondaryActionButtonText} title={title} displayMode={displayMode} isCompact={isCompact} + modalHeaderClassName={modalHeaderClassName} + modalBodyClassName={modalBodyClassName} + modalFooterClassName={modalFooterClassName} /> ); }; diff --git a/packages/module/src/CodeModal/CodeModal.test.tsx b/packages/module/src/CodeModal/CodeModal.test.tsx index 8297c3c40..e99b4f266 100644 --- a/packages/module/src/CodeModal/CodeModal.test.tsx +++ b/packages/module/src/CodeModal/CodeModal.test.tsx @@ -1,4 +1,4 @@ -import { render, screen } from '@testing-library/react'; +import { render, screen, within } from '@testing-library/react'; import '@testing-library/jest-dom'; import CodeModal from './CodeModal'; @@ -20,4 +20,32 @@ describe('ChatbotModal', () => { ); expect(screen.getByRole('dialog')).toHaveClass('pf-m-compact'); }); + + it('should render CodeModal with custom classNames', async () => { + render( + + ); + + const modal = screen.getByRole('dialog'); + const modalHeader = within(modal).getByRole('banner'); + expect(modalHeader).toHaveClass('custom-header-class'); + const modalBody = modal.querySelector('#code-modal-body'); + expect(modalBody).toHaveClass('custom-body-class'); + const modalfooter = within(modal).getByRole('contentinfo'); + expect(modalfooter).toHaveClass('custom-footer-class'); + }); }); diff --git a/packages/module/src/CodeModal/CodeModal.tsx b/packages/module/src/CodeModal/CodeModal.tsx index 53ee07d77..8672109c6 100644 --- a/packages/module/src/CodeModal/CodeModal.tsx +++ b/packages/module/src/CodeModal/CodeModal.tsx @@ -43,6 +43,12 @@ export interface CodeModalProps { displayMode?: ChatbotDisplayMode; /** Sets modal to compact styling. */ isCompact?: boolean; + /** Class applied to modal header */ + modalHeaderClassName?: string; + /** Class applied to modal body */ + modalBodyClassName?: string; + /** Class applied to modal footer */ + modalFooterClassName?: string; } export const CodeModal: FunctionComponent = ({ @@ -61,6 +67,9 @@ export const CodeModal: FunctionComponent = ({ title, displayMode = ChatbotDisplayMode.default, isCompact, + modalHeaderClassName, + modalBodyClassName, + modalFooterClassName, ...props }: CodeModalProps) => { const [newCode, setNewCode] = useState(code); @@ -102,8 +111,8 @@ export const CodeModal: FunctionComponent = ({ displayMode={displayMode} isCompact={isCompact} > - - + + @@ -130,7 +139,7 @@ export const CodeModal: FunctionComponent = ({ - + diff --git a/packages/module/src/PreviewAttachment/PreviewAttachment.test.tsx b/packages/module/src/PreviewAttachment/PreviewAttachment.test.tsx index 91d065ec1..5de87b057 100644 --- a/packages/module/src/PreviewAttachment/PreviewAttachment.test.tsx +++ b/packages/module/src/PreviewAttachment/PreviewAttachment.test.tsx @@ -1,4 +1,5 @@ -import { fireEvent, render, screen } from '@testing-library/react'; +import { fireEvent, render, screen, within } from '@testing-library/react'; +import '@testing-library/jest-dom'; import { PreviewAttachment } from './PreviewAttachment'; describe('PreviewAttachment', () => { @@ -47,4 +48,46 @@ describe('PreviewAttachment', () => { expect(onDismiss).toHaveBeenCalled(); }); + + it('should render custom button text for footer actions buttons', () => { + render( + + ); + + screen.getByText('Edit'); + screen.getByText('Close'); + }); + + it('should render PreviewAttachment with custom classNames', async () => { + render( + + ); + + const modal = screen.getByRole('dialog'); + const modalHeader = within(modal).getByRole('banner'); + expect(modalHeader).toHaveClass('custom-header-class'); + const modalBody = modal.querySelector('#code-modal-body'); + expect(modalBody).toHaveClass('custom-body-class'); + const modalfooter = within(modal).getByRole('contentinfo'); + expect(modalfooter).toHaveClass('custom-footer-class'); + }); }); diff --git a/packages/module/src/PreviewAttachment/PreviewAttachment.tsx b/packages/module/src/PreviewAttachment/PreviewAttachment.tsx index 0bc3c148e..4a87c3fb2 100644 --- a/packages/module/src/PreviewAttachment/PreviewAttachment.tsx +++ b/packages/module/src/PreviewAttachment/PreviewAttachment.tsx @@ -24,6 +24,16 @@ export interface PreviewAttachmentProps { displayMode?: ChatbotDisplayMode; /** Sets modal to compact styling. */ isCompact?: boolean; + /** Primary action button text */ + primaryActionButtonText?: string; + /** Secondary action button text */ + secondaryActionButtonText?: string; + /** Class applied to modal header */ + modalHeaderClassName?: string; + /** Class applied to modal body */ + modalBodyClassName?: string; + /** Class applied to modal footer */ + modalFooterClassName?: string; } export const PreviewAttachment: FunctionComponent = ({ @@ -34,7 +44,12 @@ export const PreviewAttachment: FunctionComponent = ({ onDismiss = undefined, onEdit, title = 'Preview attachment', + primaryActionButtonText = 'Edit', + secondaryActionButtonText = 'Dismiss', displayMode = ChatbotDisplayMode.default, + modalHeaderClassName, + modalBodyClassName, + modalFooterClassName, isCompact }: PreviewAttachmentProps) => { const handleEdit = (_event: MouseEvent | MouseEvent | KeyboardEvent) => { @@ -58,12 +73,15 @@ export const PreviewAttachment: FunctionComponent = ({ isModalOpen={isModalOpen} onPrimaryAction={handleEdit} onSecondaryAction={handleDismiss} - primaryActionBtn="Edit" - secondaryActionBtn="Dismiss" + primaryActionBtn={primaryActionButtonText} + secondaryActionBtn={secondaryActionButtonText} title={title} isReadOnly displayMode={displayMode} isCompact={isCompact} + modalHeaderClassName={modalHeaderClassName} + modalBodyClassName={modalBodyClassName} + modalFooterClassName={modalFooterClassName} /> ); };