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

Dhruv/mt5 password modal styling/trah 3963 #116

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
542bf8d
fix: style
Dhruv-deriv Aug 19, 2024
d3ffe71
fix: Removed and fixed the styles of MT5 password model
Dhruv-deriv Aug 19, 2024
9e9972e
fix: cleaned up code
Dhruv-deriv Aug 20, 2024
cd13bf0
fix: restored deleted file
Dhruv-deriv Aug 20, 2024
ada2bde
chore: added testcases for MT5CreatePassword
Dhruv-deriv Aug 21, 2024
b504f7b
fix: cleaned the code
Dhruv-deriv Aug 22, 2024
9813d12
fix: modifies test case
Dhruv-deriv Aug 23, 2024
b430ac7
Merge branch 'dhruv/amina_mt5_defaulting_jurisdiction' into dhruv/TRA…
Dhruv-deriv Aug 23, 2024
082aeca
fix: merges fixed
Dhruv-deriv Aug 23, 2024
799a388
fix: added test case for Mt5CreatePassword
Dhruv-deriv Aug 23, 2024
6549843
fix: empty commit for merging
Dhruv-deriv Aug 23, 2024
6b564f1
fix: added test cases1
Dhruv-deriv Aug 23, 2024
2cce76f
fix: added test cases2
Dhruv-deriv Aug 23, 2024
0f854a5
fix: cleaned code and removed unnecessary styles from scss
Dhruv-deriv Aug 26, 2024
e651aac
fix: code recovered
Dhruv-deriv Aug 26, 2024
3a1558f
fix: cleaned code added missing style
Dhruv-deriv Aug 26, 2024
e9f0597
fix: reaolved comments2
Dhruv-deriv Aug 26, 2024
0752a5c
fix: resolved comments3
Dhruv-deriv Aug 26, 2024
5699da9
fix: resolved comments4
Dhruv-deriv Aug 26, 2024
45ff441
fix: resolved comments5
Dhruv-deriv Aug 26, 2024
5b58678
fix: added icon testcase
Dhruv-deriv Aug 26, 2024
686bb54
fix: cleaned coded2
Dhruv-deriv Aug 26, 2024
f694bc2
fix: rectified styles and changed names of style classes
Dhruv-deriv Aug 27, 2024
acd1a3f
fix: cleaned code and styles
Dhruv-deriv Aug 27, 2024
94ee60d
fix: resolved comments
Dhruv-deriv Aug 28, 2024
e806ccb
fix: resolved comments2
Dhruv-deriv Aug 28, 2024
91de439
fix: resolved comments3
Dhruv-deriv Aug 28, 2024
3afda7c
fix: resolved comments4
Dhruv-deriv Aug 28, 2024
f73b823
fix: cleaned testcases
Dhruv-deriv Aug 28, 2024
e051d0b
fix: resolved testcases
Dhruv-deriv Aug 28, 2024
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 @@ -2044,7 +2044,6 @@
overflow-x: hidden;
height: 100%;
max-height: calc(100% - 6.4rem);
padding: 1rem;
Dhruv-deriv marked this conversation as resolved.
Show resolved Hide resolved
}
}
@include tablet-up {
Expand Down
4 changes: 2 additions & 2 deletions packages/cfd/src/Containers/cfd-password-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import { useCfdStore } from '../Stores/Modules/CFD/Helpers/useCfdStores';
import { CFD_PLATFORMS, CATEGORY } from '../Helpers/cfd-config';
import classNames from 'classnames';
import { getDxCompanies, getMtCompanies, TDxCompanies, TMtCompanies } from '../Stores/Modules/CFD/Helpers/cfd-config';
import '../sass/cfd.scss';
import './mt5-create-password/mt5-create-password.scss';
Dhruv-deriv marked this conversation as resolved.
Show resolved Hide resolved
import { useGetDefaultMT5Jurisdiction } from '@deriv/hooks';

const MT5CreatePassword = makeLazyLoader(
() => moduleLoader(() => import('./mt5-create-password')),
() => moduleLoader(() => import('./mt5-create-password/mt5-create-password')),
() => <div />
)();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import React from 'react';
import { Router } from 'react-router';
import { createBrowserHistory } from 'history';
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import MT5CreatePassword from '../mt5-create-password';
import { mockStore } from '@deriv/stores';
import CFDProviders from '../../../cfd-providers';
import { getErrorMessages, validPassword } from '@deriv/shared';

jest.mock('@deriv/components', () => ({
...jest.requireActual('@deriv/components'),
Icon: jest.fn(({ icon }) => <div>{icon}</div>),
useDevice: () => ({ isMobile: false }),
}));

jest.mock('@deriv/shared', () => ({
...jest.requireActual('@deriv/shared'),
getErrorMessages: jest.fn().mockReturnValue({
password_warnings: '',
password: jest.fn().mockReturnValue('Password should have lower and uppercase English letters with numbers.'),
}),
validPassword: jest.fn().mockReturnValue(true),
isDesktop: jest.fn().mockReturnValue(true),
DBVI_COMPANY_NAMES: {
svg: { name: 'Sample Company', licence_name: 'Sample Licence' },
other: { name: 'Other Company', licence_name: 'Other Licence' },
},
}));

describe('<MT5CreatePassword/>', () => {
const mockFn = jest.fn();
const mockSubmitMt5Password = jest.fn();
const history = createBrowserHistory();
let modal_root_el;

let mockRootStore = {
client: {
email: '',
account_status: {},
updateAccountStatus: jest.fn(),
landing_companies: {},
mt5_login_list: [],
is_dxtrade_allowed: false,
},
traders_hub: {
show_eu_related_content: false,
},
modules: {
cfd: {
is_cfd_password_modal_enabled: true,
submitMt5Password: mockSubmitMt5Password,
setError: jest.fn(),
setCFDSuccessDialog: jest.fn(),
has_cfd_error: false,
error_message: '',
account_title: '',
account_type: {},
getAccountStatus: mockFn,
new_account_response: {},
jurisdiction_selected_shortcode: 'svg',
setProduct: jest.fn(),
},
},
};

const default_props = {
password: '',
platform: 'mt5',
error_message: '',
validatePassword: jest.fn(),
onSubmit: jest.fn(),
need_tnc: true,
};

beforeAll(() => {
modal_root_el = document.createElement('div');
modal_root_el.setAttribute('id', 'modal_root');
document.body.appendChild(modal_root_el);
});

afterAll(() => {
document.body.removeChild(modal_root_el);
});

it('should render MT5CreatePassword component', async () => {
render(
<Router history={history}>
<MT5CreatePassword {...default_props} />
</Router>,
{
wrapper: ({ children }) => <CFDProviders store={mockStore(mockRootStore)}>{children}</CFDProviders>,
}
);

expect(await screen.findByTestId('dt_create_password')).toBeInTheDocument();
Dhruv-deriv marked this conversation as resolved.
Show resolved Hide resolved
});

it('should display password field for user to enter the password and hold the entered value', async () => {
const user_input = 'zo8lAet#2q01Ih';

render(
<Router history={history}>
<MT5CreatePassword {...default_props} />
</Router>,
{
wrapper: ({ children }) => <CFDProviders store={mockStore(mockRootStore)}>{children}</CFDProviders>,
}
);
const password_input = await screen.findByTestId('dt_mt5_password');
fireEvent.change(password_input, { target: { value: user_input } });
await waitFor(() => {
expect(password_input.value).toBe(user_input);
});
});

it('should display password requirements message', async () => {
render(
<Router history={history}>
<MT5CreatePassword {...default_props} />
</Router>,
{
wrapper: ({ children }) => <CFDProviders store={mockStore(mockRootStore)}>{children}</CFDProviders>,
}
);

expect(await screen.findByText(/This password works for all your Deriv MT5 accounts./i)).toBeInTheDocument();
});

it('should show TNC checkbox when need_tnc is true', async () => {
render(
<Router history={history}>
<MT5CreatePassword {...default_props} need_tnc={true} />
</Router>,
{
wrapper: ({ children }) => <CFDProviders store={mockStore(mockRootStore)}>{children}</CFDProviders>,
}
);
const checkbox = await screen.findByRole('checkbox');
expect(checkbox).toBeInTheDocument();
});

it('should call onSubmit when form is submitted', async () => {
const user_input = 'zo8lAet#2q01Ih';
const onSubmit = jest.fn();
const validatePassword = jest.fn().mockReturnValue({});

render(
<Router history={history}>
<MT5CreatePassword
{...default_props}
password={user_input}
onSubmit={onSubmit}
validatePassword={validatePassword}
/>
</Router>,
{
wrapper: ({ children }) => <CFDProviders store={mockStore(mockRootStore)}>{children}</CFDProviders>,
}
);

const passwordInput = await screen.findByTestId('dt_mt5_password');
const submitButton = await screen.findByRole('button', { name: /Create account/i });

expect(passwordInput).toBeInTheDocument();
expect(submitButton).toBeInTheDocument();

fireEvent.change(passwordInput, { target: { value: user_input } });
fireEvent.click(submitButton);

await waitFor(() => {
expect(onSubmit).toHaveBeenCalled();
});
});
});
Loading
Loading