Skip to content

Commit 5defe5c

Browse files
authored
fix: profile picture is not showing in forum responses (#849)
1 parent 911b8b3 commit 5defe5c

File tree

8 files changed

+51
-11
lines changed

8 files changed

+51
-11
lines changed

src/discussions/learners/data/selectors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export const selectLearnerSorting = () => state => state.learners.sortedBy;
1414
export const selectLearnerNextPage = () => state => state.learners.nextPage;
1515

1616
export const selectLearnerAvatar = author => state => (
17-
state.learners.learnerProfiles[author]?.profileImage?.imageUrlLarge
17+
state.learners.learnerProfiles[author]?.profileImage?.imageUrlSmall
1818
);

src/discussions/post-comments/PostCommentsView.test.jsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import {
99
} from 'react-router-dom';
1010
import { Factory } from 'rosie';
1111

12-
import { camelCaseObject, initializeMockApp } from '@edx/frontend-platform';
12+
import {
13+
camelCaseObject, getConfig, initializeMockApp, setConfig,
14+
} from '@edx/frontend-platform';
1315
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
1416
import { AppProvider } from '@edx/frontend-platform/react';
1517

@@ -738,6 +740,20 @@ describe('ThreadView', () => {
738740
expect(screen.queryByTestId('comment-comment-4'))
739741
.toBeInTheDocument();
740742
});
743+
744+
it('it show avatar for reply author when ENABLE_PROFILE_IMAGE is true', async () => {
745+
setConfig({
746+
...getConfig(),
747+
ENABLE_PROFILE_IMAGE: 'true',
748+
});
749+
await waitFor(() => renderComponent(discussionPostId));
750+
751+
const comment = await waitFor(() => screen.findByTestId('comment-comment-1'));
752+
753+
expect(comment).toBeInTheDocument();
754+
const replyAuthorAvatar = within(comment).getAllByAltText('edx');
755+
expect(replyAuthorAvatar.length).toBeGreaterThan(0);
756+
});
741757
});
742758

743759
describe('for question thread', () => {

src/discussions/post-comments/comments/comment/Comment.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const Comment = ({
4646
const {
4747
id, parentId, childCount, abuseFlagged, endorsed, threadId, endorsedAt, endorsedBy, endorsedByLabel, renderedBody,
4848
voted, following, voteCount, authorLabel, author, createdAt, lastEdit, rawBody, closed, closedBy, closeReason,
49-
editByLabel, closedByLabel, users: postUsers,
49+
editByLabel, closedByLabel, users: commentUsers,
5050
} = comment;
5151
const intl = useIntl();
5252
const hasChildren = childCount > 0;
@@ -209,7 +209,7 @@ const Comment = ({
209209
closed={closed}
210210
createdAt={createdAt}
211211
lastEdit={lastEdit}
212-
postUsers={postUsers}
212+
commentUsers={commentUsers}
213213
/>
214214
{isEditing ? (
215215
<CommentEditor

src/discussions/post-comments/comments/comment/CommentHeader.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const CommentHeader = ({
1919
closed,
2020
createdAt,
2121
lastEdit,
22-
postUsers,
22+
commentUsers,
2323
}) => {
2424
const colorClass = AvatarOutlineAndLabelColors[authorLabel];
2525
const hasAnyAlert = useAlertBannerVisible({
@@ -31,7 +31,7 @@ const CommentHeader = ({
3131
const authorAvatar = useSelector(selectAuthorAvatar(author));
3232

3333
const profileImage = getConfig()?.ENABLE_PROFILE_IMAGE === 'true'
34-
? Object.values(postUsers ?? {})[0]?.profile?.image
34+
? Object.values(commentUsers ?? {})[0]?.profile?.image
3535
: null;
3636

3737
return (
@@ -43,7 +43,7 @@ const CommentHeader = ({
4343
<Avatar
4444
className={`border-0 ml-0.5 mr-2.5 ${colorClass ? `outline-${colorClass}` : 'outline-anonymous'}`}
4545
alt={author}
46-
src={profileImage?.hasImage ? profileImage?.imageUrlSmall : authorAvatar}
46+
src={profileImage?.hasImage ? profileImage?.imageUrlSmall : authorAvatar?.imageUrlSmall}
4747
style={{
4848
width: '32px',
4949
height: '32px',
@@ -72,7 +72,7 @@ CommentHeader.propTypes = {
7272
editorUsername: PropTypes.string,
7373
reason: PropTypes.string,
7474
}),
75-
postUsers: PropTypes.shape({}).isRequired,
75+
commentUsers: PropTypes.shape({}).isRequired,
7676
};
7777

7878
CommentHeader.defaultProps = {

src/discussions/post-comments/comments/comment/CommentHeader.test.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const defaultProps = {
2222
closed: false,
2323
createdAt: '2025-09-23T10:00:00Z',
2424
lastEdit: null,
25-
postUsers: {
25+
commentUsers: {
2626
'test-user': {
2727
profile: { image: { hasImage: true, imageUrlSmall: 'http://avatar.test/img.png' } },
2828
},

src/discussions/post-comments/comments/comment/Reply.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Avatar, useToggle } from '@openedx/paragon';
55
import { useDispatch, useSelector } from 'react-redux';
66
import * as timeago from 'timeago.js';
77

8+
import { getConfig } from '@edx/frontend-platform';
89
import { useIntl } from '@edx/frontend-platform/i18n';
910

1011
import HTMLLoader from '../../../../components/HTMLLoader';
@@ -24,7 +25,7 @@ import CommentEditor from './CommentEditor';
2425
const Reply = ({ responseId }) => {
2526
timeago.register('time-locale', timeLocale);
2627
const {
27-
id, abuseFlagged, author, authorLabel, endorsed, lastEdit, closed, closedBy,
28+
id, abuseFlagged, author, authorLabel, endorsed, lastEdit, closed, closedBy, users: replyUsers,
2829
closeReason, createdAt, threadId, parentId, rawBody, renderedBody, editByLabel, closedByLabel,
2930
} = useSelector(selectCommentOrResponseById(responseId));
3031
const intl = useIntl();
@@ -78,6 +79,10 @@ const Reply = ({ responseId }) => {
7879
[ContentActions.REPORT]: handleAbusedFlag,
7980
}), [handleEditContent, handleReplyEndorse, showDeleteConfirmation, handleAbusedFlag]);
8081

82+
const profileImage = getConfig()?.ENABLE_PROFILE_IMAGE === 'true'
83+
? Object.values(replyUsers ?? {})[0]?.profile?.image
84+
: null;
85+
8186
return (
8287
<div className="d-flex flex-column mt-2.5 " data-testid={`reply-${id}`} role="listitem">
8388
<Confirmation
@@ -123,7 +128,7 @@ const Reply = ({ responseId }) => {
123128
<Avatar
124129
className={`ml-0.5 mt-0.5 border-0 ${colorClass ? `outline-${colorClass}` : 'outline-anonymous'}`}
125130
alt={author}
126-
src={authorAvatar?.imageUrlSmall}
131+
src={profileImage?.hasImage ? profileImage?.imageUrlSmall : authorAvatar?.imageUrlSmall}
127132
style={{
128133
width: '32px',
129134
height: '32px',

src/discussions/post-comments/data/__factories__/comments.factory.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ Factory.define('comment')
3030
parent_id: null,
3131
children: [],
3232
abuse_flagged_any_user: false,
33+
users: {
34+
edx: {
35+
profile: {
36+
image: {
37+
hasImage: true,
38+
imageUrlSmall: 'http://test.site/default-avatar-small.png',
39+
},
40+
},
41+
},
42+
},
3343
});
3444

3545
Factory.define('commentsResult')

src/setupTest.jsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import PropTypes from 'prop-types';
22

3+
import { mergeConfig } from '@edx/frontend-platform';
4+
35
import '@testing-library/jest-dom/extend-expect';
46
import 'babel-polyfill';
57

@@ -66,3 +68,10 @@ global.ResizeObserver = jest.fn().mockImplementation(() => ({
6668
}));
6769

6870
jest.setTimeout(1000000);
71+
72+
mergeConfig({
73+
LEARNING_BASE_URL: process.env.LEARNING_BASE_URL,
74+
LEARNER_FEEDBACK_URL: process.env.LEARNER_FEEDBACK_URL,
75+
STAFF_FEEDBACK_URL: process.env.STAFF_FEEDBACK_URL,
76+
ENABLE_PROFILE_IMAGE: process.env.ENABLE_PROFILE_IMAGE || 'false',
77+
}, 'DiscussionsConfig');

0 commit comments

Comments
 (0)