Skip to content

Commit

Permalink
hot fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Renatavl committed Nov 19, 2024
1 parent e7550c4 commit 4f13d16
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/containers/about-chat-sidebar/AboutChatSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,35 @@ interface AboutChatSidebarProps {
member: Member
links: Link[]
onClose?: () => void
title?: SidebarContentEnum
}

const AboutChatSidebar: FC<AboutChatSidebarProps> = ({
member,
links,
onClose
onClose,
title = SidebarContentEnum.About
}) => {
const { t } = useTranslation()
const navigate = useNavigate()
const { About, Links } = SidebarContentEnum
const [titleText, setTitleText] = useState<SidebarContentEnum>(About)
const [titleText, setTitleText] = useState<SidebarContentEnum>(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 && (
<IconButton onClick={() => setTitleText(About)} sx={styles.goBackBtn}>
<IconButton
data-testid='back-icon'
onClick={() => setTitleText(About)}
sx={styles.goBackBtn}
>
<ArrowBackIcon sx={styles.goBackIcon} />
</IconButton>
)
Expand Down Expand Up @@ -106,6 +109,7 @@ const AboutChatSidebar: FC<AboutChatSidebarProps> = ({
</Typography>
</Box>
<Divider />

<SidebarContentBox
content={links}
icon={<LinkOutlinedIcon />}
Expand Down
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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()
})
})

0 comments on commit 4f13d16

Please sign in to comment.