2022-09-02 14:53:38 +00:00
|
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
2023-02-16 03:52:54 +00:00
|
|
|
import { Networks, useEnvironment } from '@vegaprotocol/environment';
|
2022-12-13 13:31:28 +00:00
|
|
|
import { RiskNoticeDialog } from './risk-notice-dialog';
|
2022-09-02 14:53:38 +00:00
|
|
|
|
2023-02-16 03:52:54 +00:00
|
|
|
jest.mock('@vegaprotocol/environment');
|
|
|
|
|
2022-09-02 14:53:38 +00:00
|
|
|
const mockEnvDefinitions = {
|
|
|
|
VEGA_CONFIG_URL: 'https://config.url',
|
|
|
|
VEGA_URL: 'https://test.url',
|
|
|
|
VEGA_NETWORKS: JSON.stringify({}),
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Risk notice dialog', () => {
|
2022-12-13 13:31:28 +00:00
|
|
|
const mockOnClose = jest.fn();
|
|
|
|
afterEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2022-09-02 14:53:38 +00:00
|
|
|
it.each`
|
2023-04-26 15:17:23 +00:00
|
|
|
assertion | network
|
|
|
|
${'displays'} | ${Networks.CUSTOM}
|
|
|
|
${'displays'} | ${Networks.DEVNET}
|
|
|
|
${'displays'} | ${Networks.TESTNET}
|
2022-09-02 14:53:38 +00:00
|
|
|
`(
|
2023-05-02 21:01:33 +00:00
|
|
|
'$assertion a generic message on $network',
|
2022-09-02 14:53:38 +00:00
|
|
|
async ({ assertion, network }) => {
|
2023-02-16 03:52:54 +00:00
|
|
|
// @ts-ignore ignore mock implementation
|
|
|
|
useEnvironment.mockImplementation(() => ({
|
|
|
|
...mockEnvDefinitions,
|
|
|
|
VEGA_ENV: network,
|
|
|
|
}));
|
|
|
|
|
2023-05-02 21:01:33 +00:00
|
|
|
render(<RiskNoticeDialog onClose={mockOnClose} network={network} />);
|
2022-09-02 14:53:38 +00:00
|
|
|
|
2023-05-02 21:01:33 +00:00
|
|
|
expect(
|
|
|
|
screen.getByText(
|
|
|
|
new RegExp(
|
|
|
|
`This application for trading on Vega is connected to ${network}`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
|
|
|
const button = screen.getByRole('button', {
|
|
|
|
name: 'Continue',
|
|
|
|
});
|
|
|
|
fireEvent.click(button);
|
|
|
|
expect(mockOnClose).toHaveBeenCalled();
|
2022-09-02 14:53:38 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|