index.spec.tsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {EventGroupingInfo} from 'sentry/components/events/groupingInfo';
  5. import {EventGroupVariantType, IssueCategory} from 'sentry/types';
  6. describe('EventGroupingInfo', function () {
  7. const group = GroupFixture();
  8. const event = EventFixture({
  9. groupingConfig: {
  10. id: 'default:XXXX',
  11. },
  12. });
  13. const defaultProps = {
  14. event,
  15. projectSlug: 'project-slug',
  16. showGroupingConfig: false,
  17. group,
  18. };
  19. let groupingInfoRequest = jest.fn();
  20. beforeEach(() => {
  21. MockApiClient.clearMockResponses();
  22. groupingInfoRequest = MockApiClient.addMockResponse({
  23. url: `/projects/org-slug/project-slug/events/${event.id}/grouping-info/`,
  24. body: {
  25. app: {
  26. description: 'variant description',
  27. hash: '123',
  28. hashMismatch: false,
  29. key: 'key',
  30. type: EventGroupVariantType.CHECKSUM,
  31. },
  32. },
  33. });
  34. });
  35. it('fetches and renders grouping info for errors', async function () {
  36. render(<EventGroupingInfo {...defaultProps} />);
  37. await screen.findByText('variant description');
  38. // Hash should not be visible until toggling open
  39. expect(screen.queryByText('123')).not.toBeInTheDocument();
  40. await userEvent.click(screen.getByRole('button', {name: 'Show Details'}));
  41. expect(screen.getByText('123')).toBeInTheDocument();
  42. });
  43. it('gets performance grouping info from group/event data', async function () {
  44. const perfEvent = EventFixture({
  45. type: 'transaction',
  46. occurrence: {fingerprint: ['123'], evidenceData: {op: 'bad-op'}},
  47. });
  48. const perfGroup = GroupFixture({issueCategory: IssueCategory.PERFORMANCE});
  49. render(<EventGroupingInfo {...defaultProps} event={perfEvent} group={perfGroup} />);
  50. expect(screen.getByText('performance problem')).toBeInTheDocument();
  51. // Hash should not be visible until toggling open
  52. expect(screen.queryByText('123')).not.toBeInTheDocument();
  53. await userEvent.click(screen.getByRole('button', {name: 'Show Details'}));
  54. expect(screen.getByText('123')).toBeInTheDocument();
  55. // Should not make grouping-info request
  56. expect(groupingInfoRequest).not.toHaveBeenCalled();
  57. });
  58. it('can switch grouping configs', async function () {
  59. MockApiClient.addMockResponse({
  60. url: `/organizations/org-slug/grouping-configs/`,
  61. body: [
  62. {id: 'default:XXXX', hidden: false},
  63. {id: 'new:XXXX', hidden: false},
  64. ],
  65. });
  66. render(<EventGroupingInfo {...defaultProps} showGroupingConfig />);
  67. await userEvent.click(screen.getByRole('button', {name: 'Show Details'}));
  68. // Should show first hash
  69. await screen.findByText('123');
  70. expect(screen.getByText('default:XXXX')).toBeInTheDocument();
  71. MockApiClient.addMockResponse({
  72. url: `/projects/org-slug/project-slug/events/${event.id}/grouping-info/`,
  73. query: {config: 'new:XXXX'},
  74. body: {
  75. app: {
  76. description: 'variant description',
  77. hash: '789',
  78. hashMismatch: false,
  79. key: 'key',
  80. type: EventGroupVariantType.CHECKSUM,
  81. },
  82. },
  83. });
  84. await userEvent.click(screen.getAllByRole('button', {name: 'default:XXXX'})[0]);
  85. await userEvent.click(screen.getByRole('option', {name: 'new:XXXX'}));
  86. // Should show new hash
  87. await screen.findByText('789');
  88. });
  89. });