Skip to content

Commit

Permalink
fix: convert notification banner to text if accounts url is not set (#…
Browse files Browse the repository at this point in the history
…362)

* fix: convert banner to text if ACCOUNT_SETTINGS_URL is not set

* refactor: refactoring

* refactor: rename notificationsBannerLinkMessage to notificationsBannerPreferencesCenterMessage

* refactor: remove lodash usage

* refactor: remove lodash usage
  • Loading branch information
asadali145 authored Nov 4, 2024
1 parent 91e3374 commit c9d0abe
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 13 deletions.
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

0 comments on commit c9d0abe

Please sign in to comment.