Skip to content

Commit

Permalink
Post title (#2412)
Browse files Browse the repository at this point in the history
  • Loading branch information
VanshikaSabharwal authored Nov 8, 2024
1 parent 3f6b41a commit cd9dd1a
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -25,10 +24,10 @@ interface InterfaceCreateDirectChatProps {
chatsListRefetch: (
variables?:
| Partial<{
id: any;
id: string;
}>
| undefined,
) => Promise<ApolloQueryResult<any>>;
) => Promise<ApolloQueryResult<string>>;
}

/**
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,7 +35,7 @@ interface InterfaceCreateGroupChatProps {
id: string;
}>
| undefined,
) => Promise<ApolloQueryResult<any>>;
) => Promise<ApolloQueryResult<string>>;
}

interface InterfaceOrganization {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
3 changes: 1 addition & 2 deletions src/components/UserPortal/UserSidebar/UserSidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions src/screens/UserPortal/Chat/Chat.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
79 changes: 21 additions & 58 deletions src/screens/UserPortal/Posts/Posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -311,7 +275,6 @@ export default function home(): JSX.Element {
<>
<div className={`d-flex flex-row ${styles.containerHeight}`}>
<div className={`${styles.colorLight} ${styles.mainContainer}`}>
<h1>{t('posts')}</h1>
<div className={`${styles.postContainer}`}>
<div className={`${styles.heading}`}>{t('startPost')}</div>
<div className={styles.postInputContainer}>
Expand Down
10 changes: 6 additions & 4 deletions src/screens/UserPortal/UserScreen/UserScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand Down Expand Up @@ -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(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
Expand Down
2 changes: 1 addition & 1 deletion src/screens/UserPortal/UserScreen/UserScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ const UserScreen = (): JSX.Element => {
>
<div className="d-flex justify-content-between align-items-center">
<div style={{ flex: 1 }}>
<h1>{titleKey !== 'home' ? t('title') : ''}</h1>
<h1>{t('title')}</h1>
</div>
<ProfileDropdown />
</div>
Expand Down

0 comments on commit cd9dd1a

Please sign in to comment.