modulesOnboarding.spec.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 {ModuleName} from 'sentry/views/insights/types';
  6. import {ModulesOnboarding} from './modulesOnboarding';
  7. jest.mock('sentry/utils/useProjects');
  8. jest.mock('sentry/utils/usePageFilters');
  9. describe('ModulesOnboarding', () => {
  10. afterEach(() => {
  11. jest.resetAllMocks();
  12. });
  13. it('renders children correctly', async () => {
  14. const project = ProjectFixture();
  15. project.firstTransactionEvent = true;
  16. project.hasInsightsCaches = true;
  17. jest.mocked(useProjects).mockReturnValue({
  18. projects: [project],
  19. onSearch: jest.fn(),
  20. placeholders: [],
  21. fetching: false,
  22. hasMore: null,
  23. fetchError: null,
  24. initiallyLoaded: false,
  25. });
  26. jest.mocked(usePageFilters).mockReturnValue({
  27. isReady: true,
  28. desyncedFilters: new Set(),
  29. pinnedFilters: new Set(),
  30. shouldPersist: true,
  31. selection: {
  32. datetime: {
  33. period: '10d',
  34. start: null,
  35. end: null,
  36. utc: false,
  37. },
  38. environments: [],
  39. projects: [2],
  40. },
  41. });
  42. render(
  43. <ModulesOnboarding
  44. moduleName={ModuleName.CACHE}
  45. onboardingContent={<div>Start collecting Insights!</div>}
  46. >
  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
  81. moduleName={ModuleName.CACHE}
  82. onboardingContent={<div>Start collecting Insights!</div>}
  83. >
  84. <div>Module Content</div>
  85. </ModulesOnboarding>
  86. );
  87. await screen.findByText('Start collecting Insights!');
  88. });
  89. });