diff --git a/public/locales/en.json b/public/locales/en.json index bfefeec253..6649378b31 100644 --- a/public/locales/en.json +++ b/public/locales/en.json @@ -288,6 +288,7 @@ "postDetails": "Post Details", "postTitle1": "Write title of the post", "postTitle": "Title", + "addMedia": "Upload Photo or Video", "information": "Information", "information1": "Write information of the post", "image": "Post Image", @@ -304,7 +305,8 @@ "Oldest": "Oldest First", "Latest": "Latest First", "sortPost": "Sort Post", - "tag": " Your browser does not support the video tag" + "tag": " Your browser does not support the video tag", + "postCreatedSuccess": "Congratulations! You have Posted Something." }, "postNotFound": { "post": "Post", diff --git a/public/locales/fr.json b/public/locales/fr.json index 818ffd6fcd..a872c71c4f 100644 --- a/public/locales/fr.json +++ b/public/locales/fr.json @@ -277,6 +277,7 @@ "postDetails": "Détails de la publication", "postTitle1": "Écrire le titre de la publication", "postTitle": "Titre", + "addMedia": "Télécharger une photo ou une vidéo", "information": "Informations", "information1": "Écrire les informations de la publication", "image": "Image de la publication", @@ -293,7 +294,8 @@ "Oldest": "Les plus anciennes d'abord", "Latest": "Les plus récentes d'abord", "sortPost": "Trier les publications", - "tag": "Votre navigateur ne prend pas en charge la balise vidéo" + "tag": "Votre navigateur ne prend pas en charge la balise vidéo", + "postCreatedSuccess": "Félicitations ! Vous avez publié quelque chose." }, "postNotFound": { "post": "Poste", diff --git a/public/locales/hi.json b/public/locales/hi.json index fb9ae1ab23..7080921d6e 100644 --- a/public/locales/hi.json +++ b/public/locales/hi.json @@ -276,6 +276,7 @@ "postDetails": "पोस्ट विवरण", "postTitle1": "पोस्ट का शीर्षक लिखें", "postTitle": "शीर्षक", + "addMedia": "फ़ोटो या वीडियो अपलोड करें", "information": "जानकारी", "information1": "पोस्ट की जानकारी लिखें", "image": "पोस्ट छवि", @@ -292,7 +293,8 @@ "Oldest": "सबसे पुराना पहले", "Latest": "सबसे नवीनतम पहले", "sortPost": "पोस्ट को क्रमित करें", - "tag": "आपका ब्राउज़र वीडियो टैग का समर्थन नहीं करता" + "tag": "आपका ब्राउज़र वीडियो टैग का समर्थन नहीं करता", + "postCreatedSuccess": "बधाई हो! आपने कुछ पोस्ट किया है।" }, "postNotFound": { "post": "पोस्ट", diff --git a/public/locales/sp.json b/public/locales/sp.json index 09d6472753..de2eb32c65 100644 --- a/public/locales/sp.json +++ b/public/locales/sp.json @@ -276,6 +276,7 @@ "postDetails": "Detalles de la Publicación", "postTitle1": "Escribir título de la publicación", "postTitle": "Título", + "addMedia": "Subir foto o video", "information": "Información", "information1": "Escribir información de la publicación", "image": "Imagen de la Publicación", @@ -292,7 +293,8 @@ "Oldest": "Más Antiguas Primero", "Latest": "Más Recientes Primero", "sortPost": "Ordenar Publicaciones", - "tag": "Su navegador no admite la etiqueta de video" + "tag": "Su navegador no admite la etiqueta de video", + "postCreatedSuccess": "¡Felicidades! Has publicado algo." }, "postNotFound": { "post": "Publicaciones", diff --git a/public/locales/zh.json b/public/locales/zh.json index 138a345206..0b307d322f 100644 --- a/public/locales/zh.json +++ b/public/locales/zh.json @@ -276,6 +276,7 @@ "postDetails": "帖子详情", "postTitle1": "填写帖子标题", "postTitle": "标题", + "addMedia": "上传照片或视频", "information": "信息", "information1": "填写帖子信息", "image": "帖子图片", @@ -292,7 +293,8 @@ "Oldest": "最旧的优先", "Latest": "最新的优先", "sortPost": "排序帖子", - "tag": "您的浏览器不支持视频标签" + "tag": "您的浏览器不支持视频标签", + "postCreatedSuccess": "恭喜!您已经发布了一些内容。" }, "postNotFound": { "post": "郵政", diff --git a/src/components/OrgPostCard/OrgPostCard.tsx b/src/components/OrgPostCard/OrgPostCard.tsx index 5845ef90ba..239a1ba7c7 100644 --- a/src/components/OrgPostCard/OrgPostCard.tsx +++ b/src/components/OrgPostCard/OrgPostCard.tsx @@ -235,7 +235,7 @@ export default function OrgPostCard( return ( <> -
+
{ }, likeCount: 0, commentCount: 0, - pinned: false, + pinned: true, likedBy: [], comments: [], }); @@ -171,14 +208,8 @@ describe('Organisation Post Page', () => { userEvent.type(screen.getByTestId('modalTitle'), formData.posttitle); userEvent.type(screen.getByTestId('modalinfo'), formData.postinfo); - userEvent.upload( - screen.getByTestId('organisationImage'), - formData.postImage - ); - userEvent.upload( - screen.getByTestId('organisationImage'), - formData.postVideo - ); + userEvent.upload(screen.getByTestId('addMediaField'), formData.postImage); + userEvent.upload(screen.getByTestId('addMediaField'), formData.postVideo); userEvent.click(screen.getByTestId('createPostBtn')); @@ -207,7 +238,7 @@ describe('Organisation Post Page', () => { }); } await debounceWait(); - userEvent.type(screen.getByPlaceholderText(/Search By/i), 'postone'); + userEvent.type(screen.getByPlaceholderText(/Search By/i), 'postone{enter}'); await debounceWait(); const sortDropdown = screen.getByTestId('sort'); userEvent.click(sortDropdown); @@ -362,18 +393,24 @@ describe('Organisation Post Page', () => { fireEvent.change(postInfoTextarea, { target: { value: 'Test post information' }, }); - const file = new File(['image content'], 'image.png', { + + // Simulate uploading an image + const imageFile = new File(['image content'], 'image.png', { type: 'image/png', }); - const input = screen.getByTestId('organisationImage'); - userEvent.upload(input, file); + const imageInput = screen.getByTestId('addMediaField'); + userEvent.upload(imageInput, imageFile); - await screen.findByAltText('Post Image Preview'); - expect(screen.getByAltText('Post Image Preview')).toBeInTheDocument(); + // Check if the image is displayed + const imagePreview = await screen.findByAltText('Post Image Preview'); + expect(imagePreview).toBeInTheDocument(); - const createPostBtn = screen.getByTestId('createPostBtn'); - fireEvent.click(createPostBtn); - debug(); + // Check if the close button for the image works + const closeButton = screen.getByTestId('mediaCloseButton'); + fireEvent.click(closeButton); + + // Check if the image is removed from the preview + expect(imagePreview).not.toBeInTheDocument(); }, 15000); test('Modal opens and closes', async () => { @@ -398,7 +435,7 @@ describe('Organisation Post Page', () => { const modalTitle = screen.getByTestId('modalOrganizationHeader'); expect(modalTitle).toBeInTheDocument(); - const closeButton = screen.getByTestId('closeOrganizationModal'); + const closeButton = screen.getByTestId(/closeModalBtn/i); userEvent.click(closeButton); await wait(); @@ -426,8 +463,6 @@ describe('Organisation Post Page', () => { // Check if input fields and buttons are present expect(screen.getByTestId('modalTitle')).toBeInTheDocument(); expect(screen.getByTestId('modalinfo')).toBeInTheDocument(); - expect(screen.getByTestId('organisationImage')).toBeInTheDocument(); - expect(screen.getByTestId('organisationVideo')).toBeInTheDocument(); expect(screen.getByTestId('createPostBtn')).toBeInTheDocument(); }); @@ -488,13 +523,13 @@ describe('Organisation Post Page', () => { const file = new File(['image content'], 'image.png', { type: 'image/png', }); - const input = screen.getByTestId('organisationImage'); + const input = screen.getByTestId('addMediaField'); userEvent.upload(input, file); await screen.findByAltText('Post Image Preview'); expect(screen.getByAltText('Post Image Preview')).toBeInTheDocument(); - const closeButton = screen.getByTestId('closePreview'); + const closeButton = screen.getByTestId('mediaCloseButton'); fireEvent.click(closeButton); }, 15000); test('Create post, preview image, and close preview', async () => { @@ -528,21 +563,71 @@ describe('Organisation Post Page', () => { type: 'video/mp4', }); - const videoInput = screen.getByTestId('organisationVideo'); - fireEvent.change(videoInput, { - target: { - files: [videoFile], - }, - }); + userEvent.upload(screen.getByTestId('addMediaField'), videoFile); // Check if the video is displayed const videoPreview = await screen.findByTestId('videoPreview'); expect(videoPreview).toBeInTheDocument(); // Check if the close button for the video works - const closeVideoPreviewButton = screen.getByTestId('videoclosebutton'); + const closeVideoPreviewButton = screen.getByTestId('mediaCloseButton'); fireEvent.click(closeVideoPreviewButton); expect(videoPreview).not.toBeInTheDocument(); }); }); + test('Sorting posts by pinned status', async () => { + // Mocked data representing posts with different pinned statuses + const mockedPosts = [ + { + _id: '1', + title: 'Post 1', + pinned: true, + }, + { + _id: '2', + title: 'Post 2', + pinned: false, + }, + { + _id: '3', + title: 'Post 3', + pinned: true, + }, + { + _id: '4', + title: 'Post 4', + pinned: true, + }, + ]; + + // Render the OrgPost component and pass the mocked data to it + render( + + + + + + + + + + + ); + + await wait(); + + const sortedPosts = screen.getAllByTestId('post-item'); + + // Assert that the posts are sorted correctly + expect(sortedPosts).toHaveLength(mockedPosts.length); + expect(sortedPosts[0]).toHaveTextContent( + 'postoneThis is the first po... Aditya Shelke' + ); + expect(sortedPosts[1]).toHaveTextContent( + 'posttwoTis is the post two Aditya Shelke' + ); + expect(sortedPosts[2]).toHaveTextContent( + 'posttwoTis is the post two Aditya Shelke' + ); + }); }); diff --git a/src/screens/OrgPost/OrgPost.tsx b/src/screens/OrgPost/OrgPost.tsx index 9f098c291b..d4f50a61a4 100644 --- a/src/screens/OrgPost/OrgPost.tsx +++ b/src/screens/OrgPost/OrgPost.tsx @@ -1,7 +1,7 @@ import type { ChangeEvent } from 'react'; import React, { useState, useEffect } from 'react'; -import { Search } from '@mui/icons-material'; import SortIcon from '@mui/icons-material/Sort'; +import { Search } from '@mui/icons-material'; import Row from 'react-bootstrap/Row'; import Modal from 'react-bootstrap/Modal'; import { Form } from 'react-bootstrap'; @@ -45,15 +45,17 @@ function orgPost(): JSX.Element { postinfo: '', postImage: '', postVideo: '', + addMedia: '', }); const [sortingOption, setSortingOption] = useState('latest'); - const [showTitle, setShowTitle] = useState(true); - + const [file, setFile] = useState(null); const currentUrl = window.location.href.split('=')[1]; + const [showTitle, setShowTitle] = useState(true); const showInviteModal = (): void => { setPostModalIsOpen(true); }; + const hideInviteModal = (): void => { setPostModalIsOpen(false); setPostFormState({ @@ -61,6 +63,7 @@ function orgPost(): JSX.Element { postinfo: '', postImage: '', postVideo: '', + addMedia: '', }); }; @@ -87,6 +90,7 @@ function orgPost(): JSX.Element { setDisplayedPosts(newDisplayedPosts); } }, [orgPostListData, sortingOption]); + const createPost = async (e: ChangeEvent): Promise => { e.preventDefault(); @@ -110,23 +114,24 @@ function orgPost(): JSX.Element { title: posttitle, text: postinfo, organizationId: currentUrl, - file: postImage || postVideo, + file: postImage || postVideo || postformState.addMedia, }, }); + /* istanbul ignore next */ if (data) { - toast.success('Congratulations! You have Posted Something.'); + toast.success(t('postCreatedSuccess')); refetch(); setPostFormState({ posttitle: '', postinfo: '', postImage: '', postVideo: '', + addMedia: '', }); - setPostModalIsOpen(false); // close the modal + setPostModalIsOpen(false); } } catch (error: any) { - /* istanbul ignore next */ errorHandler(t, error); } }; @@ -134,11 +139,28 @@ function orgPost(): JSX.Element { if (createPostLoading || orgPostListLoading) { return ; } - /* istanbul ignore next */ if (orgPostListError) { window.location.assign('/orglist'); } + const handleAddMediaChange = async ( + e: React.ChangeEvent + ): Promise => { + setPostFormState((prevPostFormState) => ({ + ...prevPostFormState, + addMedia: '', + })); + + const selectedFile = e.target.files?.[0]; + + if (selectedFile) { + setFile(selectedFile); + setPostFormState({ + ...postformState, + addMedia: await convertToBase64(selectedFile), + }); + } + }; const handleSearch = (e: any): void => { const { value } = e.target; @@ -182,12 +204,13 @@ function orgPost(): JSX.Element { if (a.pinned === b.pinned) { return 0; } - + /* istanbul ignore next */ if (a.pinned) { return -1; } return 1; }); + return ( <> @@ -370,118 +393,57 @@ function orgPost(): JSX.Element { }); }} /> - {!postformState.postVideo && ( - <> - {t('image')} - - ): Promise => { - setPostFormState((prevPostFormState) => ({ - ...prevPostFormState, - postImage: '', - })); - const file = e.target.files?.[0]; - if (file) { - setPostFormState({ - ...postformState, - postImage: await convertToBase64(file), - }); - } - }} - /> + + + {t('addMedia')} + - {postformState.postImage && ( -
- Post Image Preview - -
+ {postformState.addMedia && file && ( +
+ {/* Display preview for both image and video */} + {file.type.startsWith('image') ? ( + Post Image Preview + ) : ( + )} - - )} - {!postformState.postImage && ( - <> - {t('video')} - => { - setPostFormState((prevPostFormState) => ({ - ...prevPostFormState, - postVideo: '', - })); - const target = e.target as HTMLInputElement; - const file = target.files && target.files[0]; - if (file) { - const videoBase64 = await convertToBase64(file); - setPostFormState({ - ...postformState, - postVideo: videoBase64, - }); + -
- )} - + data-testid="mediaCloseButton" + > + + +
)} +