projectIssues.spec.jsx 4.2 KB

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