groupSidebar.spec.jsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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 = {name: 'production', displayName: 'Production', id: '1'};
  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. });
  62. afterEach(function () {
  63. MockApiClient.clearMockResponses();
  64. });
  65. describe('sidebar', () => {
  66. it('should make a request to the /tags/ endpoint to get top values', async () => {
  67. render(
  68. <GroupSidebar
  69. group={group}
  70. project={project}
  71. organization={organization}
  72. event={TestStubs.Event()}
  73. environments={[environment]}
  74. />,
  75. {organization}
  76. );
  77. expect(await screen.findByText('browser')).toBeInTheDocument();
  78. expect(tagsMock).toHaveBeenCalled();
  79. });
  80. });
  81. describe('renders with tags', function () {
  82. it('renders', async function () {
  83. render(
  84. <GroupSidebar
  85. group={group}
  86. project={project}
  87. organization={organization}
  88. event={TestStubs.Event()}
  89. environments={[environment]}
  90. />,
  91. {organization}
  92. );
  93. expect(await screen.findByText('browser')).toBeInTheDocument();
  94. expect(screen.getByText('device')).toBeInTheDocument();
  95. expect(screen.getByText('url')).toBeInTheDocument();
  96. expect(screen.getByText('environment')).toBeInTheDocument();
  97. expect(screen.getByText('user')).toBeInTheDocument();
  98. });
  99. });
  100. describe('environment toggle', function () {
  101. it('re-requests tags with correct environment', async function () {
  102. const stagingEnv = {name: 'staging', displayName: 'Staging', id: '2'};
  103. const {rerender} = render(
  104. <GroupSidebar
  105. group={group}
  106. project={project}
  107. organization={organization}
  108. event={TestStubs.Event()}
  109. environments={[environment]}
  110. />,
  111. {organization}
  112. );
  113. expect(await screen.findByText('browser')).toBeInTheDocument();
  114. expect(tagsMock).toHaveBeenCalledTimes(1);
  115. rerender(
  116. <GroupSidebar
  117. group={group}
  118. project={project}
  119. organization={organization}
  120. event={TestStubs.Event()}
  121. environments={[stagingEnv]}
  122. />,
  123. {organization}
  124. );
  125. expect(await screen.findByText('browser')).toBeInTheDocument();
  126. expect(tagsMock).toHaveBeenCalledTimes(2);
  127. expect(tagsMock).toHaveBeenCalledWith(
  128. '/issues/1/tags/',
  129. expect.objectContaining({
  130. query: expect.objectContaining({
  131. environment: ['staging'],
  132. }),
  133. })
  134. );
  135. });
  136. });
  137. describe('renders without tags', function () {
  138. beforeEach(function () {
  139. group = TestStubs.Group();
  140. MockApiClient.addMockResponse({
  141. url: '/issues/1/',
  142. body: group,
  143. });
  144. MockApiClient.addMockResponse({
  145. url: '/issues/1/tags/',
  146. body: [],
  147. });
  148. });
  149. it('renders empty text', async function () {
  150. render(
  151. <GroupSidebar
  152. group={group}
  153. project={project}
  154. organization={organization}
  155. event={TestStubs.Event()}
  156. environments={[environment]}
  157. />,
  158. {organization}
  159. );
  160. expect(
  161. await screen.findByText('No tags found in the selected environments')
  162. ).toBeInTheDocument();
  163. });
  164. });
  165. it('renders participants and viewers', async () => {
  166. const users = [
  167. TestStubs.User({
  168. id: '2',
  169. name: 'John Smith',
  170. email: 'johnsmith@example.com',
  171. }),
  172. TestStubs.User({
  173. id: '3',
  174. name: 'Sohn Jmith',
  175. email: 'sohnjmith@example.com',
  176. }),
  177. ];
  178. render(
  179. <GroupSidebar
  180. group={{
  181. ...group,
  182. participants: users,
  183. seenBy: users,
  184. }}
  185. project={project}
  186. organization={organization}
  187. event={TestStubs.Event()}
  188. environments={[]}
  189. />,
  190. {organization}
  191. );
  192. expect(await screen.findByText('Participants (2)')).toBeInTheDocument();
  193. expect(screen.getByText('Viewers (2)')).toBeInTheDocument();
  194. });
  195. describe('displays mobile tags when issue platform is mobile', function () {
  196. beforeEach(function () {
  197. group = TestStubs.Group();
  198. MockApiClient.addMockResponse({
  199. url: '/issues/1/',
  200. body: group,
  201. });
  202. });
  203. it('renders mobile tags on top of tag summary for mobile platforms', async function () {
  204. render(
  205. <GroupSidebar
  206. group={group}
  207. project={{...project, platform: 'react-native'}}
  208. organization={{
  209. ...organization,
  210. features: [...organization.features, 'issue-details-tag-improvements'],
  211. }}
  212. event={TestStubs.Event()}
  213. environments={[environment]}
  214. />,
  215. {organization}
  216. );
  217. await waitFor(() => expect(tagsMock).toHaveBeenCalled());
  218. expect(
  219. within(screen.getByTestId('top-distribution-wrapper')).getByText('device')
  220. ).toBeInTheDocument();
  221. });
  222. it('does not render mobile tags on top of tag summary for non mobile platforms', async function () {
  223. render(
  224. <GroupSidebar
  225. group={group}
  226. project={project}
  227. organization={{
  228. ...organization,
  229. features: [...organization.features, 'issue-details-tag-improvements'],
  230. }}
  231. event={TestStubs.Event()}
  232. environments={[environment]}
  233. />,
  234. {organization}
  235. );
  236. await waitFor(() => expect(tagsMock).toHaveBeenCalled());
  237. expect(
  238. within(screen.getByTestId('top-distribution-wrapper')).queryByText('device')
  239. ).not.toBeInTheDocument();
  240. });
  241. });
  242. });