From cd9dd1a076e2114975f8e33f5f17bcc2da1e2b11 Mon Sep 17 00:00:00 2001 From: Vanshika Sabharwal <143436704+VanshikaSabharwal@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:50:01 +0530 Subject: [PATCH] Post title (#2412) --- .../CreateDirectChat.test.tsx | 2 +- .../CreateDirectChat/CreateDirectChat.tsx | 9 +-- .../CreateGroupChat/CreateGroupChat.tsx | 7 +- .../OrganizationCard.test.tsx | 4 +- .../UserSidebar/UserSidebar.test.tsx | 3 +- src/screens/UserPortal/Chat/Chat.test.tsx | 4 +- src/screens/UserPortal/Posts/Posts.tsx | 79 +++++-------------- .../UserPortal/UserScreen/UserScreen.test.tsx | 10 ++- .../UserPortal/UserScreen/UserScreen.tsx | 2 +- 9 files changed, 37 insertions(+), 83 deletions(-) diff --git a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.test.tsx b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.test.tsx index 645b663579..d8b3466207 100644 --- a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.test.tsx +++ b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.test.tsx @@ -7,7 +7,7 @@ import { waitFor, } from '@testing-library/react'; import { MockedProvider } from '@apollo/react-testing'; -import { I18nextProvider, useTranslation } from 'react-i18next'; +import { I18nextProvider } from 'react-i18next'; import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; import { BrowserRouter } from 'react-router-dom'; import { Provider } from 'react-redux'; diff --git a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx index a8bdfd3d31..24c853fcdd 100644 --- a/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx +++ b/src/components/UserPortal/CreateDirectChat/CreateDirectChat.tsx @@ -16,7 +16,6 @@ import type { InterfaceQueryUserListItem } from 'utils/interfaces'; import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; import Loader from 'components/Loader/Loader'; import { Search } from '@mui/icons-material'; -import { useTranslation } from 'react-i18next'; import { useParams } from 'react-router-dom'; interface InterfaceCreateDirectChatProps { @@ -25,10 +24,10 @@ interface InterfaceCreateDirectChatProps { chatsListRefetch: ( variables?: | Partial<{ - id: any; + id: string; }> | undefined, - ) => Promise>; + ) => Promise>; } /** @@ -62,10 +61,6 @@ export default function createDirectChatModal({ createDirectChatModalisOpen, chatsListRefetch, }: InterfaceCreateDirectChatProps): JSX.Element { - const { t } = useTranslation('translation', { - keyPrefix: 'userChat', - }); - const { orgId: organizationId } = useParams(); const userId: string | null = getItem('userId'); diff --git a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx index ba9fca9fdb..e293675a03 100644 --- a/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx +++ b/src/components/UserPortal/CreateGroupChat/CreateGroupChat.tsx @@ -25,7 +25,6 @@ import type { InterfaceQueryUserListItem } from 'utils/interfaces'; import { USERS_CONNECTION_LIST } from 'GraphQl/Queries/Queries'; import Loader from 'components/Loader/Loader'; import { Search } from '@mui/icons-material'; -import { useTranslation } from 'react-i18next'; interface InterfaceCreateGroupChatProps { toggleCreateGroupChatModal: () => void; @@ -36,7 +35,7 @@ interface InterfaceCreateGroupChatProps { id: string; }> | undefined, - ) => Promise>; + ) => Promise>; } interface InterfaceOrganization { @@ -94,10 +93,6 @@ export default function CreateGroupChat({ createGroupChatModalisOpen, chatsListRefetch, }: InterfaceCreateGroupChatProps): JSX.Element { - const { t } = useTranslation('translation', { - keyPrefix: 'userChat', - }); - const userId: string | null = getItem('userId'); const [createChat] = useMutation(CREATE_CHAT); diff --git a/src/components/UserPortal/OrganizationCard/OrganizationCard.test.tsx b/src/components/UserPortal/OrganizationCard/OrganizationCard.test.tsx index 3ea0c3230e..77516ddc7a 100644 --- a/src/components/UserPortal/OrganizationCard/OrganizationCard.test.tsx +++ b/src/components/UserPortal/OrganizationCard/OrganizationCard.test.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import { act } from '@testing-library/react'; -import { fireEvent, render, screen } from '@testing-library/react'; +import { act, fireEvent, render, screen } from '@testing-library/react'; + import { MockedProvider } from '@apollo/react-testing'; import { I18nextProvider } from 'react-i18next'; diff --git a/src/components/UserPortal/UserSidebar/UserSidebar.test.tsx b/src/components/UserPortal/UserSidebar/UserSidebar.test.tsx index 0bbf33a782..79d603614f 100644 --- a/src/components/UserPortal/UserSidebar/UserSidebar.test.tsx +++ b/src/components/UserPortal/UserSidebar/UserSidebar.test.tsx @@ -1,6 +1,6 @@ import React, { act } from 'react'; import type { RenderResult } from '@testing-library/react'; -import { fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { fireEvent, render, screen } from '@testing-library/react'; import { MockedProvider } from '@apollo/react-testing'; import { I18nextProvider } from 'react-i18next'; import styles from './UserSidebar.module.css'; @@ -15,7 +15,6 @@ import i18nForTest from 'utils/i18nForTest'; import { StaticMockLink } from 'utils/StaticMockLink'; import UserSidebar from './UserSidebar'; import useLocalStorage from 'utils/useLocalstorage'; -import userEvent from '@testing-library/user-event'; const { setItem } = useLocalStorage(); diff --git a/src/screens/UserPortal/Chat/Chat.test.tsx b/src/screens/UserPortal/Chat/Chat.test.tsx index a5c74b1e35..660eeaa236 100644 --- a/src/screens/UserPortal/Chat/Chat.test.tsx +++ b/src/screens/UserPortal/Chat/Chat.test.tsx @@ -1545,7 +1545,7 @@ describe('Testing Chat Screen [User Portal]', () => { ).toBeInTheDocument(); }); - test('Test create new direct chat', async () => { + test('create new direct chat', async () => { const mock = [ ...USER_JOINED_ORG_MOCK, ...GROUP_CHAT_BY_ID_QUERY_MOCK, @@ -1585,7 +1585,7 @@ describe('Testing Chat Screen [User Portal]', () => { fireEvent.click(closeButton); }); - test('Test create new group chat', async () => { + test('create new group chat', async () => { const mock = [ ...USER_JOINED_ORG_MOCK, ...GROUP_CHAT_BY_ID_QUERY_MOCK, diff --git a/src/screens/UserPortal/Posts/Posts.tsx b/src/screens/UserPortal/Posts/Posts.tsx index 256bb5f52f..ceb10c9b49 100644 --- a/src/screens/UserPortal/Posts/Posts.tsx +++ b/src/screens/UserPortal/Posts/Posts.tsx @@ -52,34 +52,16 @@ type Ad = { endDate: string; // Assuming it's a string in the format 'yyyy-MM-dd' startDate: string; // Assuming it's a string in the format 'yyyy-MM-dd' }; -interface InterfaceAdContent { - _id: string; - name: string; - type: string; - organization: { - _id: string; - }; - mediaUrl: string; - endDate: string; - startDate: string; - - comments: InterfacePostComments; - likes: InterfacePostLikes; -} - -type AdvertisementsConnection = { - edges: { - node: InterfaceAdContent; - }[]; -}; type InterfacePostComments = { + id: string; creator: { - _id: string; + id: string; firstName: string; lastName: string; email: string; }; + likeCount: number; likedBy: { id: string; @@ -226,42 +208,24 @@ export default function home(): JSX.Element { comments, } = node; - const allLikes: any = []; - - likedBy.forEach((value: any) => { - const singleLike = { - firstName: value.firstName, - lastName: value.lastName, - id: value._id, - }; - allLikes.push(singleLike); - }); - - const postComments: any = []; - - comments.forEach((value: any) => { - const commentLikes: any = []; - value.likedBy.forEach((commentLike: any) => { - const singleLike = { - id: commentLike._id, - }; - commentLikes.push(singleLike); - }); - - const comment = { - id: value._id, - creator: { - firstName: value.creator.firstName, - lastName: value.creator.lastName, - id: value.creator._id, - email: value.creator.email, - }, - likeCount: value.likeCount, - likedBy: commentLikes, - text: value.text, - }; - postComments.push(comment); - }); + const allLikes: InterfacePostLikes = likedBy.map((value) => ({ + firstName: value.firstName, + lastName: value.lastName, + id: value._id, + })); + + const postComments: InterfacePostComments = comments?.map((value) => ({ + id: value.id, + creator: { + firstName: value.creator?.firstName ?? '', + lastName: value.creator?.lastName ?? '', + id: value.creator?.id ?? '', + email: value.creator?.email ?? '', + }, + likeCount: value.likeCount, + likedBy: value.likedBy?.map((like) => ({ id: like?.id ?? '' })) ?? [], + text: value.text, + })); const date = new Date(node.createdAt); const formattedDate = new Intl.DateTimeFormat('en-US', { @@ -311,7 +275,6 @@ export default function home(): JSX.Element { <>
-

{t('posts')}

{t('startPost')}
diff --git a/src/screens/UserPortal/UserScreen/UserScreen.test.tsx b/src/screens/UserPortal/UserScreen/UserScreen.test.tsx index 96ee9767f2..642b231a66 100644 --- a/src/screens/UserPortal/UserScreen/UserScreen.test.tsx +++ b/src/screens/UserPortal/UserScreen/UserScreen.test.tsx @@ -4,7 +4,7 @@ import { fireEvent, render, screen } from '@testing-library/react'; import { I18nextProvider } from 'react-i18next'; import 'jest-location-mock'; import { Provider } from 'react-redux'; -import { BrowserRouter } from 'react-router-dom'; +import { BrowserRouter, useNavigate } from 'react-router-dom'; import { store } from 'state/store'; import i18nForTest from 'utils/i18nForTest'; import UserScreen from './UserScreen'; @@ -87,7 +87,7 @@ describe('Testing LeftDrawer in OrganizationScreen', () => { ); const titleElement = screen.getByRole('heading', { level: 1 }); - expect(titleElement).toHaveTextContent(''); + expect(titleElement).toHaveTextContent('Posts'); }); test('renders the correct title based on the titleKey', () => { @@ -109,7 +109,7 @@ describe('Testing LeftDrawer in OrganizationScreen', () => { expect(titleElement).toHaveTextContent('People'); }); - test('Testing LeftDrawer in page functionality', async () => { + test('LeftDrawer should toggle correctly based on window size and user interaction', async () => { render( @@ -138,8 +138,10 @@ describe('Testing LeftDrawer in OrganizationScreen', () => { expect(icon).toHaveClass('fa fa-angle-double-left'); }); - test('should be redirected to / if orgId is undefined', async () => { + test('should be redirected to root when orgId is undefined', async () => { mockID = undefined; + const navigate = jest.fn(); + jest.spyOn({ useNavigate }, 'useNavigate').mockReturnValue(navigate); render( diff --git a/src/screens/UserPortal/UserScreen/UserScreen.tsx b/src/screens/UserPortal/UserScreen/UserScreen.tsx index 1b9a436f2c..bcb1d867f3 100644 --- a/src/screens/UserPortal/UserScreen/UserScreen.tsx +++ b/src/screens/UserPortal/UserScreen/UserScreen.tsx @@ -131,7 +131,7 @@ const UserScreen = (): JSX.Element => { >
-

{titleKey !== 'home' ? t('title') : ''}

+

{t('title')}