Skip to content

Commit 7811908

Browse files
committed
feat: resolve conflicts
2 parents 10f00b9 + 8452b12 commit 7811908

File tree

137 files changed

+2282
-2036
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+2282
-2036
lines changed

__mocks__/translation.mock.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,12 @@ const useTranslations = () => ({
4444

4545
const localize = mockFn;
4646

47-
const getAllowedLanguages = jest.fn(() => ({ EN: 'English', VI: 'Tiếng Việt' }));
47+
const getAllowedLanguages = jest.fn(unsupported_languages => {
48+
if (unsupported_languages.includes('VI')) {
49+
return { EN: 'English' };
50+
}
51+
return { EN: 'English', VI: 'Tiếng Việt' };
52+
});
4853

4954
const getInitialLanguage = jest.fn(() => 'EN');
5055

packages/account/src/Sections/Profile/LanguageSettings/language-settings.tsx

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Redirect } from 'react-router-dom';
2-
import { UNSUPPORTED_LANGUAGES, routes } from '@deriv/shared';
2+
import { UNSUPPORTED_LANGUAGES, WALLETS_UNSUPPORTED_LANGUAGES, routes } from '@deriv/shared';
33
import { observer, useStore } from '@deriv/stores';
44
import { useTranslations, getAllowedLanguages } from '@deriv-com/translations';
55
import FormSubHeader from '../../../Components/form-sub-header';
@@ -25,13 +25,9 @@ const LanguageSettings = observer(() => {
2525
switchLanguage(language_key);
2626
};
2727

28-
let allowed_languages: Record<string, string> = getAllowedLanguages(UNSUPPORTED_LANGUAGES);
29-
30-
if (has_wallet) {
31-
allowed_languages = Object.fromEntries(
32-
Object.entries(allowed_languages).filter(([language_key]) => ['EN', 'AR'].includes(language_key))
33-
);
34-
}
28+
const allowed_languages: Record<string, string> = getAllowedLanguages(
29+
has_wallet ? WALLETS_UNSUPPORTED_LANGUAGES : UNSUPPORTED_LANGUAGES
30+
);
3531

3632
return (
3733
<div className='settings-language'>

packages/account/src/Sections/Security/Passwords/__tests__/deriv-email.spec.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,10 @@ describe('DerivEmail', () => {
3333
</APIProvider>
3434
);
3535

36-
it('should render email address in disabled form', () => {
36+
it('should render message properly', () => {
3737
renderComponent({});
3838

39-
const el_input_field = screen.getByRole('textbox', { name: /Email address\*/i });
40-
expect(el_input_field).toBeDisabled();
39+
expect(screen.getByText(/This is the email address associated with your Deriv account./i)).toBeInTheDocument();
4140
});
4241

4342
it('should display button when it is not redirected from deriv-go', () => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
3+
import DerivMT5Password from '../deriv-mt5-password';
4+
import { APIProvider, useMutation } from '@deriv/api';
5+
import { mockStore, StoreProvider } from '@deriv/stores';
6+
7+
jest.mock('@deriv/quill-icons', () => ({
8+
...jest.requireActual('@deriv/quill-icons'),
9+
PartnersProductDerivMt5BrandLightLogoHorizontalIcon: () => 'PartnersProductDerivMt5BrandLightLogoHorizontalIcon',
10+
}));
11+
12+
jest.mock('@deriv/api', () => ({
13+
...jest.requireActual('@deriv/api'),
14+
useMutation: jest.fn(() => ({ mutate: jest.fn() })),
15+
}));
16+
17+
describe('<DerivMT5Password />', () => {
18+
let modal_root_el: HTMLDivElement;
19+
20+
beforeAll(() => {
21+
modal_root_el = document.createElement('div');
22+
modal_root_el.setAttribute('id', 'modal_root');
23+
document.body.appendChild(modal_root_el);
24+
});
25+
26+
afterAll(() => {
27+
document.body.removeChild(modal_root_el);
28+
});
29+
30+
const store = mockStore({ client: { email: '[email protected]' } });
31+
32+
const renderComponent = ({ store_config = store }) =>
33+
render(
34+
<APIProvider>
35+
<StoreProvider store={store_config}>
36+
<DerivMT5Password />
37+
</StoreProvider>
38+
</APIProvider>
39+
);
40+
41+
it('Should render properly', async () => {
42+
renderComponent({});
43+
44+
expect(screen.getAllByText(/deriv mt5 password/i)).toHaveLength(2);
45+
expect(
46+
screen.getByText(/use your to log in to your Deriv MT5 accounts on the desktop, web and mobile apps\./i)
47+
).toBeInTheDocument();
48+
expect(screen.queryByText(/PartnersProductDerivMt5BrandLightLogoHorizontalIcon/i)).toBeInTheDocument();
49+
expect(screen.getByRole('button', { name: /Change password/i })).toBeInTheDocument();
50+
expect(screen.queryByText(/unlink from/i)).not.toBeInTheDocument();
51+
});
52+
53+
it('displays a change password button', () => {
54+
renderComponent({});
55+
const change_password_button = screen.getByRole('button', {
56+
name: /change password/i,
57+
});
58+
59+
expect(change_password_button).toBeInTheDocument();
60+
});
61+
62+
it('should invoke useMutation when change password is clicked', async () => {
63+
renderComponent({});
64+
const ele_change_btn = screen.getByRole('button', {
65+
name: /change password/i,
66+
});
67+
fireEvent.click(ele_change_btn);
68+
expect(screen.queryByText(/weve sent you an email/i)).toBeInTheDocument();
69+
expect(screen.getByText(/please click on the link in the email to change your/i)).toBeInTheDocument();
70+
await waitFor(() => {
71+
expect(useMutation).toHaveBeenCalled();
72+
});
73+
});
74+
});

packages/account/src/Sections/Security/Passwords/__tests__/deriv-password.spec.tsx

+5-20
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,15 @@ describe('<DerivPassword />', () => {
4141
it('Should render properly', async () => {
4242
renderComponent({});
4343

44-
expect(
45-
screen.getByRole('heading', {
46-
name: /deriv password/i,
47-
})
48-
).toBeInTheDocument();
44+
expect(screen.getAllByText(/deriv password/i)).toHaveLength(2);
4945
expect(
5046
screen.getByText(
51-
/use the to log in to deriv\.com, deriv go, deriv trader, smarttrader, deriv bot and deriv ctrader\./i
47+
/use your to log in to deriv\.com, deriv go, deriv trader, smarttrader, deriv bot and deriv ctrader\./i
5248
)
5349
).toBeInTheDocument();
5450
expect(screen.queryByText(/BrandDerivLogoCoralIcon/i)).toBeInTheDocument();
55-
expect(screen.getByRole('button', { name: /change password/i })).toBeInTheDocument();
51+
expect(screen.getByRole('button', { name: /Change password/i })).toBeInTheDocument();
5652
expect(screen.queryByText(/unlink from/i)).not.toBeInTheDocument();
57-
58-
const popover_wrapper = screen.getAllByTestId('dt_popover_wrapper');
59-
expect(popover_wrapper).toHaveLength(5);
6053
});
6154

6255
it('displays the correct platform information for non-MF clients & restricted countries', () => {
@@ -65,12 +58,7 @@ describe('<DerivPassword />', () => {
6558
});
6659
renderComponent({ store_config });
6760

68-
expect(screen.getByText(/use the to log in to deriv\.com, deriv trader and deriv go\./i));
69-
70-
const popover_wrapper = screen.getAllByTestId('dt_popover_wrapper');
71-
// expect popover to have length of 4
72-
expect(popover_wrapper).toHaveLength(3);
73-
// expect button with text change password to be in the document
61+
expect(screen.getByText(/use your to log in to deriv\.com, deriv trader and deriv go\./i));
7462
expect(screen.getByRole('button', { name: /change password/i })).toBeInTheDocument();
7563
});
7664

@@ -80,11 +68,8 @@ describe('<DerivPassword />', () => {
8068
});
8169
renderComponent({ store_config });
8270

83-
expect(screen.getByText(/use the to log in to deriv\.com and deriv trader\./i)).toBeInTheDocument();
84-
85-
const popover_wrapper = screen.getByTestId('dt_popover_wrapper');
71+
expect(screen.getByText(/use your to log in to deriv\.com and deriv trader\./i)).toBeInTheDocument();
8672

87-
expect(popover_wrapper).toBeInTheDocument();
8873
expect(screen.getByRole('button', { name: /change password/i })).toBeInTheDocument();
8974
});
9075

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
3+
import DerivXPassword from '../deriv-x-password';
4+
import { APIProvider, useMutation } from '@deriv/api';
5+
import { mockStore, StoreProvider } from '@deriv/stores';
6+
7+
jest.mock('@deriv/quill-icons', () => ({
8+
...jest.requireActual('@deriv/quill-icons'),
9+
AccountsDerivXIcon: () => 'AccountsDerivXIcon',
10+
}));
11+
12+
jest.mock('@deriv/api', () => ({
13+
...jest.requireActual('@deriv/api'),
14+
useMutation: jest.fn(() => ({ mutate: jest.fn() })),
15+
}));
16+
17+
describe('<DerivXPassword />', () => {
18+
let modal_root_el: HTMLDivElement;
19+
20+
beforeAll(() => {
21+
modal_root_el = document.createElement('div');
22+
modal_root_el.setAttribute('id', 'modal_root');
23+
document.body.appendChild(modal_root_el);
24+
});
25+
26+
afterAll(() => {
27+
document.body.removeChild(modal_root_el);
28+
});
29+
30+
const store = mockStore({ client: { email: '[email protected]' } });
31+
32+
const renderComponent = ({ store_config = store }) =>
33+
render(
34+
<APIProvider>
35+
<StoreProvider store={store_config}>
36+
<DerivXPassword />
37+
</StoreProvider>
38+
</APIProvider>
39+
);
40+
41+
it('Should render properly', async () => {
42+
renderComponent({});
43+
44+
expect(screen.getAllByText(/deriv x password/i)).toHaveLength(2);
45+
expect(
46+
screen.getByText(/use your to log in to your Deriv X accounts on the web and mobile apps\./i)
47+
).toBeInTheDocument();
48+
expect(screen.queryByText(/AccountsDerivXIcon/i)).toBeInTheDocument();
49+
expect(screen.getByRole('button', { name: /Change password/i })).toBeInTheDocument();
50+
expect(screen.queryByText(/unlink from/i)).not.toBeInTheDocument();
51+
});
52+
53+
it('displays a change password button', () => {
54+
renderComponent({});
55+
const change_password_button = screen.getByRole('button', {
56+
name: /change password/i,
57+
});
58+
59+
expect(change_password_button).toBeInTheDocument();
60+
});
61+
62+
it('should invoke useMutation when change password is clicked', async () => {
63+
renderComponent({});
64+
const ele_change_btn = screen.getByRole('button', {
65+
name: /change password/i,
66+
});
67+
fireEvent.click(ele_change_btn);
68+
expect(screen.queryByText(/weve sent you an email/i)).toBeInTheDocument();
69+
expect(screen.getByText(/please click on the link in the email to change your/i)).toBeInTheDocument();
70+
await waitFor(() => {
71+
expect(useMutation).toHaveBeenCalled();
72+
});
73+
});
74+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import React from 'react';
2+
import { render, screen, fireEvent } from '@testing-library/react';
3+
import EmailPasswordSection from '../email-password-section';
4+
5+
describe('EmailPasswordSection', () => {
6+
const mockProps = {
7+
title: 'Test Title',
8+
title_icon: 'test-icon',
9+
description: 'Test description',
10+
onClick: jest.fn(),
11+
button_text: 'Test Button',
12+
};
13+
14+
it('should renders correctly with all props', () => {
15+
render(<EmailPasswordSection {...mockProps} />);
16+
17+
expect(screen.getByText('Test Title')).toBeInTheDocument();
18+
expect(screen.getByText('Test description')).toBeInTheDocument();
19+
expect(screen.getByRole('button', { name: 'Test Button' })).toBeInTheDocument();
20+
});
21+
22+
it('should calls onClick when button is clicked', () => {
23+
render(<EmailPasswordSection {...mockProps} />);
24+
25+
const button = screen.getByRole('button', { name: 'Test Button' });
26+
fireEvent.click(button);
27+
28+
expect(mockProps.onClick).toHaveBeenCalledTimes(1);
29+
});
30+
31+
it('should not render button when should_display_button is false', () => {
32+
render(<EmailPasswordSection {...mockProps} should_display_button={false} />);
33+
34+
expect(screen.queryByRole('button')).not.toBeInTheDocument();
35+
});
36+
37+
it('should render button with icon when provided', () => {
38+
const buttonIcon = <span data-testid='test-icon'>Icon</span>;
39+
render(<EmailPasswordSection {...mockProps} button_icon={buttonIcon} />);
40+
41+
const button = screen.getByRole('button', { name: 'Icon Test Button' });
42+
expect(button).toContainElement(screen.getByTestId('test-icon'));
43+
});
44+
45+
it('should render description as ReactNode when provided', () => {
46+
const customDescription = <span data-testid='custom-description'>Custom Description</span>;
47+
render(<EmailPasswordSection {...mockProps} description={customDescription} />);
48+
49+
expect(screen.getByTestId('custom-description')).toBeInTheDocument();
50+
});
51+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { render, screen } from '@testing-library/react';
3+
import EmailPasswordTitle from '../email-password-title';
4+
import { AccountsDerivXIcon, BrandDerivLogoCoralIcon, LegacyEmailIcon } from '@deriv/quill-icons';
5+
6+
jest.mock('@deriv/quill-icons', () => ({
7+
AccountsDerivXIcon: jest.fn(() => null),
8+
BrandDerivLogoCoralIcon: jest.fn(() => null),
9+
PartnersProductDerivMt5BrandLightLogoHorizontalIcon: jest.fn(() => null),
10+
LegacyEmailIcon: jest.fn(() => null),
11+
}));
12+
13+
describe('EmailPasswordTitle', () => {
14+
it('renders the correct icon and title for deriv_email', () => {
15+
render(<EmailPasswordTitle icon='deriv_email' title='Email' />);
16+
17+
expect(LegacyEmailIcon).toHaveBeenCalledWith({ iconSize: 'sm' }, {});
18+
expect(screen.getByText('Email')).toBeInTheDocument();
19+
});
20+
21+
it('renders the correct icon and title for deriv_password', () => {
22+
render(<EmailPasswordTitle icon='deriv_password' title='Deriv Password' />);
23+
24+
expect(BrandDerivLogoCoralIcon).toHaveBeenCalledWith({ height: 24, width: 24 }, {});
25+
expect(screen.getByText('Deriv Password')).toBeInTheDocument();
26+
});
27+
28+
it('renders the correct icon and title for deriv_mt5_password', () => {
29+
render(<EmailPasswordTitle icon='deriv_mt5_password' title='MT5 Password' />);
30+
31+
expect(BrandDerivLogoCoralIcon).toHaveBeenCalledWith({ height: 24, width: 24 }, {});
32+
expect(screen.getByText('MT5 Password')).toBeInTheDocument();
33+
});
34+
35+
it('renders the correct icon and title for deriv_x_password', () => {
36+
render(<EmailPasswordTitle icon='deriv_x_password' title='Deriv X Password' />);
37+
38+
expect(AccountsDerivXIcon).toHaveBeenCalledWith({ iconSize: 'sm' }, {});
39+
expect(screen.getByText('Deriv X Password')).toBeInTheDocument();
40+
});
41+
});

0 commit comments

Comments
 (0)