groupSidebar.spec.tsx 7.9 KB

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