fix: anonymous user is not clickable (#258)

* fix: anonymous user is not clickable

* fix: link handled for anonymous user everywhere
This commit is contained in:
Mehak Nasir
2022-08-23 13:19:36 +05:00
committed by GitHub
parent 7ee5a8e157
commit 9be71ff92e
7 changed files with 22 additions and 5 deletions

View File

@@ -75,7 +75,7 @@ function AuthorLabel({
</div>
);
return linkToProfile && author && learnersTabEnabled
return linkToProfile && author && learnersTabEnabled && author !== messages.anonymous
? (
<Link
data-testid="learner-posts-link"

View File

@@ -77,7 +77,7 @@ export default function DiscussionsHome() {
}}
>
{!inIframe && <Header />}
<main className="container-fluid d-flex flex-column p-0 h-100 w-100 overflow-hidden" id="main" tabIndex={-1}>
<main className="container-fluid d-flex flex-column p-0 h-100 w-100 overflow-hidden" id="main" tabIndex="-1">
{!inIframe
&& <CourseTabsNavigation activeTab="discussion" courseId={courseId} />}
<div

View File

@@ -28,7 +28,7 @@ const ActionItem = ({
aria-checked={value === selected}
>
<Icon src={Check} className={classNames('text-success mr-2', { invisible: value !== selected })} />
<Form.Radio id={id} className="sr-only sr-only-focusable" value={value} tabIndex={0}>
<Form.Radio id={id} className="sr-only sr-only-focusable" value={value} tabIndex="0">
{label}
</Form.Radio>
<span aria-hidden className="text-truncate">

View File

@@ -153,6 +153,11 @@ const messages = defineMessages({
defaultMessage: 'Load more posts',
description: 'Text on button for loading more posts by a user',
},
anonymous: {
id: 'discussions.post.anonymous.author',
defaultMessage: 'anonymous',
description: 'Author name displayed when a post is anonymous',
},
});
export default messages;

View File

@@ -39,7 +39,7 @@ const ActionItem = ({
aria-checked={value === selected}
>
<Icon src={Check} className={classNames('text-success mr-2', { invisible: value !== selected })} />
<Form.Radio id={id} className="sr-only sr-only-focusable" value={value} tabIndex={0}>
<Form.Radio id={id} className="sr-only sr-only-focusable" value={value} tabIndex="0">
{label}
</Form.Radio>
<span aria-hidden className="text-truncate">

View File

@@ -109,7 +109,7 @@ function PostHeader({
&& <Badge variant="success">{intl.formatMessage(messages.answered)}</Badge>}
</div>
)
: <h4 className="mb-0" style={{ lineHeight: '28px' }} aria-level="1" tabIndex={-1} accessKey="h">{post.title}</h4>}
: <h4 className="mb-0" style={{ lineHeight: '28px' }} aria-level="1" tabIndex="-1" accessKey="h">{post.title}</h4>}
<AuthorLabel
author={post.author || intl.formatMessage(messages.anonymous)}
authorLabel={post.authorLabel}

View File

@@ -106,4 +106,16 @@ describe('Post username', () => {
expect(screen.queryByTestId('learner-posts-link')).toBeInTheDocument();
}
});
it.each([
true,
false,
])('is only clickable if user is not anonymous', async (isAnonymous) => {
renderComponent({ ...mockPost, author: isAnonymous ? null : 'test-user' });
if (isAnonymous) {
expect(screen.queryByTestId('learner-posts-link')).not.toBeInTheDocument();
} else {
expect(screen.queryByTestId('learner-posts-link')).toBeInTheDocument();
}
});
});