specifyClientRateModal.spec.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {
  2. renderGlobalModal,
  3. screen,
  4. userEvent,
  5. waitForElementToBeRemoved,
  6. } from 'sentry-test/reactTestingLibrary';
  7. import {openModal} from 'sentry/actionCreators/modal';
  8. import {SpecifyClientRateModal} from 'sentry/views/settings/project/server-side-sampling/modals/specifyClientRateModal';
  9. import {SERVER_SIDE_SAMPLING_DOC_LINK} from 'sentry/views/settings/project/server-side-sampling/utils';
  10. import {getMockData} from '../testUtils';
  11. jest.mock('sentry/utils/analytics/trackAdvancedAnalyticsEvent');
  12. describe('Server-Side Sampling - Specify Client Rate Modal', function () {
  13. it('renders', async function () {
  14. const {organization, project} = getMockData();
  15. const handleReadDocs = jest.fn();
  16. const handleGoNext = jest.fn();
  17. const handleChange = jest.fn();
  18. const {container} = renderGlobalModal();
  19. openModal(modalProps => (
  20. <SpecifyClientRateModal
  21. {...modalProps}
  22. organization={organization}
  23. onReadDocs={handleReadDocs}
  24. projectId={project.id}
  25. onGoNext={handleGoNext}
  26. value={undefined}
  27. onChange={handleChange}
  28. />
  29. ));
  30. // Header
  31. expect(
  32. await screen.findByRole('heading', {
  33. name: 'Current SDK Sample Rate',
  34. })
  35. ).toBeInTheDocument();
  36. expect(
  37. screen.getByText(/We are not able to estimate your client sample rate/)
  38. ).toBeInTheDocument();
  39. // Content
  40. expect(screen.getByRole('spinbutton')).toBeInTheDocument();
  41. // Footer
  42. expect(screen.getByRole('button', {name: 'Read Docs'})).toHaveAttribute(
  43. 'href',
  44. SERVER_SIDE_SAMPLING_DOC_LINK
  45. );
  46. expect(screen.getByText('Step 1 of 3')).toBeInTheDocument();
  47. expect(screen.getByRole('button', {name: 'Cancel'})).toBeInTheDocument();
  48. expect(screen.getByRole('button', {name: 'Next'})).toBeDisabled();
  49. expect(container).toSnapshot();
  50. // Hover over next button
  51. userEvent.hover(screen.getByRole('button', {name: 'Next'}));
  52. expect(await screen.findByText('Sample rate must not be empty')).toBeInTheDocument();
  53. // Enter valid specified client-sample rate
  54. userEvent.type(screen.getByRole('spinbutton'), '0.2{enter}');
  55. expect(handleChange).toHaveBeenCalledWith('0.2');
  56. // Click on the docs
  57. userEvent.click(screen.getByLabelText('Read Docs'));
  58. expect(handleReadDocs).toHaveBeenCalled();
  59. // Click on cancel button
  60. userEvent.click(screen.getByLabelText('Cancel'));
  61. await waitForElementToBeRemoved(() => screen.queryByLabelText('Cancel'));
  62. });
  63. });