ignore.spec.jsx 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {mountGlobalModal} from 'sentry-test/modal';
  3. import IgnoreActions from 'app/components/actions/ignore';
  4. describe('IgnoreActions', function () {
  5. const routerContext = TestStubs.routerContext();
  6. describe('disabled', function () {
  7. let component, button;
  8. const spy = jest.fn();
  9. beforeEach(function () {
  10. component = mountWithTheme(
  11. <IgnoreActions onUpdate={spy} disabled />,
  12. routerContext
  13. );
  14. button = component.find('button[aria-label="Ignore"]').first();
  15. });
  16. it('has disabled prop', function () {
  17. expect(button.props()['aria-disabled']).toBe(true);
  18. });
  19. it('does not call onUpdate when clicked', function () {
  20. button.simulate('click');
  21. expect(spy).not.toHaveBeenCalled();
  22. });
  23. });
  24. describe('ignored', function () {
  25. let component;
  26. const spy = jest.fn();
  27. beforeEach(function () {
  28. component = mountWithTheme(
  29. <IgnoreActions onUpdate={spy} isIgnored />,
  30. routerContext
  31. );
  32. });
  33. it('displays ignored view', function () {
  34. const button = component.find('button[aria-label="Unignore"]');
  35. expect(button).toHaveLength(1);
  36. // Shows icon only
  37. expect(button.text()).toBe('');
  38. });
  39. it('calls onUpdate with unresolved status when clicked', function () {
  40. component.find('button[aria-label="Unignore"]').simulate('click');
  41. expect(spy).toHaveBeenCalledWith({status: 'unresolved'});
  42. });
  43. });
  44. describe('without confirmation', function () {
  45. let component;
  46. const spy = jest.fn();
  47. beforeEach(function () {
  48. component = mountWithTheme(<IgnoreActions onUpdate={spy} />, routerContext);
  49. });
  50. it('calls spy with ignore details when clicked', function () {
  51. const button = component.find('button[aria-label="Ignore"]').first();
  52. button.simulate('click');
  53. expect(spy).toHaveBeenCalledTimes(1);
  54. expect(spy).toHaveBeenCalledWith({status: 'ignored'});
  55. });
  56. });
  57. describe('with confirmation step', function () {
  58. let component, button;
  59. const spy = jest.fn();
  60. beforeEach(function () {
  61. component = mountWithTheme(
  62. <IgnoreActions onUpdate={spy} shouldConfirm confirmMessage="confirm me" />,
  63. routerContext
  64. );
  65. button = component.find('button[aria-label="Ignore"]');
  66. });
  67. it('displays confirmation modal with message provided', async function () {
  68. button.simulate('click');
  69. const modal = await mountGlobalModal();
  70. expect(modal.text()).toContain('confirm me');
  71. expect(spy).not.toHaveBeenCalled();
  72. modal.find('Button[priority="primary"]').simulate('click');
  73. expect(spy).toHaveBeenCalled();
  74. });
  75. });
  76. });