autofixBanner.spec.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. } from 'sentry-test/reactTestingLibrary';
  7. import {AutofixBanner} from './autofixBanner';
  8. function mockIsSentryEmployee(isEmployee: boolean) {
  9. jest
  10. .spyOn(require('sentry/utils/useIsSentryEmployee'), 'useIsSentryEmployee')
  11. .mockImplementation(() => isEmployee);
  12. }
  13. describe('AutofixBanner', () => {
  14. afterEach(() => {
  15. jest.resetAllMocks();
  16. });
  17. const defaultProps = {
  18. groupId: '1',
  19. hasSuccessfulSetup: true,
  20. triggerAutofix: jest.fn(),
  21. };
  22. it('shows PII check for sentry employee users', () => {
  23. mockIsSentryEmployee(true);
  24. render(<AutofixBanner {...defaultProps} projectId="1" />);
  25. expect(
  26. screen.getByText(
  27. 'By clicking the button above, you confirm that there is no PII in this event.'
  28. )
  29. ).toBeInTheDocument();
  30. });
  31. it('does not show PII check for non sentry employee users', () => {
  32. mockIsSentryEmployee(false);
  33. render(<AutofixBanner {...defaultProps} projectId="1" />);
  34. expect(
  35. screen.queryByText(
  36. 'By clicking the button above, you confirm that there is no PII in this event.'
  37. )
  38. ).not.toBeInTheDocument();
  39. });
  40. it('can run without instructions', async () => {
  41. const mockTriggerAutofix = jest.fn();
  42. render(
  43. <AutofixBanner
  44. {...defaultProps}
  45. triggerAutofix={mockTriggerAutofix}
  46. projectId="1"
  47. />
  48. );
  49. renderGlobalModal();
  50. await userEvent.click(screen.getByRole('button', {name: 'Get root causes'}));
  51. expect(mockTriggerAutofix).toHaveBeenCalledWith('');
  52. });
  53. it('can provide instructions', async () => {
  54. const mockTriggerAutofix = jest.fn();
  55. render(
  56. <AutofixBanner
  57. {...defaultProps}
  58. triggerAutofix={mockTriggerAutofix}
  59. projectId="1"
  60. />
  61. );
  62. renderGlobalModal();
  63. await userEvent.click(screen.getByRole('button', {name: 'Provide context first'}));
  64. await userEvent.type(screen.getByRole('textbox'), 'instruction!');
  65. await userEvent.click(screen.getByRole('button', {name: "Let's go!"}));
  66. expect(mockTriggerAutofix).toHaveBeenCalledWith('instruction!');
  67. });
  68. });