9bcb923cc0
* feat: add risk warning modal WIP * feat: add risk notice modal and fix broken mobile dialog styles * fix: format * fix: lint * fix: format * fix: dialog scrollbar * fix: style issues * fix: styles * fix: spacing * fix: more style fixes * fix: more spacing * fix: format * fix: move logic into risk dialog from global app * fix: brance yourselves, more style updates * feat: add test for risk dialog
79 lines
2.3 KiB
TypeScript
79 lines
2.3 KiB
TypeScript
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import { RiskNoticeDialog } from './risk-notice-dialog';
|
|
import { Networks, EnvironmentProvider } from '@vegaprotocol/environment';
|
|
import { useGlobalStore } from '../../stores';
|
|
|
|
beforeEach(() => {
|
|
localStorage.clear();
|
|
useGlobalStore.setState((state) => ({
|
|
...state,
|
|
vegaRiskNoticeDialog: false,
|
|
}));
|
|
});
|
|
|
|
const mockEnvDefinitions = {
|
|
VEGA_CONFIG_URL: 'https://config.url',
|
|
VEGA_URL: 'https://test.url',
|
|
VEGA_NETWORKS: JSON.stringify({}),
|
|
};
|
|
|
|
describe('Risk notice dialog', () => {
|
|
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 }) => {
|
|
render(
|
|
<EnvironmentProvider
|
|
definitions={{ ...mockEnvDefinitions, VEGA_ENV: network }}
|
|
config={{ hosts: [] }}
|
|
>
|
|
<RiskNoticeDialog />
|
|
</EnvironmentProvider>
|
|
);
|
|
|
|
if (assertion === 'displays') {
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
|
expect(screen.queryByText('WARNING')).toBeInTheDocument();
|
|
} else {
|
|
// eslint-disable-next-line jest/no-conditional-expect
|
|
expect(screen.queryByText('WARNING')).not.toBeInTheDocument();
|
|
}
|
|
}
|
|
);
|
|
|
|
it("doesn't display the risk notice when previously acknowledged", () => {
|
|
const { rerender } = render(
|
|
<EnvironmentProvider
|
|
definitions={{ ...mockEnvDefinitions, VEGA_ENV: Networks.MAINNET }}
|
|
config={{ hosts: [] }}
|
|
>
|
|
<RiskNoticeDialog />
|
|
</EnvironmentProvider>
|
|
);
|
|
|
|
expect(screen.queryByText('WARNING')).toBeInTheDocument();
|
|
|
|
const button = screen.getByRole('button', {
|
|
name: 'I understand, Continue',
|
|
});
|
|
fireEvent.click(button);
|
|
|
|
rerender(
|
|
<EnvironmentProvider
|
|
definitions={{ ...mockEnvDefinitions, VEGA_ENV: Networks.MAINNET }}
|
|
config={{ hosts: [] }}
|
|
>
|
|
<RiskNoticeDialog />
|
|
</EnvironmentProvider>
|
|
);
|
|
|
|
expect(screen.queryByText('WARNING')).not.toBeInTheDocument();
|
|
});
|
|
});
|