Skip to content

Commit

Permalink
test: added test cases for menu header component
Browse files Browse the repository at this point in the history
  • Loading branch information
niloofar-deriv committed Jun 18, 2024
1 parent 03e9006 commit c760681
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/components/AppHeader/MobileMenu/__tests__/MenuHeader.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useTranslations } from '@deriv-com/translations';
import { useDevice } from '@deriv-com/ui';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MenuHeader } from '../MenuHeader';

const mockOpenLanguageSetting = jest.fn();

jest.mock('@deriv-com/ui', () => ({
...jest.requireActual('@deriv-com/ui'),
useDevice: jest.fn(() => ({ isMobile: true })),
}));

jest.mock('@deriv-com/translations', () => ({
useTranslations: jest.fn(),
}));

describe('MenuHeader component', () => {
beforeEach(() => {
(useTranslations as jest.Mock).mockReturnValue({
currentLang: 'EN',
localize: jest.fn(text => text),
});
});

it('renders "Menu" with "lg" text size in mobile view', () => {
render(<MenuHeader hideLanguageSetting={false} openLanguageSetting={mockOpenLanguageSetting} />);
expect(screen.getByText('Menu')).toHaveClass('derivs-text__size--lg');
});

it('renders "Menu" with "md" text size in desktop view', () => {
(useDevice as jest.Mock).mockReturnValue({ isMobile: false });
render(<MenuHeader hideLanguageSetting={false} openLanguageSetting={mockOpenLanguageSetting} />);
expect(screen.getByText('Menu')).toHaveClass('derivs-text__size--md');
});

it('does not render language setting button when hideLanguageSetting is true', () => {
render(<MenuHeader hideLanguageSetting openLanguageSetting={mockOpenLanguageSetting} />);
expect(screen.queryByText('EN')).not.toBeInTheDocument();
});

it('renders language setting button with correct content when hideLanguageSetting is false', () => {
render(<MenuHeader hideLanguageSetting={false} openLanguageSetting={mockOpenLanguageSetting} />);
expect(screen.getByText('EN')).toBeInTheDocument();
});

it('calls openLanguageSetting when language button is clicked', async () => {
render(<MenuHeader hideLanguageSetting={false} openLanguageSetting={mockOpenLanguageSetting} />);
await userEvent.click(screen.getByText('EN'));
expect(mockOpenLanguageSetting).toHaveBeenCalled();
});
});

0 comments on commit c760681

Please sign in to comment.