sidebar.spec.jsx 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import GroupSidebar from 'sentry/components/group/sidebar';
  4. describe('GroupSidebar', function () {
  5. let group = TestStubs.Group({tags: TestStubs.Tags()});
  6. const {organization, project} = initializeOrg();
  7. const environment = {name: 'production', displayName: 'Production', id: '1'};
  8. let tagsMock;
  9. beforeEach(function () {
  10. MockApiClient.addMockResponse({
  11. url: '/projects/org-slug/project-slug/events/1/committers/',
  12. body: {committers: []},
  13. });
  14. MockApiClient.addMockResponse({
  15. url: '/projects/org-slug/project-slug/events/1/owners/',
  16. body: {
  17. owners: [],
  18. rules: [],
  19. },
  20. });
  21. MockApiClient.addMockResponse({
  22. url: '/groups/1/integrations/',
  23. body: [],
  24. });
  25. MockApiClient.addMockResponse({
  26. url: '/issues/1/participants/',
  27. body: [],
  28. });
  29. MockApiClient.addMockResponse({
  30. url: '/issues/1/',
  31. body: group,
  32. });
  33. MockApiClient.addMockResponse({
  34. url: '/issues/1/current-release/',
  35. body: {},
  36. });
  37. MockApiClient.addMockResponse({
  38. url: '/groups/1/external-issues/',
  39. body: [],
  40. });
  41. MockApiClient.addMockResponse({
  42. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  43. body: [],
  44. });
  45. MockApiClient.addMockResponse({
  46. url: `/prompts-activity/`,
  47. body: {},
  48. });
  49. MockApiClient.addMockResponse({
  50. url: `/organizations/${organization.slug}/code-mappings/`,
  51. query: {project: -1},
  52. method: 'GET',
  53. body: [],
  54. });
  55. tagsMock = MockApiClient.addMockResponse({
  56. url: '/issues/1/tags/',
  57. body: TestStubs.Tags(),
  58. });
  59. });
  60. afterEach(function () {
  61. MockApiClient.clearMockResponses();
  62. });
  63. describe('sidebar', () => {
  64. it('should make a request to the /tags/ endpoint to get top values', async () => {
  65. render(
  66. <GroupSidebar
  67. group={group}
  68. project={project}
  69. organization={organization}
  70. event={TestStubs.Event()}
  71. environments={[environment]}
  72. />,
  73. {organization}
  74. );
  75. expect(await screen.findByText('browser')).toBeInTheDocument();
  76. expect(tagsMock).toHaveBeenCalled();
  77. });
  78. });
  79. describe('renders with tags', function () {
  80. it('renders', async function () {
  81. render(
  82. <GroupSidebar
  83. group={group}
  84. project={project}
  85. organization={organization}
  86. event={TestStubs.Event()}
  87. environments={[environment]}
  88. />,
  89. {organization}
  90. );
  91. expect(await screen.findByText('browser')).toBeInTheDocument();
  92. expect(await screen.getByText('device')).toBeInTheDocument();
  93. expect(await screen.getByText('url')).toBeInTheDocument();
  94. expect(await screen.getByText('environment')).toBeInTheDocument();
  95. expect(await screen.getByText('user')).toBeInTheDocument();
  96. });
  97. });
  98. describe('environment toggle', function () {
  99. it('re-requests tags with correct environment', async function () {
  100. const stagingEnv = {name: 'staging', displayName: 'Staging', id: '2'};
  101. const {rerender} = render(
  102. <GroupSidebar
  103. group={group}
  104. project={project}
  105. organization={organization}
  106. event={TestStubs.Event()}
  107. environments={[environment]}
  108. />,
  109. {organization}
  110. );
  111. expect(await screen.findByText('browser')).toBeInTheDocument();
  112. expect(tagsMock).toHaveBeenCalledTimes(1);
  113. rerender(
  114. <GroupSidebar
  115. group={group}
  116. project={project}
  117. organization={organization}
  118. event={TestStubs.Event()}
  119. environments={[stagingEnv]}
  120. />,
  121. {organization}
  122. );
  123. expect(tagsMock).toHaveBeenCalledTimes(2);
  124. expect(tagsMock).toHaveBeenCalledWith(
  125. '/issues/1/tags/',
  126. expect.objectContaining({
  127. query: expect.objectContaining({
  128. environment: ['staging'],
  129. }),
  130. })
  131. );
  132. });
  133. });
  134. describe('renders without tags', function () {
  135. beforeEach(function () {
  136. group = TestStubs.Group();
  137. MockApiClient.addMockResponse({
  138. url: '/issues/1/',
  139. body: group,
  140. });
  141. MockApiClient.addMockResponse({
  142. url: '/issues/1/tags/',
  143. body: [],
  144. });
  145. });
  146. it('renders empty text', async function () {
  147. render(
  148. <GroupSidebar
  149. group={group}
  150. project={project}
  151. organization={organization}
  152. event={TestStubs.Event()}
  153. environments={[environment]}
  154. />,
  155. {organization}
  156. );
  157. expect(
  158. await screen.findByText('No tags found in the selected environments')
  159. ).toBeInTheDocument();
  160. });
  161. });
  162. });