issueWidgetQueries.spec.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import type {Widget} from 'sentry/views/dashboards/types';
  4. import {
  5. DashboardFilterKeys,
  6. DisplayType,
  7. WidgetType,
  8. } from 'sentry/views/dashboards/types';
  9. import IssueWidgetQueries from 'sentry/views/dashboards/widgetCard/issueWidgetQueries';
  10. describe('IssueWidgetQueries', function () {
  11. const widget: Widget = {
  12. id: '1',
  13. title: 'Issues Widget',
  14. displayType: DisplayType.TABLE,
  15. interval: '5m',
  16. queries: [
  17. {
  18. name: '',
  19. fields: ['issue', 'assignee', 'title', 'culprit', 'status'],
  20. columns: ['issue', 'assignee', 'title', 'culprit', 'status'],
  21. aggregates: [],
  22. conditions: 'assigned_or_suggested:#visibility timesSeen:>100',
  23. orderby: '',
  24. },
  25. ],
  26. widgetType: WidgetType.ISSUE,
  27. };
  28. const selection = {
  29. projects: [1],
  30. environments: ['prod'],
  31. datetime: {
  32. period: '14d',
  33. start: null,
  34. end: null,
  35. utc: false,
  36. },
  37. };
  38. const {organization} = initializeOrg({
  39. router: {orgId: 'orgId'},
  40. } as Parameters<typeof initializeOrg>[0]);
  41. const api = new MockApiClient();
  42. it('does an issue query and passes correct tableResults to child component', async function () {
  43. const mockFunction = jest.fn(() => {
  44. return <div />;
  45. });
  46. MockApiClient.clearMockResponses();
  47. MockApiClient.addMockResponse({
  48. url: '/organizations/org-slug/issues/',
  49. method: 'GET',
  50. body: [
  51. {
  52. id: '1',
  53. title: 'Error: Failed',
  54. project: {
  55. id: '3',
  56. },
  57. status: 'unresolved',
  58. owners: [
  59. {
  60. type: 'ownershipRule',
  61. owner: 'user:2',
  62. },
  63. ],
  64. lifetime: {count: 10, userCount: 5},
  65. count: 6,
  66. userCount: 3,
  67. firstSeen: '2022-01-01T13:04:02Z',
  68. },
  69. ],
  70. });
  71. render(
  72. <IssueWidgetQueries
  73. api={api}
  74. organization={organization}
  75. widget={widget}
  76. selection={{
  77. projects: [1],
  78. environments: ['prod'],
  79. datetime: {
  80. period: '14d',
  81. start: null,
  82. end: null,
  83. utc: false,
  84. },
  85. }}
  86. >
  87. {mockFunction}
  88. </IssueWidgetQueries>
  89. );
  90. await tick();
  91. expect(mockFunction).toHaveBeenCalledWith(
  92. expect.objectContaining({
  93. tableResults: [
  94. expect.objectContaining({
  95. data: [
  96. expect.objectContaining({
  97. id: '1',
  98. title: 'Error: Failed',
  99. status: 'unresolved',
  100. lifetimeEvents: 10,
  101. lifetimeUsers: 5,
  102. events: 6,
  103. users: 3,
  104. firstSeen: '2022-01-01T13:04:02Z',
  105. }),
  106. ],
  107. }),
  108. ],
  109. })
  110. );
  111. });
  112. it('appends dashboard filters to issue request', async function () {
  113. const mock = MockApiClient.addMockResponse({
  114. url: '/organizations/org-slug/issues/',
  115. body: [],
  116. });
  117. render(
  118. <IssueWidgetQueries
  119. api={api}
  120. organization={organization}
  121. widget={widget}
  122. selection={selection}
  123. dashboardFilters={{[DashboardFilterKeys.RELEASE]: ['abc@1.2.0', 'abc@1.3.0']}}
  124. >
  125. {() => <div data-test-id="child" />}
  126. </IssueWidgetQueries>
  127. );
  128. await screen.findByTestId('child');
  129. expect(mock).toHaveBeenCalledWith(
  130. '/organizations/org-slug/issues/',
  131. expect.objectContaining({
  132. data: expect.objectContaining({
  133. query:
  134. 'assigned_or_suggested:#visibility timesSeen:>100 release:["abc@1.2.0","abc@1.3.0"] ',
  135. }),
  136. })
  137. );
  138. });
  139. });