sidebar.spec.jsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import {Event} from 'fixtures/js-stubs/event';
  2. import {Group} from 'fixtures/js-stubs/group';
  3. import {Tags} from 'fixtures/js-stubs/tags';
  4. import {User} from 'fixtures/js-stubs/user';
  5. import {initializeOrg} from 'sentry-test/initializeOrg';
  6. import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';
  7. import GroupSidebar from 'sentry/components/group/sidebar';
  8. describe('GroupSidebar', function () {
  9. let group = Group({tags: Tags()});
  10. const {organization, project} = initializeOrg();
  11. const environment = {name: 'production', displayName: 'Production', id: '1'};
  12. let tagsMock;
  13. beforeEach(function () {
  14. MockApiClient.addMockResponse({
  15. url: '/projects/org-slug/project-slug/events/1/committers/',
  16. body: {committers: []},
  17. });
  18. MockApiClient.addMockResponse({
  19. url: '/projects/org-slug/project-slug/events/1/owners/',
  20. body: {
  21. owners: [],
  22. rules: [],
  23. },
  24. });
  25. MockApiClient.addMockResponse({
  26. url: '/groups/1/integrations/',
  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: 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={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={Event()}
  87. environments={[environment]}
  88. />,
  89. {organization}
  90. );
  91. expect(await screen.findByText('browser')).toBeInTheDocument();
  92. expect(screen.getByText('device')).toBeInTheDocument();
  93. expect(screen.getByText('url')).toBeInTheDocument();
  94. expect(screen.getByText('environment')).toBeInTheDocument();
  95. expect(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={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={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 = 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={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. it('renders participants and viewers', () => {
  163. const users = [
  164. User({
  165. id: '2',
  166. name: 'John Smith',
  167. email: 'johnsmith@example.com',
  168. }),
  169. User({
  170. id: '3',
  171. name: 'Sohn Jmith',
  172. email: 'sohnjmith@example.com',
  173. }),
  174. ];
  175. const org = {...organization, features: ['issue-actions-v2']};
  176. render(
  177. <GroupSidebar
  178. group={{
  179. ...group,
  180. participants: users,
  181. seenBy: users,
  182. }}
  183. project={project}
  184. organization={org}
  185. event={Event()}
  186. environments={[]}
  187. />,
  188. {organization: org}
  189. );
  190. expect(screen.getByText('Participants (2)')).toBeInTheDocument();
  191. expect(screen.getByText('Viewers (2)')).toBeInTheDocument();
  192. });
  193. describe('displays mobile tags when issue platform is mobile', function () {
  194. beforeEach(function () {
  195. group = Group();
  196. MockApiClient.addMockResponse({
  197. url: '/issues/1/',
  198. body: group,
  199. });
  200. });
  201. it('renders mobile tags on mobile platform', async function () {
  202. render(
  203. <GroupSidebar
  204. group={group}
  205. project={{...project, platform: 'android'}}
  206. organization={{
  207. ...organization,
  208. features: [...organization.features, 'issue-details-tag-improvements'],
  209. }}
  210. event={Event()}
  211. environments={[environment]}
  212. />,
  213. {organization}
  214. );
  215. expect(await screen.findByText('device')).toBeInTheDocument();
  216. });
  217. it('does not render mobile tags on non mobile platform', async function () {
  218. render(
  219. <GroupSidebar
  220. group={group}
  221. project={project}
  222. organization={{
  223. ...organization,
  224. features: [...organization.features, 'issue-details-tag-improvements'],
  225. }}
  226. event={Event()}
  227. environments={[environment]}
  228. />,
  229. {organization}
  230. );
  231. await waitFor(() => expect(tagsMock).toHaveBeenCalled());
  232. expect(screen.queryByText('device')).not.toBeInTheDocument();
  233. });
  234. });
  235. });