groupSidebar.spec.tsx 7.4 KB

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