groupSidebar.spec.tsx 8.2 KB

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