specifyClientRateModal.spec.tsx 2.7 KB

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