Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,104 +1,130 @@
import { useState, FunctionComponent } from 'react';
import Message from '@patternfly/chatbot/dist/dynamic/Message';
import patternflyAvatar from './patternfly_avatar.jpg';
import { Checkbox, FormGroup, Stack } from '@patternfly/react-core';
import { Checkbox, FormGroup, Flex, FlexItem } from '@patternfly/react-core';

export const MessageWithFeedbackExample: FunctionComponent = () => {
const [hasCloseButton, setHasCloseButton] = useState(false);
const [hasTextArea, setHasTextArea] = useState(false);
const [hasChildren, setHasChildren] = useState(false);

const children = <>Do not share any personal or other sensitive information in your feedback.</>;

return (
<>
<Stack hasGutter>
<FormGroup role="radiogroup" isInline fieldId="feedback-card" label="Variant">
<Checkbox
isChecked={hasTextArea}
onChange={() => {
setHasTextArea(!hasTextArea);
<Flex direction={{ default: 'column' }} spaceItems={{ default: 'spaceItemsMd' }}>
<FlexItem>
<FormGroup role="radiogroup" isInline isStack fieldId="feedback-card" label="Variant">
<Checkbox
isChecked={hasTextArea}
onChange={() => {
setHasTextArea(!hasTextArea);
}}
name="feedback-card-with-text-area"
label="Has text area"
id="has-text-area"
/>
<Checkbox
isChecked={hasChildren}
onChange={() => {
setHasChildren(!hasChildren);
}}
name="feedback-card-with-children"
label="Has additional content"
id="has-children"
/>
</FormGroup>
</FlexItem>
<FlexItem>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="This is a message with the feedback card:"
userFeedbackForm={{
quickResponses: [
{ id: '1', content: 'Helpful information' },
{ id: '2', content: 'Easy to understand' },
{ id: '3', content: 'Resolved my issue' }
],
onSubmit: (quickResponse, additionalFeedback) =>
alert(`Selected ${quickResponse} and received the additional feedback: ${additionalFeedback}`),
hasTextArea,
children: hasChildren ? children : undefined,
// eslint-disable-next-line no-console
onClose: () => console.log('closed feedback form'),
focusOnLoad: false
}}
name="basic-inline-radio"
label="Has text area"
id="has-text-area"
/>
</FormGroup>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="This is a message with the feedback card:"
userFeedbackForm={{
quickResponses: [
{ id: '1', content: 'Helpful information' },
{ id: '2', content: 'Easy to understand' },
{ id: '3', content: 'Resolved my issue' }
],
onSubmit: (quickResponse, additionalFeedback) =>
alert(`Selected ${quickResponse} and received the additional feedback: ${additionalFeedback}`),
hasTextArea,
// eslint-disable-next-line no-console
onClose: () => console.log('closed feedback form'),
focusOnLoad: false
}}
/>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="This is a compact message with the feedback card:"
userFeedbackForm={{
quickResponses: [
{ id: '1', content: 'Helpful information' },
{ id: '2', content: 'Easy to understand' },
{ id: '3', content: 'Resolved my issue' }
],
onSubmit: (quickResponse, additionalFeedback) =>
alert(`Selected ${quickResponse} and received the additional feedback: ${additionalFeedback}`),
hasTextArea,
// eslint-disable-next-line no-console
onClose: () => console.log('closed feedback form'),
focusOnLoad: false
}}
isCompact
/>
</Stack>
<Stack hasGutter>
<FormGroup role="radiogroup" isInline fieldId="feedback-thank-you" label="Variant">
<Checkbox
isChecked={hasCloseButton}
onChange={() => {
setHasCloseButton(!hasCloseButton);
</FlexItem>
<FlexItem>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="This is a compact message with the feedback card:"
userFeedbackForm={{
quickResponses: [
{ id: '1', content: 'Helpful information' },
{ id: '2', content: 'Easy to understand' },
{ id: '3', content: 'Resolved my issue' }
],
onSubmit: (quickResponse, additionalFeedback) =>
alert(`Selected ${quickResponse} and received the additional feedback: ${additionalFeedback}`),
hasTextArea,
children: hasChildren ? children : undefined,
// eslint-disable-next-line no-console
onClose: () => console.log('closed feedback form'),
focusOnLoad: false
}}
name="basic-inline-radio"
label="Has close button"
id="has-close"
isCompact
/>
</FormGroup>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="This is a thank-you message, which is displayed once the feedback card is submitted:"
// eslint-disable-next-line no-console
userFeedbackComplete={{
</FlexItem>
</Flex>
<Flex direction={{ default: 'column' }}>
<FlexItem>
<FormGroup role="radiogroup" isInline fieldId="feedback-thank-you" label="Variant">
<Checkbox
isChecked={hasCloseButton}
onChange={() => {
setHasCloseButton(!hasCloseButton);
}}
name="basic-inline-radio"
label="Has close button"
id="has-close"
/>
</FormGroup>
</FlexItem>
<FlexItem>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="This is a thank-you message, which is displayed once the feedback card is submitted:"
// eslint-disable-next-line no-console
onClose: hasCloseButton ? () => console.log('closed completion message') : undefined,
focusOnLoad: false
}}
/>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="This is a compact thank-you message, which is displayed once the feedback card is submitted:"
// eslint-disable-next-line no-console
userFeedbackComplete={{
userFeedbackComplete={{
// eslint-disable-next-line no-console
onClose: hasCloseButton ? () => console.log('closed completion message') : undefined,
focusOnLoad: false
}}
/>
</FlexItem>
<FlexItem>
<Message
name="Bot"
role="bot"
avatar={patternflyAvatar}
content="This is a compact thank-you message, which is displayed once the feedback card is submitted:"
// eslint-disable-next-line no-console
onClose: hasCloseButton ? () => console.log('closed completion message') : undefined,
focusOnLoad: false
}}
isCompact
/>
</Stack>
userFeedbackComplete={{
// eslint-disable-next-line no-console
onClose: hasCloseButton ? () => console.log('closed completion message') : undefined,
focusOnLoad: false
}}
isCompact
/>
</FlexItem>
</Flex>
</>
);
};
107 changes: 107 additions & 0 deletions packages/module/src/Message/UserFeedback/UserFeedback.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,111 @@ describe('UserFeedback', () => {
);
expect(screen.getByTestId('card')).toHaveClass('pf-m-compact');
});
it('should pass buttonProps to submit button', () => {
render(
<UserFeedback
timestamp="12/12/12"
onClose={jest.fn}
onSubmit={jest.fn}
quickResponses={MOCK_RESPONSES}
submitButtonProps={{ variant: 'secondary', isDisabled: true }}
/>
);
const submitButton = 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', () => {
render(
<UserFeedback
timestamp="12/12/12"
onClose={jest.fn}
onSubmit={jest.fn}
quickResponses={MOCK_RESPONSES}
cardHeaderProps={{ 'data-testid': 'card-header', className: 'custom-header' } as any}
/>
);
const cardHeader = screen.getByTestId('card-header');
expect(cardHeader).toHaveClass('custom-header');
});
it('should pass cardBodyProps to card body', () => {
render(
<UserFeedback
timestamp="12/12/12"
onClose={jest.fn}
onSubmit={jest.fn}
quickResponses={MOCK_RESPONSES}
cardBodyProps={{ 'data-testid': 'card-body', className: 'custom-body' } as any}
/>
);
const cardBody = screen.getByTestId('card-body');
expect(cardBody).toHaveClass('custom-body');
});
it('should pass headingLevelProps to title heading', () => {
render(
<UserFeedback
timestamp="12/12/12"
onClose={jest.fn}
onSubmit={jest.fn}
quickResponses={MOCK_RESPONSES}
headingLevelProps={{ className: 'custom-heading', id: 'feedback-title' }}
/>
);
const heading = 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', () => {
render(
<UserFeedback
timestamp="12/12/12"
onClose={jest.fn}
onSubmit={jest.fn}
quickResponses={MOCK_RESPONSES}
formProps={{ 'data-testid': 'feedback-form', className: 'custom-form' } as any}
/>
);
const form = screen.getByTestId('feedback-form');
expect(form).toHaveClass('custom-form');
});
it('should pass textAreaProps to text area when hasTextArea is true', () => {
render(
<UserFeedback
timestamp="12/12/12"
onClose={jest.fn}
onSubmit={jest.fn}
quickResponses={MOCK_RESPONSES}
hasTextArea
textAreaProps={{ 'data-testid': 'custom-textarea', rows: 5 } as any}
/>
);
const textArea = screen.getByTestId('custom-textarea');
expect(textArea).toHaveAttribute('rows', '5');
expect(textArea).toHaveAttribute('data-testid', 'custom-textarea');
});
it('should pass actionGroupProps to action group', () => {
render(
<UserFeedback
timestamp="12/12/12"
onClose={jest.fn}
onSubmit={jest.fn}
quickResponses={MOCK_RESPONSES}
actionGroupProps={{ 'data-testid': 'action-group', className: 'custom-actions' } as any}
/>
);
const actionGroup = screen.getByTestId('action-group');
expect(actionGroup).toHaveClass('custom-actions');
});
it('should render children', () => {
render(
<UserFeedback timestamp="12/12/12" onClose={jest.fn} onSubmit={jest.fn} quickResponses={MOCK_RESPONSES}>
<div data-testid="custom-content">Custom feedback content</div>
<p>Additional paragraph</p>
</UserFeedback>
);
expect(screen.getByTestId('custom-content')).toBeInTheDocument();
expect(screen.getByText('Custom feedback content')).toBeInTheDocument();
expect(screen.getByText('Additional paragraph')).toBeInTheDocument();
});
});
Loading
Loading