projectIssues.spec.jsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import ProjectIssues from 'sentry/views/projectDetail/projectIssues';
  4. describe('ProjectDetail > ProjectIssues', function () {
  5. let endpointMock, filteredEndpointMock, wrapper;
  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. wrapper.unmount();
  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. wrapper = mountWithTheme(
  35. <ProjectIssues organization={organization} location={router.location} />,
  36. routerContext
  37. );
  38. await tick();
  39. wrapper.update();
  40. expect(wrapper.find('StreamGroup').length).toBe(2);
  41. });
  42. it('renders a link to Issues', function () {
  43. wrapper = mountWithTheme(
  44. <ProjectIssues organization={organization} location={router.location} />,
  45. routerContext
  46. );
  47. expect(
  48. wrapper.find('ControlsWrapper Link[aria-label="Open in Issues"]').at(0).prop('to')
  49. ).toEqual({
  50. pathname: `/organizations/${organization.slug}/issues/`,
  51. query: {
  52. limit: 5,
  53. query: 'error.unhandled:true is:unresolved',
  54. sort: 'freq',
  55. statsPeriod: '14d',
  56. },
  57. });
  58. });
  59. it('renders a link to Discover', function () {
  60. wrapper = mountWithTheme(
  61. <ProjectIssues organization={organization} location={router.location} />,
  62. routerContext
  63. );
  64. expect(
  65. wrapper.find('ControlsWrapper Link[aria-label="Open in Discover"]').at(0).prop('to')
  66. ).toEqual({
  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. wrapper = mountWithTheme(
  80. <ProjectIssues
  81. organization={organization}
  82. location={{
  83. query: {statsPeriod: '7d', environment: 'staging', somethingBad: 'nope'},
  84. }}
  85. />,
  86. routerContext
  87. );
  88. expect(endpointMock).toHaveBeenCalledTimes(0);
  89. expect(filteredEndpointMock).toHaveBeenCalledTimes(1);
  90. expect(
  91. wrapper.find('ControlsWrapper Link[aria-label="Open in Issues"]').at(0).prop('to')
  92. ).toEqual({
  93. pathname: `/organizations/${organization.slug}/issues/`,
  94. query: {
  95. limit: 5,
  96. environment: 'staging',
  97. statsPeriod: '7d',
  98. query: 'error.unhandled:true is:unresolved',
  99. sort: 'freq',
  100. },
  101. });
  102. });
  103. });