Skip to content

Commit

Permalink
fix: trading platform status unit test (#17650)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubega-deriv authored Nov 25, 2024
1 parent ced6baa commit d2148b2
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DISABLED_PLATFORM_STATUSES } from '../../constants';
import { TradingPlatformStatus } from '../../screens';

type TradingPlatformStatusModalProps = {
status: typeof DISABLED_PLATFORM_STATUSES[number];
status: (typeof DISABLED_PLATFORM_STATUSES)[number];
};

const TradingPlatformStatusModal: React.FC<TradingPlatformStatusModalProps> = ({ status }) => (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import TradingPlatformStatusModal from '../TradingPlatformStatusModal';

jest.mock('../../../../../components/Base', () => ({
ModalWrapper: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
}));

jest.mock('../../../screens', () => ({
TradingPlatformStatus: jest.fn(() => <div>MockedTradingPlatformStatus</div>),
}));

describe('TradingPlatformStatusModal', () => {
it('renders TradingPlatformStatus', () => {
render(<TradingPlatformStatusModal status='under_maintenance' />);

expect(screen.getByText(/MockedTradingPlatformStatus/)).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { DISABLED_PLATFORM_STATUSES, MT5_ACCOUNT_STATUS, TRADING_PLATFORM_STATUS
import './TradingPlatformStatus.scss';

type TradingPlatformStatusModalProps = {
status: typeof DISABLED_PLATFORM_STATUSES[number];
status: (typeof DISABLED_PLATFORM_STATUSES)[number];
};

const getContentConfig = (localize: ReturnType<typeof useTranslations>['localize']) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import { useDevice } from '@deriv-com/ui';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ModalProvider } from '../../../../../components/ModalProvider';
import TradingPlatformStatus from '../TradingPlatformStatus';

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

const mockHide = jest.fn();
jest.mock('../../../../../components/ModalProvider', () => ({
...jest.requireActual('../../../../../components/ModalProvider'),
useModal: jest.fn(() => ({
...jest.requireActual('../../../../../components/ModalProvider').useModal(),
hide: mockHide,
})),
}));

describe('TradingPlatformStatus', () => {
beforeEach(() => {
(useDevice as jest.Mock).mockReturnValue({ isDesktop: true });
});

it('renders default content for maintenance status', () => {
render(
<ModalProvider>
<TradingPlatformStatus status='under_maintenance' />
</ModalProvider>
);

expect(screen.getByText('Server Maintenance')).toBeInTheDocument();
expect(
screen.getByText('We’re currently performing server maintenance. Service may be affected.')
).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'OK' })).toBeInTheDocument();
});

it('renders default content for unavailable status', () => {
render(
<ModalProvider>
<TradingPlatformStatus status='unavailable' />
</ModalProvider>
);

expect(screen.getByText('Account Unavailable')).toBeInTheDocument();
expect(
screen.getByText('The server is temporarily unavailable for this account. We’re working to resolve this.')
).toBeInTheDocument();
expect(screen.getByRole('button', { name: 'OK' })).toBeInTheDocument();
});

it('calls hide when clicking on OK button', async () => {
(useDevice as jest.Mock).mockReturnValue({ isDesktop: false });
render(
<ModalProvider>
<TradingPlatformStatus status='under_maintenance' />
</ModalProvider>
);

await userEvent.click(screen.getByRole('button', { name: 'OK' }));
expect(mockHide).toHaveBeenCalled();
});
});

0 comments on commit d2148b2

Please sign in to comment.