autofixRootCause.spec.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {AutofixRootCauseData} from 'sentry-fixture/autofixRootCauseData';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import {AutofixRootCause} from 'sentry/components/events/autofix/autofixRootCause';
  4. describe('AutofixRootCause', function () {
  5. const defaultProps = {
  6. causes: [AutofixRootCauseData()],
  7. groupId: '1',
  8. rootCauseSelection: null,
  9. runId: '101',
  10. };
  11. it('can select a suggested fix', async function () {
  12. const mockSelectFix = MockApiClient.addMockResponse({
  13. url: '/issues/1/autofix/update/',
  14. method: 'POST',
  15. });
  16. render(<AutofixRootCause {...defaultProps} />);
  17. // Displays all root cause and suggested fix info
  18. expect(screen.getByText('This is the title of a root cause.')).toBeInTheDocument();
  19. expect(
  20. screen.getByText('This is the description of a root cause.')
  21. ).toBeInTheDocument();
  22. expect(
  23. screen.getByText('Suggested Fix #1: This is the title of a suggested fix.')
  24. ).toBeInTheDocument();
  25. expect(
  26. screen.getByText('This is the description of a suggested fix.')
  27. ).toBeInTheDocument();
  28. await userEvent.click(screen.getByRole('button', {name: 'Continue With This Fix'}));
  29. expect(mockSelectFix).toHaveBeenCalledWith(
  30. expect.anything(),
  31. expect.objectContaining({
  32. data: {
  33. run_id: '101',
  34. payload: {
  35. type: 'select_root_cause',
  36. cause_id: '100',
  37. fix_id: '200',
  38. },
  39. },
  40. })
  41. );
  42. });
  43. it('can provide a custom root cause', async function () {
  44. const mockSelectFix = MockApiClient.addMockResponse({
  45. url: '/issues/1/autofix/update/',
  46. method: 'POST',
  47. });
  48. render(<AutofixRootCause {...defaultProps} />);
  49. await userEvent.click(
  50. screen.getByRole('button', {name: 'Provide your own root cause'})
  51. );
  52. await userEvent.keyboard('custom root cause');
  53. await userEvent.click(screen.getByRole('button', {name: 'Continue With This Fix'}));
  54. expect(mockSelectFix).toHaveBeenCalledWith(
  55. expect.anything(),
  56. expect.objectContaining({
  57. data: {
  58. run_id: '101',
  59. payload: {
  60. type: 'select_root_cause',
  61. custom_root_cause: 'custom root cause',
  62. },
  63. },
  64. })
  65. );
  66. });
  67. it('shows graceful error state when there are no causes', function () {
  68. render(
  69. <AutofixRootCause
  70. {...{
  71. ...defaultProps,
  72. causes: [],
  73. }}
  74. />
  75. );
  76. // Displays all root cause and suggested fix info
  77. expect(
  78. screen.getByText('Autofix was not able to find a root cause. Maybe try again?')
  79. ).toBeInTheDocument();
  80. });
  81. });