diff --git a/client/src/components/Chat/Input/Files/FileContainer.tsx b/client/src/components/Chat/Input/Files/FileContainer.tsx index 551f477a84..92381e82a6 100644 --- a/client/src/components/Chat/Input/Files/FileContainer.tsx +++ b/client/src/components/Chat/Input/Files/FileContainer.tsx @@ -14,6 +14,7 @@ const FileContainer = ({ containerClassName, onDelete, onClick, + disabled, }: { file: Partial; overrideType?: string; @@ -36,6 +37,7 @@ const FileContainer = ({ containerClassName?: string; onDelete?: () => void; onClick?: React.MouseEventHandler; + disabled?: boolean; }) => { const fileType = getFileType(overrideType ?? file.type); const visibleName = displayName ?? file.filename ?? ''; @@ -47,9 +49,11 @@ const FileContainer = ({ + ), +})); + +jest.mock('../FilePreviewDialog', () => ({ + __esModule: true, + default: ({ open, fileId }: { open: boolean; fileId?: string }) => + open ?
: null, +})); + +jest.mock('../Image', () => ({ + __esModule: true, + default: ({ altText }: { altText: string }) => {altText}, +})); + +const messageWithFile = (file: Partial): TMessage => + ({ + messageId: 'message-1', + files: [ + { + file_id: 'file-1', + filename: 'example.txt', + type: 'text/plain', + bytes: 12, + ...file, + }, + ], + }) as TMessage; + +describe('message file previews', () => { + it('disables previewing upload-as-text message attachments', () => { + render( + , + ); + + const chip = screen.getByTestId('file-chip-file-1'); + expect(chip).toBeDisabled(); + + fireEvent.click(chip); + + expect(screen.queryByTestId('file-preview-dialog')).not.toBeInTheDocument(); + }); + + it('keeps normal message attachments previewable', () => { + render( + , + ); + + const chip = screen.getByTestId('file-chip-file-1'); + expect(chip).not.toBeDisabled(); + + fireEvent.click(chip); + + expect(screen.getByTestId('file-preview-dialog')).toHaveAttribute('data-file-id', 'file-1'); + }); +});