2022-12-13 13:31:28 +00:00
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
2022-09-02 14:53:38 +00:00
|
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
2022-12-13 13:31:28 +00:00
|
|
|
import { MockedProvider } from '@apollo/client/testing';
|
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';
|
|
|
|
import { WelcomeDialog } from './welcome-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 introText = 'Regulation may apply to use of this app';
|
|
|
|
const mockOnClose = jest.fn();
|
|
|
|
afterEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
2022-09-02 14:53:38 +00:00
|
|
|
it.each`
|
|
|
|
assertion | network
|
|
|
|
${'displays'} | ${Networks.MAINNET}
|
|
|
|
${'does not display'} | ${Networks.CUSTOM}
|
|
|
|
${'does not display'} | ${Networks.DEVNET}
|
|
|
|
${'does not display'} | ${Networks.STAGNET3}
|
|
|
|
${'does not display'} | ${Networks.TESTNET}
|
|
|
|
`(
|
|
|
|
'$assertion the risk notice on $network',
|
|
|
|
async ({ assertion, network }) => {
|
2023-02-16 03:52:54 +00:00
|
|
|
// @ts-ignore ignore mock implementation
|
|
|
|
useEnvironment.mockImplementation(() => ({
|
|
|
|
...mockEnvDefinitions,
|
|
|
|
VEGA_ENV: network,
|
|
|
|
}));
|
|
|
|
|
2022-09-02 14:53:38 +00:00
|
|
|
render(
|
2023-02-16 03:52:54 +00:00
|
|
|
<MockedProvider>
|
|
|
|
<WelcomeDialog />
|
|
|
|
</MockedProvider>,
|
2022-12-13 13:31:28 +00:00
|
|
|
{ wrapper: BrowserRouter }
|
2022-09-02 14:53:38 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (assertion === 'displays') {
|
|
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
2022-12-13 13:31:28 +00:00
|
|
|
expect(screen.queryByText(introText)).toBeInTheDocument();
|
2022-09-02 14:53:38 +00:00
|
|
|
} else {
|
|
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
2022-12-13 13:31:28 +00:00
|
|
|
expect(screen.queryByText(introText)).not.toBeInTheDocument();
|
2022-09-02 14:53:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
it("doesn't display the risk notice when previously acknowledged", () => {
|
2023-02-16 03:52:54 +00:00
|
|
|
// @ts-ignore ignore mock implementation
|
|
|
|
useEnvironment.mockImplementation(() => ({
|
|
|
|
...mockEnvDefinitions,
|
|
|
|
VEGA_ENV: Networks.MAINNET,
|
|
|
|
}));
|
|
|
|
|
|
|
|
render(<RiskNoticeDialog onClose={mockOnClose} />);
|
2022-09-02 14:53:38 +00:00
|
|
|
|
2022-12-13 13:31:28 +00:00
|
|
|
expect(screen.queryByText(introText)).toBeInTheDocument();
|
2022-09-02 14:53:38 +00:00
|
|
|
|
|
|
|
const button = screen.getByRole('button', {
|
|
|
|
name: 'I understand, Continue',
|
|
|
|
});
|
|
|
|
fireEvent.click(button);
|
2022-12-13 13:31:28 +00:00
|
|
|
expect(mockOnClose).toHaveBeenCalled();
|
2022-09-02 14:53:38 +00:00
|
|
|
});
|
|
|
|
});
|