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

Shaheer/wall 1229 #9240

Merged
merged 15 commits into from
Aug 15, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import React from 'react';
import { render, screen } from '@testing-library/react';
import Notification from '../notification.jsx';

jest.mock('../../../Routes', () => ({
BinaryLink: 'mockedBinaryLink',
}));

describe('Notification component', () => {
it('should render the NotificationBanner component when "data.type" is "news"', () => {
render(<Notification data={{ type: 'news' }} />);
Expand Down Expand Up @@ -38,4 +42,22 @@ describe('Notification component', () => {
const element = screen.getByTestId('dt_default_component');
expect(element).toBeInTheDocument();
});

it('should render the "notify_financial_assessment" notification', () => {
const mock_props = {
action: {
route: '/account/financial-assessment',
text: 'Start now',
},
header: 'Pending action required',
key: 'notify_financial_assessment',
message: 'Please complete your financial assessment.',
should_show_again: true,
type: 'warning',
};
render(<Notification data={mock_props} />);
expect(screen.getByText('Pending action required')).toBeInTheDocument();
expect(screen.getByText('Please complete your financial assessment.')).toBeInTheDocument();
expect(screen.getByText('Start now')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import AppNotificationMessages from '../app-notification-messages';

jest.mock('Stores/connect', () => ({
__esModule: true,
default: 'mockedDefaultExport',
connect:
() =>
<T,>(Component: T) =>
Component,
}));

jest.mock('react-router-dom', () => ({
useLocation: jest.fn(() => ({
pathname: '/appstore/traders-hub',
})),
}));

jest.mock('react-transition-group', () => ({
TransitionGroup: jest.fn(({ children }) => <div>{children}</div>),
CSSTransition: jest.fn(({ children }) => <div>{children}</div>),
}));

jest.mock('../../Components/Elements/NotificationMessage', () => jest.fn(() => 'mockedNotification'));

describe('AppNotificationMessages', () => {
it('should render the component', () => {
const mock_props = {
marked_notifications: [],
notification_messages: [
{
action: {
route: '/account/financial-assessment',
text: 'Start now',
},
header: 'Pending action required',
key: 'notify_financial_assessment',
message: 'Please complete your financial assessment.',
should_show_again: true,
type: 'warning',
},
],
landing_company_shortcode: 'svg',
has_iom_account: false,
has_malta_account: false,
is_logged_in: true,
should_show_popups: true,
};
render(<AppNotificationMessages {...mock_props} />);
expect(screen.getByText('mockedNotification')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ const AppNotificationMessages = ({
'identity',
'install_pwa',
'need_fa',
'notify_financial_assessment',
'poi_name_mismatch',
'poa_address_mismatch_failure',
'poa_address_mismatch_success',
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Stores/Helpers/client-notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ export const priority_toast_messages = [
'need_fa',
'p2p_daily_limit_increase',
'authenticate',
'notify_financial_assessment',
'mt5_notification',
];
5 changes: 5 additions & 0 deletions packages/core/src/Stores/client-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ export default class ClientStore extends BaseStore {
default_currency: computed,
should_allow_authentication: computed,
is_financial_assessment_incomplete: computed,
is_financial_assessment_needed: computed,
is_authentication_needed: computed,
is_identity_verification_needed: computed,
real_account_creation_unlock_date: computed,
Expand Down Expand Up @@ -716,6 +717,10 @@ export default class ClientStore extends BaseStore {
return this.account_status?.status?.includes('financial_assessment_not_complete');
}

get is_financial_assessment_needed() {
return this.account_status?.status?.includes('financial_assessment_notification');
shaheer-deriv marked this conversation as resolved.
Show resolved Hide resolved
}

get is_authentication_needed() {
return !this.is_fully_authenticated && !!this.account_status?.authentication?.needs_verification?.length;
}
Expand Down
18 changes: 18 additions & 0 deletions packages/core/src/Stores/notification-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ export default class NotificationStore extends BaseStore {
has_enabled_two_fa,
has_changed_two_fa,
is_poi_dob_mismatch,
is_financial_assessment_needed,
is_financial_information_incomplete,
has_restricted_mt5_account,
has_mt5_account_with_rejected_poa,
Expand Down Expand Up @@ -369,6 +370,12 @@ export default class NotificationStore extends BaseStore {
this.addNotificationMessage(this.client_notifications.close_mx_mlt_account);
}

if (is_financial_assessment_needed) {
this.addNotificationMessage(this.client_notifications.notify_financial_assessment);
} else {
this.removeNotificationByKey({ key: this.client_notifications.notify_financial_assessment.key });
}

// Acuity notification is available for both Demo and Real desktop clients
this.addNotificationMessage(this.client_notifications.acuity);
if (!has_acuity_mt5_download && getPathname() === platform_name.DMT5) {
Expand Down Expand Up @@ -1071,6 +1078,17 @@ export default class NotificationStore extends BaseStore {
},
type: 'warning',
},
notify_financial_assessment: {
action: {
route: routes.financial_assessment,
text: localize('Start now'),
},
header: localize('Pending action required'),
key: 'notify_financial_assessment',
message: localize('Please complete your financial assessment.'),
should_show_again: true,
type: 'warning',
},
password_changed: {
key: 'password_changed',
header: localize('Password updated.'),
Expand Down
1 change: 1 addition & 0 deletions packages/stores/src/mockStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ const mock = (): TStores & { is_mock: boolean } => {
is_eu_country: false,
has_residence: false,
is_financial_account: false,
is_financial_assessment_needed: false,
is_financial_information_incomplete: false,
is_low_risk: false,
is_identity_verification_needed: false,
Expand Down
1 change: 1 addition & 0 deletions packages/stores/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ type TClientStore = {
has_residence: boolean;
is_authorize: boolean;
is_financial_account: boolean;
is_financial_assessment_needed: boolean;
is_financial_information_incomplete: boolean;
is_identity_verification_needed: boolean;
is_landing_company_loaded: boolean;
Expand Down