Skip to content

Commit

Permalink
Corrected placeholder text, added missing inputs(video,images) and th…
Browse files Browse the repository at this point in the history
…eir tests to edit post feature present in Admin role. (#1483)

* Corrected placeholder value and added missing fields

* Corrected placeholder value and added missing fields

* Corrected placeholder value and added missing fields

* Corrected placeholder value and added missing fields

* added tests

* Update .env.example

* Update .env.example

* fixed

* fixed files

* added tests
  • Loading branch information
Anvita0305 authored Jan 28, 2024
1 parent 3838d84 commit 8d34a8b
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 34 deletions.
2 changes: 2 additions & 0 deletions public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@
"yes": "Yes",
"editPost": "Edit Post",
"postTitle": "Title",
"postTitle1": "Edit title of the post",
"information1": "Edit information of the post",
"information": "Information",
"image": "Image",
"video": "Video",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@
"yes": "Oui",
"editPost": "Modifier la publication",
"postTitle": "Titre",
"postTitle1": "Modifier le titre du message",
"information1": "Modifier les informations du message",
"information": "Informations",
"image": "Image",
"video": "Vidéo",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@
"yes": "हाँ",
"editPost": "पोस्ट संपादित करें",
"postTitle": "शीर्षक",
"postTitle1": "पोस्ट का शीर्षक संपादित करें",
"information1": "पोस्ट की जानकारी संपादित करें",
"information": "जानकारी",
"image": "छवि",
"video": "वीडियो",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/sp.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@
"yes": "",
"editPost": "Editar Publicación",
"postTitle": "Título",
"postTitle1": "Editar título de la publicación",
"information1": "Editar información de la publicación",
"information": "Información",
"image": "Imagen",
"video": "Video",
Expand Down
2 changes: 2 additions & 0 deletions public/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@
"yes": "",
"editPost": "编辑帖子",
"postTitle": "标题",
"postTitle1": "編輯貼文標題",
"information1": "編輯貼文訊息",
"information": "信息",
"image": "图片",
"video": "视频",
Expand Down
111 changes: 79 additions & 32 deletions src/components/OrgPostCard/OrgPostCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,45 @@ describe('Testing Organization Post Card', () => {
fireEvent.change(getByTestId('updateText'), {
target: { value: 'This is a updated text' },
});
const postVideoUrlInput = screen.queryByTestId('postVideoUrl');
if (postVideoUrlInput) {
fireEvent.change(getByTestId('postVideoUrl'), {
target: { value: 'This is a updated video' },
});
userEvent.click(screen.getByPlaceholderText(/video/i));
const input = getByTestId('postVideoUrl');
const file = new File(['test-video'], 'test.mp4', { type: 'video/mp4' });
Object.defineProperty(input, 'files', {
value: [file],
});
fireEvent.change(input);
await waitFor(() => {
convertToBase64(file);
});

userEvent.click(screen.getByTestId('closePreview'));
}
const imageUrlInput = screen.queryByTestId('postImageUrl');
if (imageUrlInput) {
fireEvent.change(getByTestId('postImageUrl'), {
target: { value: 'This is a updated image' },
});
userEvent.click(screen.getByPlaceholderText(/image/i));
const input = getByTestId('postImageUrl');
const file = new File(['test-image'], 'test.jpg', { type: 'image/jpeg' });
Object.defineProperty(input, 'files', {
value: [file],
});
fireEvent.change(input);

// Simulate the asynchronous base64 conversion function
await waitFor(() => {
convertToBase64(file); // Replace with the expected base64-encoded image
});
document.getElementById = jest.fn(() => input);
const clearImageButton = getByTestId('closeimage');
fireEvent.click(clearImageButton);
}
userEvent.click(screen.getByTestId('updatePostBtn'));

await waitFor(
Expand Down Expand Up @@ -407,21 +446,26 @@ describe('Testing Organization Post Card', () => {
userEvent.click(screen.getByTestId('moreiconbtn'));

userEvent.click(screen.getByTestId('editPostModalBtn'));
userEvent.click(screen.getByTestId('closePreview'));

fireEvent.change(getByTestId('postVideoUrl'), {
target: { value: '' },
});
userEvent.click(screen.getByPlaceholderText(/video/i));
const input = getByTestId('postVideoUrl');
const file = new File(['test-video'], 'test.mp4', { type: 'video/mp4' });
Object.defineProperty(input, 'files', {
value: [file],
});
fireEvent.change(input);
await waitFor(() => {
convertToBase64(file);
});
const postVideoUrlInput = screen.queryByTestId('postVideoUrl');

if (postVideoUrlInput) {
fireEvent.change(getByTestId('postVideoUrl'), {
target: { value: '' },
});
userEvent.click(screen.getByPlaceholderText(/video/i));
const input = getByTestId('postVideoUrl');
const file = new File(['test-video'], 'test.mp4', { type: 'video/mp4' });
Object.defineProperty(input, 'files', {
value: [file],
});
fireEvent.change(input);
await waitFor(() => {
convertToBase64(file);
});

userEvent.click(screen.getByTestId('closePreview'));
}
});
test('clears postimage state and resets file input value', async () => {
const { getByTestId } = render(
Expand All @@ -436,26 +480,29 @@ describe('Testing Organization Post Card', () => {
userEvent.click(screen.getByTestId('moreiconbtn'));

userEvent.click(screen.getByTestId('editPostModalBtn'));
userEvent.click(screen.getByTestId('closePreview'));

fireEvent.change(getByTestId('postImageUrl'), {
target: { value: '' },
});
userEvent.click(screen.getByPlaceholderText(/image/i));
const input = getByTestId('postImageUrl');
const file = new File(['test-image'], 'test.jpg', { type: 'image/jpeg' });
Object.defineProperty(input, 'files', {
value: [file],
});
fireEvent.change(input);
const imageUrlInput = screen.queryByTestId('postImageUrl');

// Simulate the asynchronous base64 conversion function
await waitFor(() => {
convertToBase64(file); // Replace with the expected base64-encoded image
});
document.getElementById = jest.fn(() => input);
const clearImageButton = getByTestId('closeimage');
fireEvent.click(clearImageButton);
if (imageUrlInput) {
fireEvent.change(getByTestId('postImageUrl'), {
target: { value: '' },
});
userEvent.click(screen.getByPlaceholderText(/image/i));
const input = getByTestId('postImageUrl');
const file = new File(['test-image'], 'test.jpg', { type: 'image/jpeg' });
Object.defineProperty(input, 'files', {
value: [file],
});
fireEvent.change(input);

// Simulate the asynchronous base64 conversion function
await waitFor(() => {
convertToBase64(file); // Replace with the expected base64-encoded image
});
document.getElementById = jest.fn(() => input);
const clearImageButton = getByTestId('closeimage');
fireEvent.click(clearImageButton);
}
});
test('Testing create organization modal', async () => {
localStorage.setItem('id', '123');
Expand Down
4 changes: 2 additions & 2 deletions src/components/OrgPostCard/OrgPostCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ export default function OrgPostCard(
data-testid="updateText"
required
/>
{props.postPhoto && (
{!props.postPhoto && (
<>
<Form.Label htmlFor="postPhoto">{t('image')}</Form.Label>
<Form.Control
Expand Down Expand Up @@ -561,7 +561,7 @@ export default function OrgPostCard(
)}
</>
)}
{props.postVideo && (
{!props.postVideo && (
<>
<Form.Label htmlFor="postvideo">{t('video')}</Form.Label>
<Form.Control
Expand Down

0 comments on commit 8d34a8b

Please sign in to comment.