ignore.spec.jsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. } from 'sentry-test/reactTestingLibrary';
  7. import IgnoreActions from 'sentry/components/actions/ignore';
  8. describe('IgnoreActions', function () {
  9. const spy = jest.fn();
  10. afterEach(() => {
  11. jest.resetAllMocks();
  12. });
  13. describe('disabled', function () {
  14. it('does not call onUpdate when clicked', function () {
  15. render(<IgnoreActions onUpdate={spy} disabled />);
  16. const button = screen.getByRole('button', {name: 'Ignore'});
  17. expect(button).toBeDisabled();
  18. userEvent.click(button);
  19. expect(spy).not.toHaveBeenCalled();
  20. });
  21. });
  22. describe('ignored', function () {
  23. it('displays ignored view', function () {
  24. render(<IgnoreActions onUpdate={spy} isIgnored />);
  25. const button = screen.getByRole('button', {name: 'Unignore'});
  26. expect(button).toBeInTheDocument();
  27. // Shows icon only
  28. expect(button).toHaveTextContent('');
  29. userEvent.click(button);
  30. expect(spy).toHaveBeenCalledWith({status: 'unresolved'});
  31. });
  32. });
  33. describe('without confirmation', function () {
  34. it('calls spy with ignore details when clicked', function () {
  35. render(<IgnoreActions onUpdate={spy} />);
  36. const button = screen.getByRole('button', {name: 'Ignore'});
  37. userEvent.click(button);
  38. expect(spy).toHaveBeenCalledTimes(1);
  39. expect(spy).toHaveBeenCalledWith({status: 'ignored'});
  40. });
  41. });
  42. describe('with confirmation step', function () {
  43. it('displays confirmation modal with message provided', function () {
  44. render(<IgnoreActions onUpdate={spy} shouldConfirm confirmMessage="confirm me" />);
  45. renderGlobalModal();
  46. const button = screen.getByRole('button', {name: 'Ignore'});
  47. userEvent.click(button);
  48. expect(screen.getByText('confirm me')).toBeInTheDocument();
  49. expect(spy).not.toHaveBeenCalled();
  50. userEvent.click(screen.getByTestId('confirm-button'));
  51. expect(spy).toHaveBeenCalled();
  52. });
  53. });
  54. });