usePerformanceOnboardingDocs.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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}) => (
  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(project),
  40. {
  41. wrapper,
  42. }
  43. );
  44. await waitForNextUpdate();
  45. const {docContents, isLoading, hasOnboardingContents} = result.current;
  46. expect(isLoading).toEqual(false);
  47. const expectedDocContents = Object.keys(apiMocks).reduce((acc, key) => {
  48. acc[key] = `${key} content`;
  49. return acc;
  50. }, {});
  51. expect(docContents).toEqual(expectedDocContents);
  52. expect(hasOnboardingContents).toEqual(true);
  53. Object.values(apiMocks).forEach(mock => {
  54. expect(mock).toHaveBeenCalled();
  55. });
  56. });
  57. it('project with no onboarding support', function () {
  58. const {organization} = initializeOrg({
  59. router: {
  60. location: {query: {}, search: ''},
  61. push: jest.fn(),
  62. },
  63. } as any);
  64. const wrapper = ({children}) => (
  65. <OrganizationContext.Provider value={organization}>
  66. {children}
  67. </OrganizationContext.Provider>
  68. );
  69. const project = TestStubs.Project({
  70. platform: 'javascript-angular',
  71. firstTransactionEvent: false,
  72. });
  73. const apiMocks: any = {};
  74. const docKeys = generateOnboardingDocKeys(project.platform);
  75. expect(docKeys).toEqual([
  76. 'javascript-angular-performance-onboarding-1-install',
  77. 'javascript-angular-performance-onboarding-2-configure',
  78. 'javascript-angular-performance-onboarding-3-verify',
  79. ]);
  80. docKeys.forEach(docKey => {
  81. apiMocks[docKey] = MockApiClient.addMockResponse({
  82. url: `/projects/${organization.slug}/${project.slug}/docs/${docKey}/`,
  83. method: 'GET',
  84. body: {html: `${docKey} content`},
  85. });
  86. });
  87. const {result} = reactHooks.renderHook(() => usePerformanceOnboardingDocs(project), {
  88. wrapper,
  89. });
  90. const {docContents, isLoading, hasOnboardingContents} = result.current;
  91. expect(isLoading).toEqual(false);
  92. expect(docContents).toEqual({});
  93. expect(hasOnboardingContents).toEqual(false);
  94. Object.values(apiMocks).forEach(mock => {
  95. expect(mock).not.toHaveBeenCalled();
  96. });
  97. });
  98. it('project with no performance support', function () {
  99. const {organization} = initializeOrg({
  100. router: {
  101. location: {query: {}, search: ''},
  102. push: jest.fn(),
  103. },
  104. } as any);
  105. const wrapper = ({children}) => (
  106. <OrganizationContext.Provider value={organization}>
  107. {children}
  108. </OrganizationContext.Provider>
  109. );
  110. const project = TestStubs.Project({
  111. platform: 'elixir',
  112. firstTransactionEvent: false,
  113. });
  114. const apiMocks: any = {};
  115. const docKeys = generateOnboardingDocKeys(project.platform);
  116. expect(docKeys).toEqual([
  117. 'elixir-performance-onboarding-1-install',
  118. 'elixir-performance-onboarding-2-configure',
  119. 'elixir-performance-onboarding-3-verify',
  120. ]);
  121. docKeys.forEach(docKey => {
  122. apiMocks[docKey] = MockApiClient.addMockResponse({
  123. url: `/projects/${organization.slug}/${project.slug}/docs/${docKey}/`,
  124. method: 'GET',
  125. body: {html: `${docKey} content`},
  126. });
  127. });
  128. const {result} = reactHooks.renderHook(() => usePerformanceOnboardingDocs(project), {
  129. wrapper,
  130. });
  131. const {docContents, isLoading, hasOnboardingContents} = result.current;
  132. expect(isLoading).toEqual(false);
  133. expect(docContents).toEqual({});
  134. expect(hasOnboardingContents).toEqual(false);
  135. Object.values(apiMocks).forEach(mock => {
  136. expect(mock).not.toHaveBeenCalled();
  137. });
  138. });
  139. });