usePerformanceOnboardingDocs.spec.tsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {reactHooks} from 'sentry-test/reactTestingLibrary';
  3. import usePerformanceOnboardingDocs, {
  4. generateOnboardingDocKeys,
  5. } from 'sentry/components/performanceOnboarding/usePerformanceOnboardingDocs';
  6. import {OrganizationContext} from 'sentry/views/organizationContext';
  7. describe('usePerformanceOnboardingDocs', function () {
  8. it('fetches onboarding documentation steps', async function () {
  9. const {organization} = initializeOrg({
  10. router: {
  11. location: {query: {}, search: ''},
  12. push: jest.fn(),
  13. },
  14. } as any);
  15. const wrapper = ({children}: {children?: React.ReactNode}) => (
  16. <OrganizationContext.Provider value={organization}>
  17. {children}
  18. </OrganizationContext.Provider>
  19. );
  20. const project = TestStubs.Project({
  21. platform: 'javascript-react',
  22. firstTransactionEvent: false,
  23. });
  24. const apiMocks: any = {};
  25. const docKeys = generateOnboardingDocKeys(project.platform);
  26. expect(docKeys).toEqual([
  27. 'javascript-react-performance-onboarding-1-install',
  28. 'javascript-react-performance-onboarding-2-configure',
  29. 'javascript-react-performance-onboarding-3-verify',
  30. ]);
  31. docKeys.forEach(docKey => {
  32. apiMocks[docKey] = MockApiClient.addMockResponse({
  33. url: `/projects/${organization.slug}/${project.slug}/docs/${docKey}/`,
  34. method: 'GET',
  35. body: {html: `${docKey} content`},
  36. });
  37. });
  38. const {result, waitForNextUpdate} = reactHooks.renderHook(
  39. usePerformanceOnboardingDocs,
  40. {
  41. initialProps: project,
  42. wrapper,
  43. }
  44. );
  45. await waitForNextUpdate();
  46. const {docContents, isLoading, hasOnboardingContents} = result.current;
  47. expect(isLoading).toEqual(false);
  48. const expectedDocContents = Object.keys(apiMocks).reduce((acc, key) => {
  49. acc[key] = `${key} content`;
  50. return acc;
  51. }, {});
  52. expect(docContents).toEqual(expectedDocContents);
  53. expect(hasOnboardingContents).toEqual(true);
  54. Object.values(apiMocks).forEach(mock => {
  55. expect(mock).toHaveBeenCalled();
  56. });
  57. });
  58. it('project with no onboarding support', function () {
  59. const {organization} = initializeOrg({
  60. router: {
  61. location: {query: {}, search: ''},
  62. push: jest.fn(),
  63. },
  64. } as any);
  65. const wrapper = ({children}: {children?: React.ReactNode}) => (
  66. <OrganizationContext.Provider value={organization}>
  67. {children}
  68. </OrganizationContext.Provider>
  69. );
  70. const project = TestStubs.Project({
  71. platform: 'javascript-angular',
  72. firstTransactionEvent: false,
  73. });
  74. const apiMocks: any = {};
  75. const docKeys = generateOnboardingDocKeys(project.platform);
  76. expect(docKeys).toEqual([
  77. 'javascript-angular-performance-onboarding-1-install',
  78. 'javascript-angular-performance-onboarding-2-configure',
  79. 'javascript-angular-performance-onboarding-3-verify',
  80. ]);
  81. docKeys.forEach(docKey => {
  82. apiMocks[docKey] = MockApiClient.addMockResponse({
  83. url: `/projects/${organization.slug}/${project.slug}/docs/${docKey}/`,
  84. method: 'GET',
  85. body: {html: `${docKey} content`},
  86. });
  87. });
  88. const {result} = reactHooks.renderHook(usePerformanceOnboardingDocs, {
  89. wrapper,
  90. initialProps: project,
  91. });
  92. const {docContents, isLoading, hasOnboardingContents} = result.current;
  93. expect(isLoading).toEqual(false);
  94. expect(docContents).toEqual({});
  95. expect(hasOnboardingContents).toEqual(false);
  96. Object.values(apiMocks).forEach(mock => {
  97. expect(mock).not.toHaveBeenCalled();
  98. });
  99. });
  100. it('project with no performance support', function () {
  101. const {organization} = initializeOrg({
  102. router: {
  103. location: {query: {}, search: ''},
  104. push: jest.fn(),
  105. },
  106. } as any);
  107. const wrapper = ({children}: {children?: React.ReactNode}) => (
  108. <OrganizationContext.Provider value={organization}>
  109. {children}
  110. </OrganizationContext.Provider>
  111. );
  112. const project = TestStubs.Project({
  113. platform: 'elixir',
  114. firstTransactionEvent: false,
  115. });
  116. const apiMocks: any = {};
  117. const docKeys = generateOnboardingDocKeys(project.platform);
  118. expect(docKeys).toEqual([
  119. 'elixir-performance-onboarding-1-install',
  120. 'elixir-performance-onboarding-2-configure',
  121. 'elixir-performance-onboarding-3-verify',
  122. ]);
  123. docKeys.forEach(docKey => {
  124. apiMocks[docKey] = MockApiClient.addMockResponse({
  125. url: `/projects/${organization.slug}/${project.slug}/docs/${docKey}/`,
  126. method: 'GET',
  127. body: {html: `${docKey} content`},
  128. });
  129. });
  130. const {result} = reactHooks.renderHook(usePerformanceOnboardingDocs, {
  131. wrapper,
  132. initialProps: project,
  133. });
  134. const {docContents, isLoading, hasOnboardingContents} = result.current;
  135. expect(isLoading).toEqual(false);
  136. expect(docContents).toEqual({});
  137. expect(hasOnboardingContents).toEqual(false);
  138. Object.values(apiMocks).forEach(mock => {
  139. expect(mock).not.toHaveBeenCalled();
  140. });
  141. });
  142. });