releaseIssues.spec.jsx 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {textWithMarkupMatcher} from 'sentry-test/utils';
  4. import ReleaseIssues from 'sentry/views/releases/detail/overview/releaseIssues';
  5. import {getReleaseBounds} from 'sentry/views/releases/utils';
  6. describe('ReleaseIssues', function () {
  7. let newIssuesEndpoint,
  8. resolvedIssuesEndpoint,
  9. unhandledIssuesEndpoint,
  10. allIssuesEndpoint;
  11. const props = {
  12. orgId: 'org',
  13. organization: TestStubs.Organization(),
  14. version: '1.0.0',
  15. selection: {projects: [], environments: [], datetime: {}},
  16. location: {href: '', query: {}},
  17. releaseBounds: getReleaseBounds(TestStubs.Release({version: '1.0.0'})),
  18. };
  19. beforeEach(function () {
  20. MockApiClient.clearMockResponses();
  21. MockApiClient.addMockResponse({
  22. url: `/organizations/${props.organization.slug}/users/`,
  23. body: [],
  24. });
  25. MockApiClient.addMockResponse({
  26. url: `/organizations/${props.organization.slug}/issues-count/?end=2020-03-24T02%3A04%3A59Z&query=first-release%3A%221.0.0%22%20is%3Aunresolved&query=release%3A%221.0.0%22%20is%3Aunresolved&query=error.handled%3A0%20release%3A%221.0.0%22%20is%3Aunresolved&query=regressed_in_release%3A%221.0.0%22&start=2020-03-23T01%3A02%3A00Z`,
  27. });
  28. MockApiClient.addMockResponse({
  29. url: `/organizations/${props.organization.slug}/issues-count/?query=first-release%3A%221.0.0%22%20is%3Aunresolved&query=release%3A%221.0.0%22%20is%3Aunresolved&query=error.handled%3A0%20release%3A%221.0.0%22%20is%3Aunresolved&query=regressed_in_release%3A%221.0.0%22&statsPeriod=24h`,
  30. });
  31. MockApiClient.addMockResponse({
  32. url: `/organizations/${props.organization.slug}/releases/1.0.0/resolved/`,
  33. });
  34. newIssuesEndpoint = MockApiClient.addMockResponse({
  35. url: `/organizations/${props.organization.slug}/issues/?end=2020-03-24T02%3A04%3A59Z&groupStatsPeriod=auto&limit=10&query=first-release%3A1.0.0%20is%3Aunresolved&sort=freq&start=2020-03-23T01%3A02%3A00Z`,
  36. body: [],
  37. });
  38. MockApiClient.addMockResponse({
  39. url: `/organizations/${props.organization.slug}/issues/?groupStatsPeriod=auto&limit=10&query=first-release%3A1.0.0%20is%3Aunresolved&sort=freq&statsPeriod=24h`,
  40. body: [],
  41. });
  42. resolvedIssuesEndpoint = MockApiClient.addMockResponse({
  43. url: `/organizations/${props.organization.slug}/releases/1.0.0/resolved/?end=2020-03-24T02%3A04%3A59Z&groupStatsPeriod=auto&limit=10&query=&sort=freq&start=2020-03-23T01%3A02%3A00Z`,
  44. body: [],
  45. });
  46. unhandledIssuesEndpoint = MockApiClient.addMockResponse({
  47. url: `/organizations/${props.organization.slug}/issues/?end=2020-03-24T02%3A04%3A59Z&groupStatsPeriod=auto&limit=10&query=release%3A1.0.0%20error.handled%3A0%20is%3Aunresolved&sort=freq&start=2020-03-23T01%3A02%3A00Z`,
  48. body: [],
  49. });
  50. MockApiClient.addMockResponse({
  51. url: `/organizations/${props.organization.slug}/issues/?groupStatsPeriod=auto&limit=10&query=release%3A1.0.0%20error.handled%3A0%20is%3Aunresolved&sort=freq&statsPeriod=24h`,
  52. body: [],
  53. });
  54. allIssuesEndpoint = MockApiClient.addMockResponse({
  55. url: `/organizations/${props.organization.slug}/issues/?end=2020-03-24T02%3A04%3A59Z&groupStatsPeriod=auto&limit=10&query=release%3A1.0.0%20is%3Aunresolved&sort=freq&start=2020-03-23T01%3A02%3A00Z`,
  56. body: [],
  57. });
  58. });
  59. it('shows an empty state', async function () {
  60. render(<ReleaseIssues {...props} />);
  61. expect(await screen.findByText('No new issues in this release.')).toBeInTheDocument();
  62. userEvent.click(screen.getByRole('button', {name: 'Resolved 0'}));
  63. expect(
  64. await screen.findByText('No resolved issues in this release.')
  65. ).toBeInTheDocument();
  66. });
  67. it('shows an empty sttate with stats period', async function () {
  68. render(<ReleaseIssues {...props} location={{query: {pageStatsPeriod: '24h'}}} />);
  69. expect(
  70. await screen.findByText(
  71. textWithMarkupMatcher('No new issues for the last 24 hours.')
  72. )
  73. ).toBeInTheDocument();
  74. userEvent.click(screen.getByRole('button', {name: 'Unhandled 0'}));
  75. expect(
  76. await screen.findByText(
  77. textWithMarkupMatcher('No unhandled issues for the last 24 hours.')
  78. )
  79. ).toBeInTheDocument();
  80. });
  81. it('filters the issues', function () {
  82. render(<ReleaseIssues {...props} />);
  83. expect(screen.getAllByRole('button')).toHaveLength(6);
  84. userEvent.click(screen.getByRole('button', {name: 'New Issues'}));
  85. expect(newIssuesEndpoint).toHaveBeenCalledTimes(1);
  86. userEvent.click(screen.getByRole('button', {name: 'Resolved'}));
  87. expect(resolvedIssuesEndpoint).toHaveBeenCalledTimes(1);
  88. userEvent.click(screen.getByRole('button', {name: 'Unhandled'}));
  89. expect(unhandledIssuesEndpoint).toHaveBeenCalledTimes(1);
  90. userEvent.click(screen.getByRole('button', {name: 'All Issues'}));
  91. expect(allIssuesEndpoint).toHaveBeenCalledTimes(1);
  92. });
  93. it('renders link to Issues', function () {
  94. const {routerContext} = initializeOrg();
  95. render(<ReleaseIssues {...props} />, {context: routerContext});
  96. expect(screen.getByRole('button', {name: 'Open in Issues'})).toHaveAttribute(
  97. 'href',
  98. '/organizations/org-slug/issues/?end=2020-03-24T02%3A04%3A59Z&groupStatsPeriod=auto&query=firstRelease%3A1.0.0&sort=freq&start=2020-03-23T01%3A02%3A00Z'
  99. );
  100. userEvent.click(screen.getByRole('button', {name: 'Resolved'}));
  101. expect(screen.getByRole('button', {name: 'Open in Issues'})).toHaveAttribute(
  102. 'href',
  103. '/organizations/org-slug/issues/?end=2020-03-24T02%3A04%3A59Z&groupStatsPeriod=auto&query=release%3A1.0.0&sort=freq&start=2020-03-23T01%3A02%3A00Z'
  104. );
  105. userEvent.click(screen.getByRole('button', {name: 'Unhandled'}));
  106. expect(screen.getByRole('button', {name: 'Open in Issues'})).toHaveAttribute(
  107. 'href',
  108. '/organizations/org-slug/issues/?end=2020-03-24T02%3A04%3A59Z&groupStatsPeriod=auto&query=release%3A1.0.0%20error.handled%3A0&sort=freq&start=2020-03-23T01%3A02%3A00Z'
  109. );
  110. userEvent.click(screen.getByRole('button', {name: 'All Issues'}));
  111. expect(screen.getByRole('button', {name: 'Open in Issues'})).toHaveAttribute(
  112. 'href',
  113. '/organizations/org-slug/issues/?end=2020-03-24T02%3A04%3A59Z&groupStatsPeriod=auto&query=release%3A1.0.0&sort=freq&start=2020-03-23T01%3A02%3A00Z'
  114. );
  115. });
  116. });