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

Refactor MyProfileHeader component #3

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
@@ -0,0 +1,29 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import UserEvent from '@testing-library/user-event';
import MyProfileHeader from '../my-profile-header';

describe('<MyProfileHeader/>', () => {
it('renders the MyProfileHeader component with all the tabs', () => {
render(<MyProfileHeader />);

expect(screen.getByText('Stats')).toBeInTheDocument();
expect(screen.getByText('Payment methods')).toBeInTheDocument();
expect(screen.getByText('Ad details')).toBeInTheDocument();
expect(screen.getByText('My counterparties')).toBeInTheDocument();
});

it('can switch between tabs when a tab is clicked on', () => {
render(<MyProfileHeader />);

const StatsTab = screen.getByRole('button', { name: 'Stats' });
const MyCounterpartiesTab = screen.getByRole('button', { name: 'My counterparties' });

expect(StatsTab).toHaveClass('dc-button-menu__button--active');

UserEvent.click(MyCounterpartiesTab);

expect(StatsTab).not.toHaveClass('dc-button-menu__button--active');
expect(MyCounterpartiesTab).toHaveClass('dc-button-menu__button--active');
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import MyProfileHeader from './my-profile-header.jsx';
import MyProfileHeader from './my-profile-header';
import './my-profile-header.scss';

export default MyProfileHeader;
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react';
import { observer } from 'mobx-react-lite';
import React from 'react';
import { observer } from '@deriv/stores';
import { ButtonToggle } from '@deriv/components';
import { useStores } from 'Stores';
import { my_profile_tabs } from 'Constants/my-profile-tabs';
import ToggleContainer from 'Components/misc/toggle-container.jsx';
import { localize } from 'Components/i18next';
import { my_profile_tabs } from 'Constants/my-profile-tabs';
import { useStores } from 'Stores';

const MyProfileHeader = () => {
const { my_profile_store } = useStores();
Expand All @@ -28,7 +28,8 @@ const MyProfileHeader = () => {
},
];

const onChangeTab = event => my_profile_store.setActiveTab(event.target.value);
const onChangeTab = (event: { target: { value: string; name: string } }) =>
my_profile_store.setActiveTab(event.target.value);

return (
<ToggleContainer>
Expand Down