groupSidebar.spec.tsx 8.0 KB

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