productSelection.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. screen,
  5. userEvent,
  6. waitFor,
  7. within,
  8. } from 'sentry-test/reactTestingLibrary';
  9. import {textWithMarkupMatcher} from 'sentry-test/utils';
  10. import {PRODUCT, ProductSelection} from 'sentry/components/onboarding/productSelection';
  11. describe('Onboarding Product Selection', function () {
  12. it('renders default state', async function () {
  13. const {router, routerContext} = initializeOrg({
  14. ...initializeOrg(),
  15. router: {
  16. location: {
  17. query: {product: ['performance-monitoring', 'session-replay']},
  18. },
  19. params: {},
  20. },
  21. });
  22. render(<ProductSelection />, {
  23. context: routerContext,
  24. });
  25. // Introduction
  26. expect(
  27. screen.getByText(textWithMarkupMatcher(/In this quick guide you’ll use/))
  28. ).toBeInTheDocument();
  29. // Error monitoring shall be checked and disabled by default
  30. const errorMonitoring = screen.getByTestId(
  31. `product-${PRODUCT.ERROR_MONITORING}-${PRODUCT.PERFORMANCE_MONITORING}-${PRODUCT.SESSION_REPLAY}`
  32. );
  33. expect(within(errorMonitoring).getByText('Error Monitoring')).toBeInTheDocument();
  34. expect(within(errorMonitoring).getByRole('checkbox')).toBeChecked();
  35. expect(within(errorMonitoring).getByRole('checkbox')).toBeDisabled();
  36. // Try to uncheck error monitoring
  37. await userEvent.click(errorMonitoring);
  38. await waitFor(() => expect(router.push).not.toHaveBeenCalled());
  39. // Performance monitoring shall be checked and enabled by default
  40. const performanceMonitoring = screen.getByTestId(
  41. `product-${PRODUCT.PERFORMANCE_MONITORING}`
  42. );
  43. expect(
  44. within(performanceMonitoring).getByText('Performance Monitoring')
  45. ).toBeInTheDocument();
  46. expect(within(performanceMonitoring).getByRole('checkbox')).toBeChecked();
  47. expect(within(performanceMonitoring).getByRole('checkbox')).toBeEnabled();
  48. // Uncheck performance monitoring
  49. await userEvent.click(performanceMonitoring);
  50. await waitFor(() =>
  51. expect(router.push).toHaveBeenCalledWith({
  52. pathname: undefined,
  53. query: {product: ['session-replay']},
  54. })
  55. );
  56. // Session replay shall be checked and enabled by default
  57. const sessionReplay = screen.getByTestId(`product-${PRODUCT.SESSION_REPLAY}`);
  58. expect(within(sessionReplay).getByText('Session Replay')).toBeInTheDocument();
  59. expect(within(sessionReplay).getByRole('checkbox')).toBeChecked();
  60. expect(within(sessionReplay).getByRole('checkbox')).toBeEnabled();
  61. // Uncheck sesseion replay
  62. await userEvent.click(sessionReplay);
  63. await waitFor(() =>
  64. expect(router.push).toHaveBeenCalledWith({
  65. pathname: undefined,
  66. query: {product: ['performance-monitoring']},
  67. })
  68. );
  69. // Tooltip with explanation shall be displayed on hover
  70. await userEvent.hover(within(sessionReplay).getByTestId('more-information'));
  71. expect(await screen.findByRole('link', {name: 'Read the Docs'})).toBeInTheDocument();
  72. });
  73. });