quickContext.spec.tsx 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. import {QueryClient, QueryClientProvider} from '@tanstack/react-query';
  2. import {
  3. render,
  4. screen,
  5. userEvent,
  6. waitFor,
  7. within,
  8. } from 'sentry-test/reactTestingLibrary';
  9. import ConfigStore from 'sentry/stores/configStore';
  10. import {Commit, Repository, User} from 'sentry/types';
  11. import {EventData} from 'sentry/utils/discover/eventView';
  12. import {ContextType, QuickContextHoverWrapper} from './quickContext';
  13. const defaultRow: EventData = {
  14. id: '6b43e285de834ec5b5fe30d62d549b20',
  15. issue: 'SENTRY-VVY',
  16. release: 'backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76',
  17. title: 'error: Error -3 while decompressing data: invalid stored block lengths',
  18. 'issue.id': 3512441874,
  19. 'project.name': 'sentry',
  20. };
  21. let mockedGroup = TestStubs.Group({
  22. id: '3512441874',
  23. project: {
  24. id: '1',
  25. slug: 'cool-team',
  26. },
  27. status: 'ignored',
  28. assignedTo: {
  29. id: '12312',
  30. name: 'ingest',
  31. type: 'team',
  32. },
  33. });
  34. const mockedCommit: Commit = {
  35. dateCreated: '2020-11-30T18:46:31Z',
  36. id: 'f7f395d14b2fe29a4e253bf1d3094d61e6ad4434',
  37. message: 'ref(commitRow): refactor to fc\n',
  38. author: {
  39. id: '0',
  40. username: 'author',
  41. ip_address: '192.168.1.1',
  42. email: 'author@commit.com',
  43. name: 'Author',
  44. } as User,
  45. repository: {
  46. id: '1',
  47. integrationId: '2',
  48. name: 'getsentry/sentry',
  49. dateCreated: '2019-11-30T18:46:31Z',
  50. } as Repository,
  51. releases: [],
  52. };
  53. const mockedUser1 = {
  54. id: '2',
  55. username: 'author456',
  56. ip_address: '192.168.1.1',
  57. email: 'author1@commit.com',
  58. name: 'Key Name',
  59. } as User;
  60. const mockedUser2 = {
  61. id: '3',
  62. username: 'author123',
  63. ip_address: '192.168.1.3',
  64. email: 'author2@commit.com',
  65. name: 'Value Name',
  66. } as User;
  67. const mockedReleaseWithHealth = TestStubs.Release({
  68. id: '1',
  69. shortVersion: 'sentry-android-shop@1.2.0',
  70. version: 'sentry-android-shop@1.2.0',
  71. dateCreated: '2010-05-17T02:41:20Z',
  72. lastEvent: '2011-10-17T02:41:20Z',
  73. firstEvent: '2010-05-17T02:41:20Z',
  74. status: 'open',
  75. commitCount: 4,
  76. lastCommit: mockedCommit,
  77. newGroups: 21,
  78. authors: [mockedUser1, mockedUser2],
  79. });
  80. const queryClient = new QueryClient();
  81. const renderQuickContextContent = (
  82. dataRow: EventData = defaultRow,
  83. contextType: ContextType = ContextType.ISSUE
  84. ) => {
  85. const organization = TestStubs.Organization();
  86. render(
  87. <QueryClientProvider client={queryClient}>
  88. <QuickContextHoverWrapper
  89. dataRow={dataRow}
  90. contextType={contextType}
  91. organization={organization}
  92. >
  93. Text from Child
  94. </QuickContextHoverWrapper>
  95. </QueryClientProvider>,
  96. {organization}
  97. );
  98. };
  99. describe('Quick Context', function () {
  100. describe('Quick Context default behaviour', function () {
  101. afterEach(() => {
  102. queryClient.clear();
  103. MockApiClient.clearMockResponses();
  104. });
  105. it('Renders child and trigger icon.', async () => {
  106. renderQuickContextContent();
  107. expect(await screen.findByText(/Text from Child/i)).toBeInTheDocument();
  108. expect(screen.getByTestId('quick-context-hover-trigger')).toBeInTheDocument();
  109. });
  110. it('Renders quick context hover body', async () => {
  111. MockApiClient.addMockResponse({
  112. url: '/organizations/org-slug/users/',
  113. body: [],
  114. });
  115. MockApiClient.addMockResponse({
  116. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  117. body: [],
  118. });
  119. MockApiClient.addMockResponse({
  120. url: '/issues/3512441874/',
  121. method: 'GET',
  122. body: mockedGroup,
  123. });
  124. renderQuickContextContent();
  125. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  126. expect(await screen.findByTestId('quick-context-hover-body')).toBeInTheDocument();
  127. });
  128. it('Renders quick context failure message', async () => {
  129. MockApiClient.addMockResponse({
  130. url: '/organizations/org-slug/users/',
  131. body: [],
  132. });
  133. MockApiClient.addMockResponse({
  134. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  135. body: [],
  136. });
  137. MockApiClient.addMockResponse({
  138. url: '/issues/3512441874/',
  139. statusCode: 400,
  140. });
  141. renderQuickContextContent();
  142. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  143. // Error is expected, do not fail when calling console.error
  144. jest.spyOn(console, 'error').mockImplementation();
  145. expect(
  146. await screen.findByText(/Failed to load context for column./i)
  147. ).toBeInTheDocument();
  148. });
  149. });
  150. describe('Quick Context Content Issue Column', function () {
  151. beforeEach(() => {
  152. MockApiClient.addMockResponse({
  153. url: '/organizations/org-slug/users/',
  154. body: [],
  155. });
  156. MockApiClient.addMockResponse({
  157. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  158. body: [],
  159. });
  160. });
  161. afterEach(function () {
  162. queryClient.clear();
  163. MockApiClient.clearMockResponses();
  164. });
  165. it('Renders ignored Issue status context when data is loaded', async () => {
  166. MockApiClient.addMockResponse({
  167. url: '/issues/3512441874/',
  168. method: 'GET',
  169. body: mockedGroup,
  170. });
  171. renderQuickContextContent();
  172. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  173. expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
  174. expect(screen.getByText(/Ignored/i)).toBeInTheDocument();
  175. expect(screen.getByTestId('quick-context-ignored-icon')).toBeInTheDocument();
  176. });
  177. it('Renders resolved Issue status context when data is loaded', async () => {
  178. mockedGroup = {...mockedGroup, status: 'resolved'};
  179. MockApiClient.addMockResponse({
  180. url: '/issues/3512441874/',
  181. method: 'GET',
  182. body: mockedGroup,
  183. });
  184. renderQuickContextContent();
  185. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  186. expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
  187. expect(screen.getByText(/Resolved/i)).toBeInTheDocument();
  188. expect(screen.getByTestId('icon-check-mark')).toBeInTheDocument();
  189. });
  190. it('Renders unresolved Issue status context when data is loaded', async () => {
  191. mockedGroup = {...mockedGroup, status: 'unresolved'};
  192. MockApiClient.addMockResponse({
  193. url: '/issues/3512441874/',
  194. method: 'GET',
  195. body: mockedGroup,
  196. });
  197. renderQuickContextContent();
  198. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  199. expect(await screen.findByText(/Issue Status/i)).toBeInTheDocument();
  200. expect(screen.getByText(/Unresolved/i)).toBeInTheDocument();
  201. expect(screen.getByTestId('quick-context-unresolved-icon')).toBeInTheDocument();
  202. });
  203. it('Renders assigned To context when data is loaded', async () => {
  204. MockApiClient.addMockResponse({
  205. url: '/issues/3512441874/',
  206. method: 'GET',
  207. body: mockedGroup,
  208. });
  209. renderQuickContextContent();
  210. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  211. expect(await screen.findByText(/Assigned To/i)).toBeInTheDocument();
  212. expect(screen.getByText(/#ingest/i)).toBeInTheDocument();
  213. });
  214. it('Does not render suspect commit to context when row lacks event id', async () => {
  215. const dataRowWithoutId: unknown = {
  216. issue: 'SENTRY-VVY',
  217. release: 'backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76',
  218. title: 'error: Error -3 while decompressing data: invalid stored block lengths',
  219. 'issue.id': 3512441874,
  220. 'project.name': 'sentry',
  221. };
  222. MockApiClient.addMockResponse({
  223. url: '/issues/3512441874/',
  224. method: 'GET',
  225. body: mockedGroup,
  226. });
  227. renderQuickContextContent(dataRowWithoutId as EventData);
  228. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  229. await waitFor(() => {
  230. expect(
  231. screen.queryByTestId('quick-context-suspect-commits-container')
  232. ).not.toBeInTheDocument();
  233. });
  234. });
  235. it('Renders Suspect Commits', async () => {
  236. MockApiClient.addMockResponse({
  237. url: '/issues/3512441874/',
  238. method: 'GET',
  239. body: mockedGroup,
  240. });
  241. MockApiClient.addMockResponse({
  242. method: 'GET',
  243. url: '/projects/org-slug/cool-team/events/6b43e285de834ec5b5fe30d62d549b20/committers/',
  244. body: {
  245. committers: [
  246. {
  247. author: {name: 'Max Bittker', id: '1'},
  248. commits: [
  249. {
  250. message: 'feat: Added new feature',
  251. score: 4,
  252. id: 'ab2709293d0c9000829084ac7b1c9221fb18437c',
  253. repository: TestStubs.Repository(),
  254. dateCreated: '2018-03-02T18:30:26Z',
  255. pullRequest: {
  256. externalUrl: 'url',
  257. },
  258. },
  259. ],
  260. },
  261. ],
  262. },
  263. });
  264. renderQuickContextContent();
  265. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  266. expect(await screen.findByText(/Suspect Commits/i)).toBeInTheDocument();
  267. expect(screen.getByText(/MB/i)).toBeInTheDocument();
  268. expect(screen.getByText(/View commit/i)).toBeInTheDocument();
  269. expect(screen.getByText(/by/i)).toBeInTheDocument();
  270. expect(screen.getByText(/You/i)).toBeInTheDocument();
  271. });
  272. });
  273. describe('Quick Context Content Release Column', function () {
  274. afterEach(() => {
  275. queryClient.clear();
  276. MockApiClient.clearMockResponses();
  277. });
  278. it('Renders Release details for active release', async () => {
  279. MockApiClient.addMockResponse({
  280. url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
  281. body: mockedReleaseWithHealth,
  282. });
  283. renderQuickContextContent(defaultRow, ContextType.RELEASE);
  284. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  285. expect(await screen.findByText(/Release Details/i)).toBeInTheDocument();
  286. const definitions = screen.getAllByRole('definition');
  287. const terms = screen.getAllByRole('term');
  288. expect(within(terms[0]).getByText(/Status/i)).toBeInTheDocument();
  289. expect(within(definitions[0]).getByText(/Active/i)).toBeInTheDocument();
  290. expect(within(terms[1]).getByText(/Created/i)).toBeInTheDocument();
  291. expect(within(definitions[1]).getByText(/7 years ago/i)).toBeInTheDocument();
  292. expect(within(terms[2]).getByText(/First Event/i)).toBeInTheDocument();
  293. expect(within(definitions[2]).getByText(/7 years ago/i)).toBeInTheDocument();
  294. expect(within(terms[3]).getByText(/Last Event/i)).toBeInTheDocument();
  295. expect(within(definitions[3]).getByText(/6 years ago/i)).toBeInTheDocument();
  296. });
  297. it('Renders Release details for archived release', async () => {
  298. MockApiClient.addMockResponse({
  299. url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
  300. body: {...mockedReleaseWithHealth, status: 'closed'},
  301. });
  302. renderQuickContextContent(defaultRow, ContextType.RELEASE);
  303. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  304. expect(await screen.findByText(/Release Details/i)).toBeInTheDocument();
  305. expect(screen.getByText(/Status/i)).toBeInTheDocument();
  306. expect(screen.getByText(/Archived/i)).toBeInTheDocument();
  307. expect(screen.queryByText(/Created/i)).not.toBeInTheDocument();
  308. expect(screen.queryByText(/First Event/i)).not.toBeInTheDocument();
  309. expect(screen.queryByText(/Last Event/i)).not.toBeInTheDocument();
  310. });
  311. it('Renders Last Commit', async () => {
  312. MockApiClient.addMockResponse({
  313. url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
  314. body: mockedReleaseWithHealth,
  315. });
  316. renderQuickContextContent(defaultRow, ContextType.RELEASE);
  317. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  318. expect(await screen.findByText(/Last Commit/i)).toBeInTheDocument();
  319. expect(screen.getByTestId('quick-context-commit-row')).toBeInTheDocument();
  320. });
  321. it('Renders New Issues Count', async () => {
  322. MockApiClient.addMockResponse({
  323. url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
  324. body: mockedReleaseWithHealth,
  325. });
  326. renderQuickContextContent(defaultRow, ContextType.RELEASE);
  327. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  328. expect(await screen.findByText(/New Issues/i)).toBeInTheDocument();
  329. expect(screen.getByText(/21/i)).toBeInTheDocument();
  330. });
  331. it('Renders Commit Count and Author when user is NOT in list of authors', async () => {
  332. MockApiClient.addMockResponse({
  333. url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
  334. body: mockedReleaseWithHealth,
  335. });
  336. renderQuickContextContent(defaultRow, ContextType.RELEASE);
  337. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  338. expect(await screen.findByText(/4/i)).toBeInTheDocument();
  339. expect(screen.getByText(/commits by/i)).toBeInTheDocument();
  340. expect(screen.getAllByText(/2/i)).toHaveLength(2);
  341. expect(screen.getByText(/authors/i)).toBeInTheDocument();
  342. expect(screen.getByText(/KN/i)).toBeInTheDocument();
  343. expect(screen.getByText(/VN/i)).toBeInTheDocument();
  344. });
  345. it('Renders Commit Count and Author when user is in list of authors', async () => {
  346. jest.spyOn(ConfigStore, 'get').mockImplementation(() => mockedUser1);
  347. MockApiClient.addMockResponse({
  348. url: '/organizations/org-slug/releases/backend@22.10.0+aaf33944f93dc8fa4234ca046a8d88fb1dccfb76/',
  349. body: mockedReleaseWithHealth,
  350. });
  351. renderQuickContextContent(defaultRow, ContextType.RELEASE);
  352. userEvent.hover(screen.getByTestId('quick-context-hover-trigger'));
  353. expect(await screen.findByText(/4/i)).toBeInTheDocument();
  354. expect(screen.getByText(/commits by you and/i)).toBeInTheDocument();
  355. expect(screen.getAllByText(/1/i)).toHaveLength(2);
  356. expect(screen.getByText(/other/i)).toBeInTheDocument();
  357. expect(screen.getByText(/KN/i)).toBeInTheDocument();
  358. expect(screen.getByText(/VN/i)).toBeInTheDocument();
  359. });
  360. });
  361. });