projectIssues.spec.jsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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=is%3Aunresolved%20error.unhandled%3Atrue&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. });
  37. expect(await screen.findAllByTestId('group')).toHaveLength(2);
  38. });
  39. it('renders a link to Issues', function () {
  40. render(<ProjectIssues organization={organization} location={router.location} />, {
  41. context: routerContext,
  42. });
  43. const link = screen.getByLabelText('Open in Issues');
  44. expect(link).toBeInTheDocument();
  45. userEvent.click(link);
  46. expect(router.push).toHaveBeenCalledWith({
  47. pathname: '/organizations/org-slug/issues/',
  48. query: {
  49. limit: 5,
  50. query: 'error.unhandled:true is:unresolved',
  51. sort: 'freq',
  52. statsPeriod: '14d',
  53. },
  54. });
  55. });
  56. it('renders a link to Discover', function () {
  57. render(<ProjectIssues organization={organization} location={router.location} />, {
  58. context: routerContext,
  59. });
  60. const link = screen.getByLabelText('Open in Discover');
  61. expect(link).toBeInTheDocument();
  62. userEvent.click(link);
  63. expect(router.push).toHaveBeenCalledWith({
  64. pathname: `/organizations/${organization.slug}/discover/results/`,
  65. query: {
  66. display: 'top5',
  67. field: ['issue', 'title', 'count()', 'count_unique(user)', 'project'],
  68. name: 'Frequent Unhandled Issues',
  69. query: 'event.type:error error.unhandled:true',
  70. sort: ['-count'],
  71. statsPeriod: '14d',
  72. },
  73. });
  74. });
  75. it('changes according to global header', function () {
  76. render(
  77. <ProjectIssues
  78. organization={organization}
  79. location={{
  80. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  81. }}
  82. />,
  83. {context: routerContext}
  84. );
  85. expect(endpointMock).toHaveBeenCalledTimes(0);
  86. expect(filteredEndpointMock).toHaveBeenCalledTimes(1);
  87. const link = screen.getByLabelText('Open in Issues');
  88. expect(link).toBeInTheDocument();
  89. userEvent.click(link);
  90. expect(router.push).toHaveBeenCalledWith({
  91. pathname: `/organizations/${organization.slug}/issues/`,
  92. query: {
  93. limit: 5,
  94. environment: 'staging',
  95. statsPeriod: '7d',
  96. query: 'error.unhandled:true is:unresolved',
  97. sort: 'freq',
  98. },
  99. });
  100. });
  101. });