projectIssues.spec.jsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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=is%3Aunresolved%20error.unhandled%3Atrue&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. MockApiClient.warnOnMissingMocks();
  47. render(
  48. <OrganizationContext.Provider value={organization}>
  49. <ProjectIssues organization={organization} location={router.location} />
  50. </OrganizationContext.Provider>,
  51. {
  52. context: routerContext,
  53. }
  54. );
  55. const link = screen.getByLabelText('Open in Issues');
  56. expect(link).toBeInTheDocument();
  57. userEvent.click(link);
  58. expect(router.push).toHaveBeenCalledWith({
  59. pathname: '/organizations/org-slug/issues/',
  60. query: {
  61. limit: 5,
  62. query: 'error.unhandled:true is:unresolved',
  63. sort: 'freq',
  64. statsPeriod: '14d',
  65. },
  66. });
  67. });
  68. it('renders a link to Discover', function () {
  69. MockApiClient.warnOnMissingMocks();
  70. render(
  71. <OrganizationContext.Provider value={organization}>
  72. <ProjectIssues organization={organization} location={router.location} />
  73. </OrganizationContext.Provider>,
  74. {
  75. context: routerContext,
  76. }
  77. );
  78. const link = screen.getByLabelText('Open in Discover');
  79. expect(link).toBeInTheDocument();
  80. userEvent.click(link);
  81. expect(router.push).toHaveBeenCalledWith({
  82. pathname: `/organizations/${organization.slug}/discover/results/`,
  83. query: {
  84. display: 'top5',
  85. field: ['issue', 'title', 'count()', 'count_unique(user)', 'project'],
  86. name: 'Frequent Unhandled Issues',
  87. query: 'event.type:error error.unhandled:true',
  88. sort: ['-count'],
  89. statsPeriod: '14d',
  90. },
  91. });
  92. });
  93. it('changes according to global header', function () {
  94. render(
  95. <OrganizationContext.Provider value={organization}>
  96. <ProjectIssues
  97. organization={organization}
  98. location={{
  99. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  100. }}
  101. />
  102. </OrganizationContext.Provider>,
  103. {context: routerContext}
  104. );
  105. expect(endpointMock).toHaveBeenCalledTimes(0);
  106. expect(filteredEndpointMock).toHaveBeenCalledTimes(1);
  107. const link = screen.getByLabelText('Open in Issues');
  108. expect(link).toBeInTheDocument();
  109. userEvent.click(link);
  110. expect(router.push).toHaveBeenCalledWith({
  111. pathname: `/organizations/${organization.slug}/issues/`,
  112. query: {
  113. limit: 5,
  114. environment: 'staging',
  115. statsPeriod: '7d',
  116. query: 'error.unhandled:true is:unresolved',
  117. sort: 'freq',
  118. },
  119. });
  120. });
  121. });