anomalyDetectionFeedbackBanner.spec.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import {IncidentFixture} from 'sentry-fixture/incident';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {feedbackClient} from 'sentry/components/featureFeedback/feedbackModal';
  5. import * as analytics from 'sentry/utils/analytics';
  6. import AnomalyDetectionFeedbackBanner from './anomalyDetectionFeedbackBanner';
  7. describe('AnomalyDetectionFeedbackBanner', () => {
  8. const initialData = initializeOrg({
  9. organization: {
  10. features: [
  11. 'change-alerts',
  12. 'anomaly-detection-alerts',
  13. 'anomaly-detection-rollout',
  14. ],
  15. },
  16. });
  17. const organization = initialData.organization;
  18. const project = initialData.project;
  19. const mockIncident = IncidentFixture({projects: [project.slug]});
  20. const mockIncident2 = IncidentFixture({id: '6702'});
  21. const analyticsSpy = jest.spyOn(analytics, 'trackAnalytics');
  22. it('submits anomaly detection feedback (yes)', async () => {
  23. const {container} = render(
  24. <AnomalyDetectionFeedbackBanner
  25. id={mockIncident.id}
  26. organization={organization}
  27. selectedIncident={mockIncident}
  28. />
  29. );
  30. expect(screen.getByText(/Was the anomaly correctly identified?/)).toBeInTheDocument();
  31. await userEvent.click(screen.getByRole('button', {name: 'Yes'}));
  32. expect(analyticsSpy).toHaveBeenCalledWith(
  33. 'anomaly-detection.feedback-submitted',
  34. expect.objectContaining({
  35. choice_selected: true,
  36. organization,
  37. incident_id: mockIncident.id,
  38. })
  39. );
  40. expect(feedbackClient.captureEvent).toHaveBeenCalledWith({
  41. message: 'Anomaly Detection Alerts Banner Feedback',
  42. level: 'info',
  43. tags: {
  44. featureName: 'anomaly-detection-alerts-feedback',
  45. choice_selected: true,
  46. incident_id: mockIncident.id,
  47. alert_rule_id: mockIncident.alertRule.id,
  48. metric: mockIncident.alertRule.query,
  49. sensitivity: mockIncident.alertRule.sensitivity,
  50. direction: mockIncident.alertRule.thresholdType,
  51. time_window: mockIncident.alertRule.timeWindow,
  52. },
  53. request: expect.anything(),
  54. user: expect.anything(),
  55. });
  56. expect(container).toBeEmptyDOMElement();
  57. });
  58. it('submits anomaly detection feedback (no)', async () => {
  59. const {container} = render(
  60. <AnomalyDetectionFeedbackBanner
  61. id={mockIncident2.id}
  62. organization={organization}
  63. selectedIncident={mockIncident2}
  64. />
  65. );
  66. expect(screen.getByText(/Was the anomaly correctly identified?/)).toBeInTheDocument();
  67. await userEvent.click(screen.getByRole('button', {name: 'No'}));
  68. expect(analyticsSpy).toHaveBeenCalledWith(
  69. 'anomaly-detection.feedback-submitted',
  70. expect.objectContaining({
  71. choice_selected: false,
  72. organization,
  73. incident_id: mockIncident2.id,
  74. })
  75. );
  76. expect(feedbackClient.captureEvent).toHaveBeenCalledWith({
  77. message: 'Anomaly Detection Alerts Banner Feedback',
  78. level: 'info',
  79. tags: {
  80. featureName: 'anomaly-detection-alerts-feedback',
  81. choice_selected: false,
  82. incident_id: mockIncident2.id,
  83. alert_rule_id: mockIncident2.alertRule.id,
  84. metric: mockIncident2.alertRule.query,
  85. sensitivity: mockIncident2.alertRule.sensitivity,
  86. direction: mockIncident2.alertRule.thresholdType,
  87. time_window: mockIncident2.alertRule.timeWindow,
  88. },
  89. request: expect.anything(),
  90. user: expect.anything(),
  91. });
  92. expect(container).toBeEmptyDOMElement();
  93. });
  94. });