groupSidebar.spec.tsx 7.4 KB

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