From b0f3afe3676a015c1ab5526530576fd15000e8f3 Mon Sep 17 00:00:00 2001 From: Rebecca Alpert Date: Fri, 21 Aug 2026 10:07:00 -0400 Subject: [PATCH] fix(Sources): Allow extra content in header Fixes https://github.com/patternfly/chatbot/issues/892 Assisted-by: Cursor --- .../examples/Messages/MessageWithSources.tsx | 31 ++++++++++ .../chatbot/examples/Messages/Messages.md | 2 + .../module/src/SourcesCard/SourcesCard.scss | 6 ++ .../src/SourcesCard/SourcesCard.test.tsx | 16 +++++ .../module/src/SourcesCard/SourcesCard.tsx | 2 + .../SourcesCardBase/SourcesCardBase.test.tsx | 62 +++++++++++++++++++ .../src/SourcesCardBase/SourcesCardBase.tsx | 8 +++ 7 files changed, 127 insertions(+) diff --git a/packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithSources.tsx b/packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithSources.tsx index 5038e6141..26502ed7a 100644 --- a/packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithSources.tsx +++ b/packages/module/patternfly-docs/content/extensions/chatbot/examples/Messages/MessageWithSources.tsx @@ -78,6 +78,37 @@ export const MessageWithSourcesExample: FunctionComponent = () => { ] }} /> + Documentation + }, + { + title: 'Azure Red Hat OpenShift documentation', + link: '#', + body: 'Microsoft Azure Red Hat OpenShift allows you to deploy a production ready Red Hat OpenShift cluster in Azure ...', + isExternal: true, + headerContent: + }, + { + title: 'OKD Documentation: Home', + link: '#', + body: 'OKD is a distribution of Kubernetes optimized for continuous application development and multi-tenant deployment. OKD also serves as the upstream code base upon ...', + isExternal: true, + headerContent: + } + ], + onSetPage + }} + /> { screen.getByRole('button', { name: /Go to next page/i }); }); + it('should render headerContent above the title', () => { + render( + Dessert + } + ]} + /> + ); + expect(screen.getByText('Dessert')).toBeTruthy(); + expect(screen.getByText('How to make an apple pie')).toBeTruthy(); + }); + it('should render with wrap layout when layout is set to wrap', () => { render( { expect(screen.getByRole('link', { name: /How to make an apple pie/i })).toHaveClass('test'); }); + it('should render headerContent above the title', () => { + render( + Dessert + } + ]} + /> + ); + expect(screen.getByText('Dessert')).toBeTruthy(); + expect(screen.getByText('How to make an apple pie')).toBeTruthy(); + }); + + it('should update headerContent when navigating between sources', async () => { + render( + Dessert + }, + { + title: 'How to make cookies', + link: '', + headerContent: Snack + } + ]} + /> + ); + expect(screen.getByText('Dessert')).toBeTruthy(); + expect(screen.queryByText('Snack')).toBeFalsy(); + await userEvent.click(screen.getByRole('button', { name: /Go to next page/i })); + expect(screen.queryByText('Dessert')).toBeFalsy(); + expect(screen.getByText('Snack')).toBeTruthy(); + }); + + it('should render headerContent when using wrap layout', () => { + render( + Dessert + }, + { + title: 'How to make cookies', + link: '', + headerContent: Snack + } + ]} + /> + ); + expect(screen.getByText('Dessert')).toBeTruthy(); + expect(screen.getByText('Snack')).toBeTruthy(); + }); + it('should render with wrap layout when layout prop is set to wrap', () => { render( = ({ > + {source.headerContent && ( +
{source.headerContent}
+ )}