anomalyDetectionFeedbackBanner.spec.tsx 3.6 KB

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