groupSidebar.spec.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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';
  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. });
  77. afterEach(function () {
  78. MockApiClient.clearMockResponses();
  79. });
  80. describe('sidebar', () => {
  81. it('should make a request to the /tags/ endpoint to get top values', async () => {
  82. render(
  83. <GroupSidebar
  84. group={group}
  85. project={project}
  86. organization={organization}
  87. event={EventFixture()}
  88. environments={[environment]}
  89. />
  90. );
  91. expect(await screen.findByText('browser')).toBeInTheDocument();
  92. expect(tagsMock).toHaveBeenCalled();
  93. });
  94. });
  95. describe('renders with tags', function () {
  96. it('renders', async function () {
  97. render(
  98. <GroupSidebar
  99. group={group}
  100. project={project}
  101. organization={organization}
  102. event={EventFixture()}
  103. environments={[environment]}
  104. />
  105. );
  106. expect(await screen.findByText('browser')).toBeInTheDocument();
  107. expect(screen.getByText('device')).toBeInTheDocument();
  108. expect(screen.getByText('url')).toBeInTheDocument();
  109. expect(screen.getByText('environment')).toBeInTheDocument();
  110. expect(screen.getByText('user')).toBeInTheDocument();
  111. });
  112. });
  113. describe('environment toggle', function () {
  114. it('re-requests tags with correct environment', async function () {
  115. const stagingEnv = 'staging';
  116. const {rerender} = render(
  117. <GroupSidebar
  118. group={group}
  119. project={project}
  120. organization={organization}
  121. event={EventFixture()}
  122. environments={[environment]}
  123. />
  124. );
  125. expect(await screen.findByText('browser')).toBeInTheDocument();
  126. expect(tagsMock).toHaveBeenCalledTimes(1);
  127. rerender(
  128. <GroupSidebar
  129. group={group}
  130. project={project}
  131. organization={organization}
  132. event={EventFixture()}
  133. environments={[stagingEnv]}
  134. />
  135. );
  136. expect(await screen.findByText('browser')).toBeInTheDocument();
  137. expect(tagsMock).toHaveBeenCalledTimes(2);
  138. expect(tagsMock).toHaveBeenCalledWith(
  139. '/organizations/org-slug/issues/1/tags/',
  140. expect.objectContaining({
  141. query: expect.objectContaining({
  142. environment: ['staging'],
  143. }),
  144. })
  145. );
  146. });
  147. });
  148. describe('renders without tags', function () {
  149. beforeEach(function () {
  150. group = GroupFixture();
  151. MockApiClient.addMockResponse({
  152. url: '/organization/org-slug/issues/1/',
  153. body: group,
  154. });
  155. MockApiClient.addMockResponse({
  156. url: '/organizations/org-slug/issues/1/tags/',
  157. body: [],
  158. });
  159. });
  160. it('renders empty text', async function () {
  161. render(
  162. <GroupSidebar
  163. group={group}
  164. project={project}
  165. organization={organization}
  166. event={EventFixture()}
  167. environments={[environment]}
  168. />
  169. );
  170. expect(
  171. await screen.findByText('No tags found in the selected environments')
  172. ).toBeInTheDocument();
  173. });
  174. });
  175. it('expands participants and viewers', async () => {
  176. const org = {
  177. ...organization,
  178. };
  179. const teams: TeamParticipant[] = [{...TeamFixture(), type: 'team'}];
  180. const users: UserParticipant[] = [
  181. {
  182. ...UserFixture({
  183. id: '2',
  184. name: 'John Smith',
  185. email: 'johnsmith@example.com',
  186. }),
  187. type: 'user',
  188. },
  189. {
  190. ...UserFixture({
  191. id: '3',
  192. name: 'Sohn Jmith',
  193. email: 'sohnjmith@example.com',
  194. }),
  195. type: 'user',
  196. },
  197. ];
  198. render(
  199. <GroupSidebar
  200. group={{
  201. ...group,
  202. participants: [...teams, ...users],
  203. seenBy: users,
  204. }}
  205. project={project}
  206. organization={org}
  207. event={EventFixture()}
  208. environments={[]}
  209. />,
  210. {
  211. organization: org,
  212. }
  213. );
  214. expect(
  215. await screen.findByRole('heading', {name: 'Participants (1 Team, 2 Individuals)'})
  216. ).toBeInTheDocument();
  217. expect(screen.queryByText('#team-slug')).not.toBeInTheDocument();
  218. await userEvent.click(
  219. screen.getAllByRole('button', {name: 'Expand Participants'})[0]
  220. );
  221. await waitFor(() => expect(screen.getByText('#team-slug')).toBeVisible());
  222. });
  223. describe('displays mobile tags when issue platform is mobile', function () {
  224. beforeEach(function () {
  225. group = GroupFixture();
  226. MockApiClient.addMockResponse({
  227. url: '/issues/1/',
  228. body: group,
  229. });
  230. });
  231. it('renders mobile tags on top of tag summary for mobile platforms', async function () {
  232. render(
  233. <GroupSidebar
  234. group={group}
  235. project={{...project, platform: 'react-native'}}
  236. organization={{
  237. ...organization,
  238. features: [...organization.features, 'issue-details-tag-improvements'],
  239. }}
  240. event={EventFixture()}
  241. environments={[environment]}
  242. />
  243. );
  244. await waitFor(() => expect(tagsMock).toHaveBeenCalled());
  245. expect(
  246. within(await screen.findByTestId('top-distribution-wrapper')).getByText('device')
  247. ).toBeInTheDocument();
  248. });
  249. it('does not render mobile tags on top of tag summary for non mobile platforms', async function () {
  250. render(
  251. <GroupSidebar
  252. group={group}
  253. project={project}
  254. organization={{
  255. ...organization,
  256. features: [...organization.features, 'issue-details-tag-improvements'],
  257. }}
  258. event={EventFixture()}
  259. environments={[environment]}
  260. />
  261. );
  262. await waitFor(() => expect(tagsMock).toHaveBeenCalled());
  263. expect(
  264. within(await screen.findByTestId('top-distribution-wrapper')).queryByText(
  265. 'device'
  266. )
  267. ).not.toBeInTheDocument();
  268. });
  269. });
  270. });