projectIssues.spec.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import ProjectIssues from 'sentry/views/projectDetail/projectIssues';
  4. describe('ProjectDetail > ProjectIssues', function () {
  5. let endpointMock, filteredEndpointMock;
  6. const {organization, router, routerContext} = initializeOrg({
  7. organization: {
  8. features: ['discover-basic'],
  9. },
  10. });
  11. beforeEach(function () {
  12. endpointMock = MockApiClient.addMockResponse({
  13. url: `/organizations/${organization.slug}/issues/?limit=5&query=error.unhandled%3Atrue%20is%3Aunresolved&sort=freq&statsPeriod=14d`,
  14. body: [TestStubs.Group(), TestStubs.Group({id: '2'})],
  15. });
  16. filteredEndpointMock = MockApiClient.addMockResponse({
  17. url: `/organizations/${organization.slug}/issues/?environment=staging&limit=5&query=error.unhandled%3Atrue%20is%3Aunresolved&sort=freq&statsPeriod=7d`,
  18. body: [TestStubs.Group(), TestStubs.Group({id: '2'})],
  19. });
  20. MockApiClient.addMockResponse({
  21. url: `/organizations/${organization.slug}/users/`,
  22. body: [],
  23. });
  24. });
  25. afterEach(function () {
  26. MockApiClient.clearMockResponses();
  27. jest.clearAllMocks();
  28. });
  29. it('renders a list', async function () {
  30. MockApiClient.addMockResponse({
  31. url: `/organizations/org-slug/issues/?limit=5&query=error.unhandled%3Atrue%20is%3Aunresolved&sort=freq&statsPeriod=14d`,
  32. body: [TestStubs.Group(), TestStubs.Group({id: '2'})],
  33. });
  34. render(<ProjectIssues organization={organization} location={router.location} />, {
  35. context: routerContext,
  36. organization,
  37. });
  38. expect(await screen.findAllByTestId('group')).toHaveLength(2);
  39. });
  40. it('renders a link to Issues', function () {
  41. render(<ProjectIssues organization={organization} location={router.location} />, {
  42. context: routerContext,
  43. organization,
  44. });
  45. const link = screen.getByLabelText('Open in Issues');
  46. expect(link).toBeInTheDocument();
  47. userEvent.click(link);
  48. expect(router.push).toHaveBeenCalledWith({
  49. pathname: '/organizations/org-slug/issues/',
  50. query: {
  51. limit: 5,
  52. query: 'error.unhandled:true is:unresolved',
  53. sort: 'freq',
  54. statsPeriod: '14d',
  55. },
  56. });
  57. });
  58. it('renders a link to Discover', function () {
  59. render(<ProjectIssues organization={organization} location={router.location} />, {
  60. context: routerContext,
  61. organization,
  62. });
  63. const link = screen.getByLabelText('Open in Discover');
  64. expect(link).toBeInTheDocument();
  65. userEvent.click(link);
  66. expect(router.push).toHaveBeenCalledWith({
  67. pathname: `/organizations/${organization.slug}/discover/results/`,
  68. query: {
  69. display: 'top5',
  70. field: ['issue', 'title', 'count()', 'count_unique(user)', 'project'],
  71. name: 'Frequent Unhandled Issues',
  72. query: 'event.type:error error.unhandled:true',
  73. sort: ['-count'],
  74. statsPeriod: '14d',
  75. },
  76. });
  77. });
  78. it('changes according to global header', function () {
  79. render(
  80. <ProjectIssues
  81. organization={organization}
  82. location={{
  83. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  84. }}
  85. />,
  86. {context: routerContext, organization}
  87. );
  88. expect(endpointMock).toHaveBeenCalledTimes(0);
  89. expect(filteredEndpointMock).toHaveBeenCalledTimes(1);
  90. const link = screen.getByLabelText('Open in Issues');
  91. expect(link).toBeInTheDocument();
  92. userEvent.click(link);
  93. expect(router.push).toHaveBeenCalledWith({
  94. pathname: `/organizations/${organization.slug}/issues/`,
  95. query: {
  96. limit: 5,
  97. environment: 'staging',
  98. statsPeriod: '7d',
  99. query: 'error.unhandled:true is:unresolved',
  100. sort: 'freq',
  101. },
  102. });
  103. });
  104. });