Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Allow for a single object upload for posts #1193

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
"postDetails": "Post Details",
"postTitle1": "Write title of the post",
"postTitle": "Title",
"addMedia": "Upload Photo or Video",
rishav-jha-mech marked this conversation as resolved.
Show resolved Hide resolved
"information": "Information",
"information1": "Write information of the post",
"image": "Post Image",
Expand All @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
"postDetails": "पोस्ट विवरण",
"postTitle1": "पोस्ट का शीर्षक लिखें",
"postTitle": "शीर्षक",
"addMedia": "फ़ोटो या वीडियो अपलोड करें",
"information": "जानकारी",
"information1": "पोस्ट की जानकारी लिखें",
"image": "पोस्ट छवि",
Expand All @@ -292,7 +293,8 @@
"Oldest": "सबसे पुराना पहले",
"Latest": "सबसे नवीनतम पहले",
"sortPost": "पोस्ट को क्रमित करें",
"tag": "आपका ब्राउज़र वीडियो टैग का समर्थन नहीं करता"
"tag": "आपका ब्राउज़र वीडियो टैग का समर्थन नहीं करता",
"postCreatedSuccess": "बधाई हो! आपने कुछ पोस्ट किया है।"
},
"postNotFound": {
"post": "पोस्ट",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/sp.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion public/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@
"postDetails": "帖子详情",
"postTitle1": "填写帖子标题",
"postTitle": "标题",
"addMedia": "上传照片或视频",
"information": "信息",
"information1": "填写帖子信息",
"image": "帖子图片",
Expand All @@ -292,7 +293,8 @@
"Oldest": "最旧的优先",
"Latest": "最新的优先",
"sortPost": "排序帖子",
"tag": "您的浏览器不支持视频标签"
"tag": "您的浏览器不支持视频标签",
"postCreatedSuccess": "恭喜!您已经发布了一些内容。"
},
"postNotFound": {
"post": "郵政",
Expand Down
2 changes: 1 addition & 1 deletion src/components/OrgPostCard/OrgPostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default function OrgPostCard(

return (
<>
<div className="col-xl-4 col-lg-4 col-md-6">
<div className="col-xl-4 col-lg-4 col-md-6" data-testid="post-item">
<div
className={styles.cards}
onClick={handleCardClick}
Expand Down
149 changes: 117 additions & 32 deletions src/screens/OrgPost/OrgPost.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { CREATE_POST_MUTATION } from 'GraphQl/Mutations/mutations';
import i18nForTest from 'utils/i18nForTest';
import { StaticMockLink } from 'utils/StaticMockLink';
import { ToastContainer } from 'react-toastify';
import { debug } from 'jest-preview';

const MOCKS = [
{
Expand Down Expand Up @@ -46,7 +45,7 @@ const MOCKS = [
likeCount: 0,
commentCount: 0,
comments: [],
pinned: false,
pinned: true,
likedBy: [],
},
{
Expand All @@ -68,6 +67,44 @@ const MOCKS = [
likedBy: [],
comments: [],
},
{
_id: '6411e54835d7ba2344a78e30',
title: 'posttwo',
text: 'Tis is the post two',
imageUrl: null,
videoUrl: null,
createdAt: '2023-08-24T09:26:56.524+00:00',
creator: {
_id: '640d98d9eb6a743d75341067',
firstName: 'Aditya',
lastName: 'Shelke',
email: '[email protected]',
},
likeCount: 0,
commentCount: 0,
pinned: true,
likedBy: [],
comments: [],
},
{
_id: '6411e54835d7ba2344a78e31',
title: 'posttwo',
text: 'Tis is the post two',
imageUrl: null,
videoUrl: null,
createdAt: '2023-08-24T09:26:56.524+00:00',
creator: {
_id: '640d98d9eb6a743d75341067',
firstName: 'Aditya',
lastName: 'Shelke',
email: '[email protected]',
},
likeCount: 0,
commentCount: 0,
pinned: false,
likedBy: [],
comments: [],
},
],
},
},
Expand Down Expand Up @@ -145,7 +182,7 @@ describe('Organisation Post Page', () => {
},
likeCount: 0,
commentCount: 0,
pinned: false,
pinned: true,
likedBy: [],
comments: [],
});
Expand All @@ -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'));

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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();
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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(
<MockedProvider addTypename={false} link={link}>
<BrowserRouter>
<Provider store={store}>
<I18nextProvider i18n={i18nForTest}>
<ToastContainer />
<OrgPost />
</I18nextProvider>
</Provider>
</BrowserRouter>
</MockedProvider>
);

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'
);
});
});
Loading
Loading