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

feat: Added pinning functionality in the create post modal #1354

Merged
merged 7 commits into from
Jan 17, 2024
3 changes: 2 additions & 1 deletion public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,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",
"pinPost": "Pin post"
},
"postNotFound": {
"post": "Post",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,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",
"pinPost": "Épingler le message"
},
"postNotFound": {
"post": "Poste",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@
"Oldest": "सबसे पुराना पहले",
"Latest": "सबसे नवीनतम पहले",
"sortPost": "पोस्ट को क्रमित करें",
"tag": "आपका ब्राउज़र वीडियो टैग का समर्थन नहीं करता"
"tag": "आपका ब्राउज़र वीडियो टैग का समर्थन नहीं करता",
"pinPost": "पोस्ट को पिन करें"
},
"postNotFound": {
"post": "पोस्ट",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/sp.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,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",
"pinPost": "Fijar publicación"
},
"postNotFound": {
"post": "Publicaciones",
Expand Down
3 changes: 2 additions & 1 deletion public/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@
"Oldest": "最旧的优先",
"Latest": "最新的优先",
"sortPost": "排序帖子",
"tag": "您的浏览器不支持视频标签"
"tag": "您的浏览器不支持视频标签",
"pinPost": "针柱"
},
"postNotFound": {
"post": "郵政",
Expand Down
2 changes: 2 additions & 0 deletions src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ export const CREATE_POST_MUTATION = gql`
$videoUrl: URL
$organizationId: ID!
$file: String
$pinned: Boolean
) {
createPost(
data: {
Expand All @@ -303,6 +304,7 @@ export const CREATE_POST_MUTATION = gql`
imageUrl: $imageUrl
videoUrl: $videoUrl
organizationId: $organizationId
pinned: $pinned
}
file: $file
) {
Expand Down
2 changes: 2 additions & 0 deletions src/screens/OrgPost/OrgPost.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ describe('Organisation Post Page', () => {
screen.getByTestId('organisationImage'),
formData.postVideo
);
userEvent.click(screen.getByTestId('pinPost'));
expect(screen.getByTestId('pinPost')).toBeChecked();

userEvent.click(screen.getByTestId('createPostBtn'));

Expand Down
20 changes: 20 additions & 0 deletions src/screens/OrgPost/OrgPost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function orgPost(): JSX.Element {
postinfo: '',
postImage: '',
postVideo: '',
pinPost: false,
});
const [sortingOption, setSortingOption] = useState('latest');
const [showTitle, setShowTitle] = useState(true);
Expand All @@ -60,6 +61,7 @@ function orgPost(): JSX.Element {
postinfo: '',
postImage: '',
postVideo: '',
pinPost: false,
});
};

Expand Down Expand Up @@ -94,6 +96,7 @@ function orgPost(): JSX.Element {
postinfo: _postinfo,
postImage,
postVideo,
pinPost,
} = postformState;

const posttitle = _posttitle.trim();
Expand All @@ -110,6 +113,7 @@ function orgPost(): JSX.Element {
text: postinfo,
organizationId: currentUrl,
file: postImage || postVideo,
pinned: pinPost,
},
});
/* istanbul ignore next */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this /* Istanbul ignore next */ comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aashimawadhwa I have removed the comment and the test coverage dropped. To increase the test coverage I was trying to update tests to bring them back to 100%. But every single tests in src/screens/OrgPost/OrgPost.test.tsx which calls CREATE_POST_MUTATION are throwing error after it is called. The test were written exactly before that point where it starts throwing error, that is why they are currently passing.

The error looks like this:
ApolloError: No more mocked responses for the query: mutation CreatePost($text: String!, $title: String!, $organizationId: ID!, $file: String, $pinned: Boolean) { createPost( data: {text: $text, title: $title, organizationId: $organizationId, pinned: $pinned} file: $file ) { _id } } , variables: {"title":"Dummy Post","text":"This is dummy text","file":"","pinned":false}

I have tried many solutions, but nothing is actually worked. Please help.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aashimawadhwa Should I comment it out again for now?

Copy link
Member

@beingnoble03 beingnoble03 Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pateldivyesh1323 yes, please add the comment here.
@aashimawadhwa It just conveys Istanbul to not consider the if branch for code coverage. And, I guess it's not possible to test this branch. We have been using this comment in similar conditions in every other part of the codebase. For now, we can continue having this here.

Expand All @@ -121,6 +125,7 @@ function orgPost(): JSX.Element {
postinfo: '',
postImage: '',
postVideo: '',
pinPost: false,
});
setPostModalIsOpen(false); // close the modal
}
Expand Down Expand Up @@ -488,6 +493,21 @@ function orgPost(): JSX.Element {
)}
</>
)}
<Form.Label htmlFor="pinpost" className="mt-3">
{t('pinPost')}
</Form.Label>
<Form.Switch
id="pinPost"
type="checkbox"
data-testid="pinPost"
defaultChecked={postformState.pinPost}
onChange={(): void =>
setPostFormState({
...postformState,
pinPost: !postformState.pinPost,
})
}
/>
</Modal.Body>
<Modal.Footer>
<Button
Expand Down
Loading