modulesOnboarding.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import {ProjectFixture} from 'sentry-fixture/project';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import usePageFilters from 'sentry/utils/usePageFilters';
  4. import useProjects from 'sentry/utils/useProjects';
  5. import {useOnboardingProject} from 'sentry/views/insights/common/queries/useOnboardingProject';
  6. import {ModuleName} from 'sentry/views/insights/types';
  7. import {ModulesOnboarding} from './modulesOnboarding';
  8. jest.mock('sentry/utils/useProjects');
  9. jest.mock('sentry/utils/usePageFilters');
  10. jest.mock('sentry/views/insights/common/queries/useOnboardingProject');
  11. describe('ModulesOnboarding', () => {
  12. afterEach(() => {
  13. jest.resetAllMocks();
  14. });
  15. it('renders children correctly', async () => {
  16. const project = ProjectFixture({hasInsightsCaches: true});
  17. project.firstTransactionEvent = true;
  18. project.hasInsightsCaches = true;
  19. jest.mocked(useProjects).mockReturnValue({
  20. projects: [project],
  21. onSearch: jest.fn(),
  22. reloadProjects: jest.fn(),
  23. placeholders: [],
  24. fetching: false,
  25. hasMore: null,
  26. fetchError: null,
  27. initiallyLoaded: false,
  28. });
  29. jest.mocked(useOnboardingProject).mockReturnValue(undefined);
  30. jest.mocked(usePageFilters).mockReturnValue({
  31. isReady: true,
  32. desyncedFilters: new Set(),
  33. pinnedFilters: new Set(),
  34. shouldPersist: true,
  35. selection: {
  36. datetime: {
  37. period: '10d',
  38. start: null,
  39. end: null,
  40. utc: false,
  41. },
  42. environments: [],
  43. projects: [2],
  44. },
  45. });
  46. render(
  47. <ModulesOnboarding moduleName={ModuleName.CACHE}>
  48. <div>Module Content</div>
  49. </ModulesOnboarding>
  50. );
  51. await screen.getByText('Module Content');
  52. });
  53. it('renders onboarding content correctly', async () => {
  54. const project = ProjectFixture();
  55. jest.mocked(useProjects).mockReturnValue({
  56. projects: [project],
  57. onSearch: jest.fn(),
  58. reloadProjects: jest.fn(),
  59. placeholders: [],
  60. fetching: false,
  61. hasMore: null,
  62. fetchError: null,
  63. initiallyLoaded: false,
  64. });
  65. jest.mocked(usePageFilters).mockReturnValue({
  66. isReady: true,
  67. desyncedFilters: new Set(),
  68. pinnedFilters: new Set(),
  69. shouldPersist: true,
  70. selection: {
  71. datetime: {
  72. period: '10d',
  73. start: null,
  74. end: null,
  75. utc: false,
  76. },
  77. environments: [],
  78. projects: [2],
  79. },
  80. });
  81. render(
  82. <ModulesOnboarding moduleName={ModuleName.CACHE}>
  83. <div>Module Content</div>
  84. </ModulesOnboarding>
  85. );
  86. await screen.findByText('Bringing you one less hard problem in computer science');
  87. });
  88. it('renders performance onboarding if onboardingProject', async () => {
  89. const project = ProjectFixture();
  90. jest.mocked(useOnboardingProject).mockReturnValue(project);
  91. jest.mocked(useProjects).mockReturnValue({
  92. projects: [project],
  93. onSearch: jest.fn(),
  94. reloadProjects: jest.fn(),
  95. placeholders: [],
  96. fetching: false,
  97. hasMore: null,
  98. fetchError: null,
  99. initiallyLoaded: false,
  100. });
  101. jest.mocked(usePageFilters).mockReturnValue({
  102. isReady: true,
  103. desyncedFilters: new Set(),
  104. pinnedFilters: new Set(),
  105. shouldPersist: true,
  106. selection: {
  107. datetime: {
  108. period: '10d',
  109. start: null,
  110. end: null,
  111. utc: false,
  112. },
  113. environments: [],
  114. projects: [2],
  115. },
  116. });
  117. render(
  118. <ModulesOnboarding moduleName={ModuleName.CACHE}>
  119. <div>Module Content</div>
  120. </ModulesOnboarding>
  121. );
  122. await screen.findByText('Pinpoint problems');
  123. });
  124. });