Skip to content

Commit 294e8ec

Browse files
Alejandro Celayaacelaya
authored andcommitted
Do not mention annotations in login panel with comments mode
1 parent cac58af commit 294e8ec

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/sidebar/components/LoginPromptPanel.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,26 @@ import {
88
RestrictedIcon,
99
} from '@hypothesis/frontend-shared';
1010

11+
import type { SidebarSettings } from '../../types/config';
12+
import { withServices } from '../service-context';
1113
import { useSidebarStore } from '../store';
1214
import SidebarPanel from './SidebarPanel';
1315

1416
export type LoginPromptPanelProps = {
1517
onLogin: () => void;
1618
onSignUp: () => void;
19+
20+
// injected
21+
settings?: SidebarSettings;
1722
};
1823

1924
/**
2025
* A sidebar panel that prompts a user to log in (or sign up) to annotate.
2126
*/
22-
export default function LoginPromptPanel({
27+
function LoginPromptPanel({
2328
onLogin,
2429
onSignUp,
30+
settings,
2531
}: LoginPromptPanelProps) {
2632
const store = useSidebarStore();
2733
const isLoggedIn = store.isLoggedIn();
@@ -36,7 +42,13 @@ export default function LoginPromptPanel({
3642
<CardTitle>Login needed</CardTitle>
3743
</CardHeader>
3844
<CardContent>
39-
<p>Please log in to create annotations or highlights.</p>
45+
<p data-testid="main-text">
46+
Please log in to{' '}
47+
{settings?.commentsMode
48+
? 'write a comment'
49+
: 'create annotations or highlights'}
50+
.
51+
</p>
4052
<CardActions>
4153
<Button title="Sign up" onClick={onSignUp}>
4254
Sign up
@@ -50,3 +62,5 @@ export default function LoginPromptPanel({
5062
</SidebarPanel>
5163
);
5264
}
65+
66+
export default withServices(LoginPromptPanel, ['settings']);

src/sidebar/components/test/LoginPromptPanel-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
mockImportedComponents,
44
} from '@hypothesis/frontend-testing';
55
import { mount } from '@hypothesis/frontend-testing';
6+
import sinon from 'sinon';
67

78
import LoginPromptPanel, { $imports } from '../LoginPromptPanel';
89

@@ -11,12 +12,14 @@ describe('LoginPromptPanel', () => {
1112
let fakeOnSignUp;
1213

1314
let fakeStore;
15+
let fakeSettings;
1416

1517
function createComponent(props) {
1618
return mount(
1719
<LoginPromptPanel
1820
onLogin={fakeOnLogin}
1921
onSignUp={fakeOnSignUp}
22+
settings={fakeSettings}
2023
{...props}
2124
/>,
2225
);
@@ -26,6 +29,7 @@ describe('LoginPromptPanel', () => {
2629
fakeStore = {
2730
isLoggedIn: sinon.stub().returns(false),
2831
};
32+
fakeSettings = { commentsMode: false };
2933

3034
fakeOnLogin = sinon.stub();
3135
fakeOnSignUp = sinon.stub();
@@ -54,6 +58,25 @@ describe('LoginPromptPanel', () => {
5458
assert.isFalse(wrapper.find('SidebarPanel').exists());
5559
});
5660

61+
it.each([
62+
{ commentsMode: true, expectedText: 'Please log in to write a comment.' },
63+
{
64+
commentsMode: false,
65+
expectedText: 'Please log in to create annotations or highlights.',
66+
},
67+
])(
68+
'shows different text for comments mode',
69+
({ commentsMode, expectedText }) => {
70+
fakeSettings.commentsMode = commentsMode;
71+
const wrapper = createComponent();
72+
73+
assert.equal(
74+
wrapper.find('[data-testid="main-text"]').text(),
75+
expectedText,
76+
);
77+
},
78+
);
79+
5780
it(
5881
'should pass a11y checks',
5982
checkAccessibility({

0 commit comments

Comments
 (0)