From 0f83d77bc45d53c71d50ca666e0a2c2e1531c913 Mon Sep 17 00:00:00 2001 From: Asad Ali Date: Wed, 2 Oct 2024 14:22:24 +0500 Subject: [PATCH 1/5] fix: convert banner to text if ACCOUNT_SETTINGS_URL is not set --- .../NotificationsBanner.test.jsx | 22 ++++++++++++++- .../NotificationsBanner.test.jsx.snap | 21 ++++++++++++++- src/containers/NotificationsBanner/index.jsx | 27 ++++++++++++------- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/containers/NotificationsBanner/NotificationsBanner.test.jsx b/src/containers/NotificationsBanner/NotificationsBanner.test.jsx index d111c5fb..eb3a3686 100644 --- a/src/containers/NotificationsBanner/NotificationsBanner.test.jsx +++ b/src/containers/NotificationsBanner/NotificationsBanner.test.jsx @@ -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(); + expect(el.snapshot).toMatchSnapshot(); + }); + + test('snapshots with ACCOUNT_SETTINGS_URL', () => { + getConfig.mockReturnValue({ + ACCOUNT_SETTINGS_URL: 'http://localhost:1997', + }); const el = shallow(); expect(el.snapshot).toMatchSnapshot(); }); diff --git a/src/containers/NotificationsBanner/__snapshots__/NotificationsBanner.test.jsx.snap b/src/containers/NotificationsBanner/__snapshots__/NotificationsBanner.test.jsx.snap index ba208b01..87c8ee3f 100644 --- a/src/containers/NotificationsBanner/__snapshots__/NotificationsBanner.test.jsx.snap +++ b/src/containers/NotificationsBanner/__snapshots__/NotificationsBanner.test.jsx.snap @@ -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`] = ` @@ -27,3 +27,22 @@ exports[`NotificationsBanner component snapshots 1`] = ` `; + +exports[`NotificationsBanner component snapshots with empty ACCOUNT_SETTINGS_URL 1`] = ` + + + + + + +`; diff --git a/src/containers/NotificationsBanner/index.jsx b/src/containers/NotificationsBanner/index.jsx index 4c334e78..5ab6d6f4 100644 --- a/src/containers/NotificationsBanner/index.jsx +++ b/src/containers/NotificationsBanner/index.jsx @@ -1,4 +1,5 @@ import React from 'react'; +import _ from 'lodash'; import { getConfig } from '@edx/frontend-platform'; import { FormattedMessage } from '@edx/frontend-platform/i18n'; @@ -10,16 +11,22 @@ export const NotificationsBanner = () => ( - - - + { + _.isEmpty(getConfig().ACCOUNT_SETTINGS_URL) ? ( + + ) : ( + + + + ) + } ); From 2b2efe20fe5efca846e7b447262b8d772ee77853 Mon Sep 17 00:00:00 2001 From: Asad Ali Date: Mon, 14 Oct 2024 12:22:49 +0500 Subject: [PATCH 2/5] refactor: refactoring --- src/containers/NotificationsBanner/index.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/NotificationsBanner/index.jsx b/src/containers/NotificationsBanner/index.jsx index 5ab6d6f4..d33c07ec 100644 --- a/src/containers/NotificationsBanner/index.jsx +++ b/src/containers/NotificationsBanner/index.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import _ from 'lodash'; +import { isEmpty } from 'lodash'; import { getConfig } from '@edx/frontend-platform'; import { FormattedMessage } from '@edx/frontend-platform/i18n'; @@ -12,7 +12,7 @@ export const NotificationsBanner = () => ( { - _.isEmpty(getConfig().ACCOUNT_SETTINGS_URL) ? ( + isEmpty(getConfig().ACCOUNT_SETTINGS_URL) ? ( ) : ( Date: Fri, 18 Oct 2024 16:57:00 +0500 Subject: [PATCH 3/5] refactor: rename notificationsBannerLinkMessage to notificationsBannerPreferencesCenterMessage --- src/containers/NotificationsBanner/index.jsx | 4 ++-- src/containers/NotificationsBanner/messages.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/containers/NotificationsBanner/index.jsx b/src/containers/NotificationsBanner/index.jsx index d33c07ec..45e440ee 100644 --- a/src/containers/NotificationsBanner/index.jsx +++ b/src/containers/NotificationsBanner/index.jsx @@ -13,7 +13,7 @@ export const NotificationsBanner = () => ( { isEmpty(getConfig().ACCOUNT_SETTINGS_URL) ? ( - + ) : ( ( rel="noopener noreferrer" showLaunchIcon={false} > - + ) } diff --git a/src/containers/NotificationsBanner/messages.js b/src/containers/NotificationsBanner/messages.js index 8a831ed9..e92f4f4b 100644 --- a/src/containers/NotificationsBanner/messages.js +++ b/src/containers/NotificationsBanner/messages.js @@ -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', From 4e9039e4d894d110b506aa76091614ceffff201a Mon Sep 17 00:00:00 2001 From: Asad Ali Date: Mon, 28 Oct 2024 15:42:41 +0500 Subject: [PATCH 4/5] refactor: remove lodash usage --- src/containers/NotificationsBanner/index.jsx | 32 +++++++++++--------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/src/containers/NotificationsBanner/index.jsx b/src/containers/NotificationsBanner/index.jsx index 45e440ee..a1151067 100644 --- a/src/containers/NotificationsBanner/index.jsx +++ b/src/containers/NotificationsBanner/index.jsx @@ -12,21 +12,25 @@ export const NotificationsBanner = () => ( { - isEmpty(getConfig().ACCOUNT_SETTINGS_URL) ? ( + ( + getConfig().ACCOUNT_SETTINGS_URL === null + || getConfig().ACCOUNT_SETTINGS_URL === undefined + || getConfig().ACCOUNT_SETTINGS_URL.trim().length === 0 + ) ? ( - ) : ( - - - - ) - } + ) : ( + + + + ) + } ); From b014d97acd04aabc2d2c66396ce289e742a788dc Mon Sep 17 00:00:00 2001 From: Asad Ali Date: Mon, 28 Oct 2024 15:43:17 +0500 Subject: [PATCH 5/5] refactor: remove lodash usage --- src/containers/NotificationsBanner/index.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/containers/NotificationsBanner/index.jsx b/src/containers/NotificationsBanner/index.jsx index a1151067..64ad410c 100644 --- a/src/containers/NotificationsBanner/index.jsx +++ b/src/containers/NotificationsBanner/index.jsx @@ -1,5 +1,4 @@ import React from 'react'; -import { isEmpty } from 'lodash'; import { getConfig } from '@edx/frontend-platform'; import { FormattedMessage } from '@edx/frontend-platform/i18n';