diff --git a/src/containers/about-chat-sidebar/AboutChatSidebar.tsx b/src/containers/about-chat-sidebar/AboutChatSidebar.tsx index f3ae439ed..109a1d7ec 100644 --- a/src/containers/about-chat-sidebar/AboutChatSidebar.tsx +++ b/src/containers/about-chat-sidebar/AboutChatSidebar.tsx @@ -29,32 +29,35 @@ interface AboutChatSidebarProps { member: Member links: Link[] onClose?: () => void + title?: SidebarContentEnum } const AboutChatSidebar: FC = ({ member, links, - onClose + onClose, + title = SidebarContentEnum.About }) => { const { t } = useTranslation() const navigate = useNavigate() const { About, Links } = SidebarContentEnum - const [titleText, setTitleText] = useState(About) + const [titleText, setTitleText] = useState(title) const { user, role } = member const { _id, firstName, lastName, photo, professionalSummary } = user const { path: pathToProfile } = authRoutes.userProfile - const navigateToUserProfile = () => { + const navigateToUserProfile = () => navigate(createUrlPath(pathToProfile, _id, { role })) - } - const onSeeAllClick = (text: SidebarContentEnum) => { - setTitleText(text) - } + const onSeeAllClick = (text: SidebarContentEnum) => setTitleText(text) const goBackBtn = titleText !== About && ( - setTitleText(About)} sx={styles.goBackBtn}> + setTitleText(About)} + sx={styles.goBackBtn} + > ) @@ -106,6 +109,7 @@ const AboutChatSidebar: FC = ({ + } diff --git a/tests/unit/containers/about-chat-sidebar/AboutChatSidebar.spec.jsx b/tests/unit/containers/about-chat-sidebar/AboutChatSidebar.spec.jsx index 21dba10b2..066b05983 100644 --- a/tests/unit/containers/about-chat-sidebar/AboutChatSidebar.spec.jsx +++ b/tests/unit/containers/about-chat-sidebar/AboutChatSidebar.spec.jsx @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useState } from 'react' import { BrowserRouter } from 'react-router-dom' import { render, screen } from '@testing-library/react' @@ -81,4 +81,53 @@ describe('AboutChatSidebar component test', () => { closeButton.click() expect(onCloseMock).toHaveBeenCalledTimes(1) }) + + it('should render goBackBtn when titleText is not About ', () => { + setup({ + member: mockMember, + media: [], + files: [], + links: mockLinks, + title: 'link' + }) + + const backButton = screen.getByTestId('back-icon') + expect(backButton).toBeInTheDocument() + }) + + it('should render the user professional summary when provided', () => { + const mockMemberWithSummary = { + user: { + ...mockUser, + professionalSummary: 'Experienced web developer' + }, + role: 'tutor' + } + + setup({ + member: mockMemberWithSummary, + links: [] + }) + + const userDescription = screen.getByText('Experienced web developer') + expect(userDescription).toBeInTheDocument() + }) + + it('should render the fallback text when professional summary is not provided', () => { + const mockMemberWithoutSummary = { + user: { + ...mockUser, + professionalSummary: '' + }, + role: 'tutor' + } + + setup({ + member: mockMemberWithoutSummary, + links: [] + }) + + const fallbackText = screen.getByText('chatPage.sidebar.noSummary') + expect(fallbackText).toBeInTheDocument() + }) })