groupSidebar.spec.jsx 7.3 KB

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