groupSidebar.spec.tsx 7.9 KB

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