productSelection.spec.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  3. import {textWithMarkupMatcher} from 'sentry-test/utils';
  4. import {
  5. ProductSelection,
  6. ProductSolution,
  7. } from 'sentry/components/onboarding/productSelection';
  8. describe('Onboarding Product Selection', function () {
  9. it('renders default state', async function () {
  10. const {router, routerContext} = initializeOrg({
  11. router: {
  12. location: {
  13. query: {product: ['performance-monitoring', 'session-replay']},
  14. },
  15. params: {},
  16. },
  17. });
  18. render(<ProductSelection />, {
  19. context: routerContext,
  20. });
  21. // Introduction
  22. expect(
  23. screen.getByText(
  24. textWithMarkupMatcher(/In this quick guide you’ll use npm or yarn/)
  25. )
  26. ).toBeInTheDocument();
  27. expect(screen.queryByText('Prefer to set up Sentry using')).not.toBeInTheDocument();
  28. // Error monitoring shall be checked and disabled by default
  29. expect(screen.getByRole('checkbox', {name: 'Error Monitoring'})).toBeChecked();
  30. // Tooltip with explanation shall be displayed on hover
  31. await userEvent.hover(screen.getByRole('checkbox', {name: 'Error Monitoring'}));
  32. expect(
  33. await screen.findByText(/Let's admit it, we all have errors/)
  34. ).toBeInTheDocument();
  35. // Try to uncheck error monitoring
  36. await userEvent.click(screen.getByRole('checkbox', {name: 'Error Monitoring'}));
  37. await waitFor(() => expect(router.push).not.toHaveBeenCalled());
  38. // Performance monitoring shall be checked and enabled by default
  39. expect(screen.getByRole('checkbox', {name: 'Performance Monitoring'})).toBeChecked();
  40. expect(screen.getByRole('checkbox', {name: 'Performance Monitoring'})).toBeEnabled();
  41. // Tooltip with explanation shall be displayed on hover
  42. await userEvent.hover(screen.getByRole('checkbox', {name: 'Performance Monitoring'}));
  43. expect(
  44. await screen.findByText(/Automatic performance issue detection/)
  45. ).toBeInTheDocument();
  46. // Uncheck performance monitoring
  47. await userEvent.click(screen.getByRole('checkbox', {name: 'Performance Monitoring'}));
  48. await waitFor(() =>
  49. expect(router.replace).toHaveBeenCalledWith({
  50. pathname: undefined,
  51. query: {product: ['session-replay']},
  52. })
  53. );
  54. // Session replay shall be checked and enabled by default
  55. expect(screen.getByRole('checkbox', {name: 'Session Replay'})).toBeChecked();
  56. expect(screen.getByRole('checkbox', {name: 'Session Replay'})).toBeEnabled();
  57. // Uncheck sesseion replay
  58. await userEvent.click(screen.getByRole('checkbox', {name: 'Session Replay'}));
  59. await waitFor(() =>
  60. expect(router.replace).toHaveBeenCalledWith({
  61. pathname: undefined,
  62. query: {product: ['performance-monitoring']},
  63. })
  64. );
  65. // Tooltip with explanation shall be displayed on hover
  66. await userEvent.hover(screen.getByRole('checkbox', {name: 'Session Replay'}));
  67. expect(
  68. await screen.findByText(/Video-like reproductions of user sessions/)
  69. ).toBeInTheDocument();
  70. });
  71. it('renders for Loader Script', async function () {
  72. const {routerContext} = initializeOrg({
  73. router: {
  74. location: {
  75. query: {product: ['performance-monitoring', 'session-replay']},
  76. },
  77. params: {},
  78. },
  79. });
  80. const skipLazyLoader = jest.fn();
  81. render(<ProductSelection lazyLoader skipLazyLoader={skipLazyLoader} />, {
  82. context: routerContext,
  83. });
  84. // Introduction
  85. expect(
  86. screen.getByText(
  87. textWithMarkupMatcher(/In this quick guide you’ll use our Loader Script/)
  88. )
  89. ).toBeInTheDocument();
  90. expect(
  91. screen.getByText(
  92. textWithMarkupMatcher(/Prefer to set up Sentry using npm or yarn\?/)
  93. )
  94. ).toBeInTheDocument();
  95. await userEvent.click(screen.getByText('Go here'));
  96. expect(skipLazyLoader).toHaveBeenCalledTimes(1);
  97. });
  98. it('renders disabled product', async function () {
  99. const {router, routerContext} = initializeOrg({
  100. router: {
  101. location: {
  102. query: {product: ['session-replay']},
  103. },
  104. params: {},
  105. },
  106. });
  107. const disabledProducts = [
  108. {
  109. product: ProductSolution.PERFORMANCE_MONITORING,
  110. reason: 'Product unavailable in this SDK version',
  111. },
  112. ];
  113. render(<ProductSelection disabledProducts={disabledProducts} />, {
  114. context: routerContext,
  115. });
  116. // Performance Monitoring shall be unchecked and disabled by default
  117. expect(screen.getByRole('checkbox', {name: 'Performance Monitoring'})).toBeDisabled();
  118. expect(
  119. screen.getByRole('checkbox', {name: 'Performance Monitoring'})
  120. ).not.toBeChecked();
  121. await userEvent.hover(screen.getByRole('checkbox', {name: 'Performance Monitoring'}));
  122. // A tooltip with explanation why the option is disabled shall be displayed on hover
  123. expect(await screen.findByText(disabledProducts[0].reason)).toBeInTheDocument();
  124. await userEvent.click(screen.getByRole('checkbox', {name: 'Performance Monitoring'}));
  125. // Try to uncheck performance monitoring
  126. await waitFor(() => expect(router.push).not.toHaveBeenCalled());
  127. });
  128. });