-
Notifications
You must be signed in to change notification settings - Fork 317
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: trading platform status unit test (#17650)
- Loading branch information
1 parent
ced6baa
commit d2148b2
Showing
4 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...tures/cfd/modals/TradingPlatformStatusModal/__tests__/TradingPlatformStatusModal.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...s/src/features/cfd/screens/TradingPlatformStatus/__tests__/TradingPlatformStatus.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); |