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

fix: convert notification banner to text if accounts url is not set #362

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/containers/NotificationsBanner/NotificationsBanner.test.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import React from 'react';
import { shallow } from '@edx/react-unit-test-utils';
import { getConfig } from '@edx/frontend-platform';

import { NotificationsBanner } from '.';

jest.mock('@edx/frontend-platform', () => ({
getConfig: jest.fn(),
}));

describe('NotificationsBanner component', () => {
test('snapshots', () => {
afterEach(() => {
jest.clearAllMocks();
});

test('snapshots with empty ACCOUNT_SETTINGS_URL', () => {
getConfig.mockReturnValue({
ACCOUNT_SETTINGS_URL: '',
});
const el = shallow(<NotificationsBanner hide />);
expect(el.snapshot).toMatchSnapshot();
});

test('snapshots with ACCOUNT_SETTINGS_URL', () => {
getConfig.mockReturnValue({
ACCOUNT_SETTINGS_URL: 'http://localhost:1997',
});
const el = shallow(<NotificationsBanner hide />);
expect(el.snapshot).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`NotificationsBanner component snapshots 1`] = `
exports[`NotificationsBanner component snapshots with ACCOUNT_SETTINGS_URL 1`] = `
<PageBanner
variant="accentB"
>
Expand All @@ -27,3 +27,22 @@ exports[`NotificationsBanner component snapshots 1`] = `
</span>
</PageBanner>
`;

exports[`NotificationsBanner component snapshots with empty ACCOUNT_SETTINGS_URL 1`] = `
<PageBanner
variant="accentB"
>
<span>
<FormattedMessage
defaultMessage="You can now enable notifications for ORA assignments that require staff grading, from the "
description="user info message that user can enable notifications for ORA assignments"
id="ora-grading.NotificationsBanner.Message"
/>
<FormattedMessage
defaultMessage="preferences center."
description="placeholder for the preferences center link"
id="ora-grading.NotificationsBanner.linkMessage"
/>
</span>
</PageBanner>
`;
30 changes: 20 additions & 10 deletions src/containers/NotificationsBanner/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,26 @@ export const NotificationsBanner = () => (
<PageBanner variant="accentB">
<span>
<FormattedMessage {...messages.infoMessage} />
<Hyperlink
isInline
variant="muted"
destination={`${getConfig().ACCOUNT_SETTINGS_URL}/notifications`}
target="_blank"
rel="noopener noreferrer"
showLaunchIcon={false}
>
<FormattedMessage {...messages.notificationsBannerLinkMessage} />
</Hyperlink>
{
(
getConfig().ACCOUNT_SETTINGS_URL === null
|| getConfig().ACCOUNT_SETTINGS_URL === undefined
|| getConfig().ACCOUNT_SETTINGS_URL.trim().length === 0
) ? (
<FormattedMessage {...messages.notificationsBannerPreferencesCenterMessage} />
) : (
<Hyperlink
isInline
variant="muted"
destination={`${getConfig().ACCOUNT_SETTINGS_URL}/notifications`}
target="_blank"
rel="noopener noreferrer"
showLaunchIcon={false}
>
<FormattedMessage {...messages.notificationsBannerPreferencesCenterMessage} />
</Hyperlink>
)
}
</span>
</PageBanner>
);
Expand Down
2 changes: 1 addition & 1 deletion src/containers/NotificationsBanner/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const messages = defineMessages({
defaultMessage: 'You can now enable notifications for ORA assignments that require staff grading, from the ',
description: 'user info message that user can enable notifications for ORA assignments',
},
notificationsBannerLinkMessage: {
notificationsBannerPreferencesCenterMessage: {
id: 'ora-grading.NotificationsBanner.linkMessage',
defaultMessage: 'preferences center.',
description: 'placeholder for the preferences center link',
Expand Down
Loading