ignore.spec.jsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import {
  2. render,
  3. renderGlobalModal,
  4. screen,
  5. userEvent,
  6. within,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import IgnoreActions from 'sentry/components/actions/ignore';
  9. describe('IgnoreActions', function () {
  10. const spy = jest.fn();
  11. afterEach(() => {
  12. jest.resetAllMocks();
  13. });
  14. describe('disabled', function () {
  15. it('does not call onUpdate when clicked', function () {
  16. render(<IgnoreActions onUpdate={spy} disabled />);
  17. const button = screen.getByRole('button', {name: 'Ignore'});
  18. expect(button).toBeDisabled();
  19. userEvent.click(button);
  20. expect(spy).not.toHaveBeenCalled();
  21. });
  22. });
  23. describe('ignored', function () {
  24. it('displays ignored view', function () {
  25. render(<IgnoreActions onUpdate={spy} isIgnored />);
  26. const button = screen.getByRole('button', {name: 'Unignore'});
  27. expect(button).toBeInTheDocument();
  28. // Shows icon only
  29. expect(button).toHaveTextContent('');
  30. userEvent.click(button);
  31. expect(spy).toHaveBeenCalledWith({status: 'unresolved', statusDetails: {}});
  32. });
  33. });
  34. describe('without confirmation', function () {
  35. it('calls spy with ignore details when clicked', function () {
  36. render(<IgnoreActions onUpdate={spy} />);
  37. const button = screen.getByRole('button', {name: 'Ignore'});
  38. userEvent.click(button);
  39. expect(spy).toHaveBeenCalledTimes(1);
  40. expect(spy).toHaveBeenCalledWith({status: 'ignored', statusDetails: {}});
  41. });
  42. });
  43. describe('with confirmation step', function () {
  44. it('displays confirmation modal with message provided', function () {
  45. render(
  46. <IgnoreActions onUpdate={spy} shouldConfirm confirmMessage={() => 'confirm me'} />
  47. );
  48. renderGlobalModal();
  49. const button = screen.getByRole('button', {name: 'Ignore'});
  50. userEvent.click(button);
  51. expect(screen.getByText('confirm me')).toBeInTheDocument();
  52. expect(spy).not.toHaveBeenCalled();
  53. userEvent.click(screen.getByTestId('confirm-button'));
  54. expect(spy).toHaveBeenCalled();
  55. });
  56. });
  57. describe('custom', function () {
  58. it('can ignore until a custom date/time', function () {
  59. render(
  60. <IgnoreActions onUpdate={spy} shouldConfirm confirmMessage={() => 'confirm me'} />
  61. );
  62. renderGlobalModal();
  63. userEvent.click(screen.getByRole('button', {name: 'Ignore options'}));
  64. userEvent.hover(screen.getByRole('menuitemradio', {name: 'For…'}));
  65. userEvent.click(screen.getByRole('menuitemradio', {name: /Custom/}));
  66. // opens modal
  67. expect(screen.getByRole('dialog')).toBeInTheDocument();
  68. userEvent.click(
  69. within(screen.getByRole('dialog')).getByRole('button', {name: 'Ignore'})
  70. );
  71. expect(spy).toHaveBeenCalledWith({
  72. status: 'ignored',
  73. statusDetails: {
  74. ignoreDuration: expect.any(Number),
  75. },
  76. });
  77. });
  78. });
  79. });