modulesOnboarding.spec.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. placeholders: [],
  23. fetching: false,
  24. hasMore: null,
  25. fetchError: null,
  26. initiallyLoaded: false,
  27. });
  28. jest.mocked(useOnboardingProject).mockReturnValue(undefined);
  29. jest.mocked(usePageFilters).mockReturnValue({
  30. isReady: true,
  31. desyncedFilters: new Set(),
  32. pinnedFilters: new Set(),
  33. shouldPersist: true,
  34. selection: {
  35. datetime: {
  36. period: '10d',
  37. start: null,
  38. end: null,
  39. utc: false,
  40. },
  41. environments: [],
  42. projects: [2],
  43. },
  44. });
  45. render(
  46. <ModulesOnboarding moduleName={ModuleName.CACHE}>
  47. <div>Module Content</div>
  48. </ModulesOnboarding>
  49. );
  50. await screen.getByText('Module Content');
  51. });
  52. it('renders onboarding content correctly', async () => {
  53. const project = ProjectFixture();
  54. jest.mocked(useProjects).mockReturnValue({
  55. projects: [project],
  56. onSearch: jest.fn(),
  57. placeholders: [],
  58. fetching: false,
  59. hasMore: null,
  60. fetchError: null,
  61. initiallyLoaded: false,
  62. });
  63. jest.mocked(usePageFilters).mockReturnValue({
  64. isReady: true,
  65. desyncedFilters: new Set(),
  66. pinnedFilters: new Set(),
  67. shouldPersist: true,
  68. selection: {
  69. datetime: {
  70. period: '10d',
  71. start: null,
  72. end: null,
  73. utc: false,
  74. },
  75. environments: [],
  76. projects: [2],
  77. },
  78. });
  79. render(
  80. <ModulesOnboarding moduleName={ModuleName.CACHE}>
  81. <div>Module Content</div>
  82. </ModulesOnboarding>
  83. );
  84. await screen.findByText('Bringing you one less hard problem in computer science');
  85. });
  86. it('renders performance onboarding if onboardingProject', async () => {
  87. const project = ProjectFixture();
  88. jest.mocked(useOnboardingProject).mockReturnValue(project);
  89. jest.mocked(useProjects).mockReturnValue({
  90. projects: [project],
  91. onSearch: jest.fn(),
  92. placeholders: [],
  93. fetching: false,
  94. hasMore: null,
  95. fetchError: null,
  96. initiallyLoaded: false,
  97. });
  98. jest.mocked(usePageFilters).mockReturnValue({
  99. isReady: true,
  100. desyncedFilters: new Set(),
  101. pinnedFilters: new Set(),
  102. shouldPersist: true,
  103. selection: {
  104. datetime: {
  105. period: '10d',
  106. start: null,
  107. end: null,
  108. utc: false,
  109. },
  110. environments: [],
  111. projects: [2],
  112. },
  113. });
  114. render(
  115. <ModulesOnboarding moduleName={ModuleName.CACHE}>
  116. <div>Module Content</div>
  117. </ModulesOnboarding>
  118. );
  119. await screen.findByText('Pinpoint problems');
  120. });
  121. });