sidebar.spec.jsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, waitFor} 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/',
  27. body: group,
  28. });
  29. MockApiClient.addMockResponse({
  30. url: '/issues/1/current-release/',
  31. body: {},
  32. });
  33. MockApiClient.addMockResponse({
  34. url: '/groups/1/external-issues/',
  35. body: [],
  36. });
  37. MockApiClient.addMockResponse({
  38. url: `/projects/${organization.slug}/${project.slug}/codeowners/`,
  39. body: [],
  40. });
  41. MockApiClient.addMockResponse({
  42. url: `/prompts-activity/`,
  43. body: {},
  44. });
  45. MockApiClient.addMockResponse({
  46. url: `/organizations/${organization.slug}/code-mappings/`,
  47. query: {project: -1},
  48. method: 'GET',
  49. body: [],
  50. });
  51. tagsMock = MockApiClient.addMockResponse({
  52. url: '/issues/1/tags/',
  53. body: TestStubs.Tags(),
  54. });
  55. });
  56. afterEach(function () {
  57. MockApiClient.clearMockResponses();
  58. });
  59. describe('sidebar', () => {
  60. it('should make a request to the /tags/ endpoint to get top values', async () => {
  61. render(
  62. <GroupSidebar
  63. group={group}
  64. project={project}
  65. organization={organization}
  66. event={TestStubs.Event()}
  67. environments={[environment]}
  68. />,
  69. {organization}
  70. );
  71. expect(await screen.findByText('browser')).toBeInTheDocument();
  72. expect(tagsMock).toHaveBeenCalled();
  73. });
  74. });
  75. describe('renders with tags', function () {
  76. it('renders', async function () {
  77. render(
  78. <GroupSidebar
  79. group={group}
  80. project={project}
  81. organization={organization}
  82. event={TestStubs.Event()}
  83. environments={[environment]}
  84. />,
  85. {organization}
  86. );
  87. expect(await screen.findByText('browser')).toBeInTheDocument();
  88. expect(screen.getByText('device')).toBeInTheDocument();
  89. expect(screen.getByText('url')).toBeInTheDocument();
  90. expect(screen.getByText('environment')).toBeInTheDocument();
  91. expect(screen.getByText('user')).toBeInTheDocument();
  92. });
  93. });
  94. describe('environment toggle', function () {
  95. it('re-requests tags with correct environment', async function () {
  96. const stagingEnv = {name: 'staging', displayName: 'Staging', id: '2'};
  97. const {rerender} = render(
  98. <GroupSidebar
  99. group={group}
  100. project={project}
  101. organization={organization}
  102. event={TestStubs.Event()}
  103. environments={[environment]}
  104. />,
  105. {organization}
  106. );
  107. expect(await screen.findByText('browser')).toBeInTheDocument();
  108. expect(tagsMock).toHaveBeenCalledTimes(1);
  109. rerender(
  110. <GroupSidebar
  111. group={group}
  112. project={project}
  113. organization={organization}
  114. event={TestStubs.Event()}
  115. environments={[stagingEnv]}
  116. />,
  117. {organization}
  118. );
  119. expect(tagsMock).toHaveBeenCalledTimes(2);
  120. expect(tagsMock).toHaveBeenCalledWith(
  121. '/issues/1/tags/',
  122. expect.objectContaining({
  123. query: expect.objectContaining({
  124. environment: ['staging'],
  125. }),
  126. })
  127. );
  128. });
  129. });
  130. describe('renders without tags', function () {
  131. beforeEach(function () {
  132. group = TestStubs.Group();
  133. MockApiClient.addMockResponse({
  134. url: '/issues/1/',
  135. body: group,
  136. });
  137. MockApiClient.addMockResponse({
  138. url: '/issues/1/tags/',
  139. body: [],
  140. });
  141. });
  142. it('renders empty text', async function () {
  143. render(
  144. <GroupSidebar
  145. group={group}
  146. project={project}
  147. organization={organization}
  148. event={TestStubs.Event()}
  149. environments={[environment]}
  150. />,
  151. {organization}
  152. );
  153. expect(
  154. await screen.findByText('No tags found in the selected environments')
  155. ).toBeInTheDocument();
  156. });
  157. });
  158. it('renders participants and viewers', () => {
  159. const users = [
  160. TestStubs.User({
  161. id: '2',
  162. name: 'John Smith',
  163. email: 'johnsmith@example.com',
  164. }),
  165. TestStubs.User({
  166. id: '3',
  167. name: 'Sohn Jmith',
  168. email: 'sohnjmith@example.com',
  169. }),
  170. ];
  171. const org = {...organization, features: ['issue-actions-v2']};
  172. render(
  173. <GroupSidebar
  174. group={{
  175. ...group,
  176. participants: users,
  177. seenBy: users,
  178. }}
  179. project={project}
  180. organization={org}
  181. event={TestStubs.Event()}
  182. environments={[]}
  183. />,
  184. {organization: org}
  185. );
  186. expect(screen.getByText('Participants (2)')).toBeInTheDocument();
  187. expect(screen.getByText('Viewers (2)')).toBeInTheDocument();
  188. });
  189. describe('displays mobile tags when issue platform is mobile', function () {
  190. beforeEach(function () {
  191. group = TestStubs.Group();
  192. MockApiClient.addMockResponse({
  193. url: '/issues/1/',
  194. body: group,
  195. });
  196. });
  197. it('renders mobile tags on mobile platform', async function () {
  198. render(
  199. <GroupSidebar
  200. group={group}
  201. project={{...project, platform: 'android'}}
  202. organization={{
  203. ...organization,
  204. features: [...organization.features, 'issue-details-tag-improvements'],
  205. }}
  206. event={TestStubs.Event()}
  207. environments={[environment]}
  208. />,
  209. {organization}
  210. );
  211. expect(await screen.findByText('device')).toBeInTheDocument();
  212. });
  213. it('does not render mobile tags on non mobile platform', async function () {
  214. render(
  215. <GroupSidebar
  216. group={group}
  217. project={project}
  218. organization={{
  219. ...organization,
  220. features: [...organization.features, 'issue-details-tag-improvements'],
  221. }}
  222. event={TestStubs.Event()}
  223. environments={[environment]}
  224. />,
  225. {organization}
  226. );
  227. await waitFor(() => expect(tagsMock).toHaveBeenCalled());
  228. expect(screen.queryByText('device')).not.toBeInTheDocument();
  229. });
  230. });
  231. });