mechanism.spec.jsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import {render} from 'sentry-test/reactTestingLibrary';
  2. import ExceptionMechanism from 'sentry/components/events/interfaces/crashContent/exception/mechanism';
  3. describe('ExceptionMechanism', () => {
  4. describe('basic attributes', () => {
  5. it('should render the exception mechanism', () => {
  6. const mechanism = {type: 'generic'};
  7. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  8. expect(wrapper.container).toSnapshot();
  9. });
  10. it('should render a help_link icon', () => {
  11. const mechanism = {type: 'generic', help_link: 'https://example.org/help'};
  12. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  13. expect(wrapper.container).toSnapshot();
  14. });
  15. it('should render a description hovercard', () => {
  16. const mechanism = {type: 'generic', description: 'Nothing to see here.'};
  17. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  18. expect(wrapper.container).toSnapshot();
  19. });
  20. it('should add the help_link to the description hovercard', () => {
  21. const mechanism = {
  22. type: 'generic',
  23. description: 'Nothing to see here.',
  24. help_link: 'https://example.org/help',
  25. };
  26. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  27. expect(wrapper.container).toSnapshot();
  28. });
  29. it('should not add the help_link if not starts with http(s)', () => {
  30. const mechanism = {
  31. type: 'generic',
  32. description: 'Nothing to see here.',
  33. help_link: 'example.org/help',
  34. };
  35. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  36. expect(wrapper.container).toSnapshot();
  37. });
  38. it('should render the handled pill', () => {
  39. const mechanism = {type: 'generic', handled: false};
  40. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  41. expect(wrapper.container).toSnapshot();
  42. });
  43. });
  44. describe('errno meta', () => {
  45. it('should render the errno number', () => {
  46. const mechanism = {type: 'generic', meta: {errno: {number: 7}}};
  47. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  48. expect(wrapper.container).toSnapshot();
  49. });
  50. it('should prefer the errno name if present', () => {
  51. const mechanism = {type: 'generic', meta: {errno: {number: 7, name: 'E2BIG'}}};
  52. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  53. expect(wrapper.container).toSnapshot();
  54. });
  55. });
  56. describe('mach_exception meta', () => {
  57. it('should render the mach exception number', () => {
  58. const mechanism = {
  59. type: 'generic',
  60. meta: {mach_exception: {exception: 1, subcode: 8, code: 1}},
  61. };
  62. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  63. expect(wrapper.container).toSnapshot();
  64. });
  65. it('should prefer the exception name if present', () => {
  66. const mechanism = {
  67. type: 'generic',
  68. meta: {
  69. mach_exception: {exception: 1, subcode: 8, code: 1, name: 'EXC_BAD_ACCESS'},
  70. },
  71. };
  72. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  73. expect(wrapper.container).toSnapshot();
  74. });
  75. });
  76. describe('signal meta', () => {
  77. it('should render the signal number', () => {
  78. const mechanism = {type: 'generic', meta: {signal: {number: 11}}};
  79. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  80. expect(wrapper.container).toSnapshot();
  81. });
  82. it('should add the signal code if present', () => {
  83. const mechanism = {type: 'generic', meta: {signal: {number: 11, code: 0}}};
  84. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  85. expect(wrapper.container).toSnapshot();
  86. });
  87. it('should prefer signal and code names if present', () => {
  88. const mechanism = {
  89. type: 'generic',
  90. meta: {signal: {number: 11, code: 0, name: 'SIGSEGV', code_name: 'SEGV_NOOP'}},
  91. };
  92. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  93. expect(wrapper.container).toSnapshot();
  94. });
  95. });
  96. describe('additional data', () => {
  97. it('should render all fields in the data object', () => {
  98. const mechanism = {type: 'generic', data: {relevant_address: '0x1'}};
  99. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  100. expect(wrapper.container).toSnapshot();
  101. });
  102. it('should skip object-like values', () => {
  103. const mechanism = {
  104. type: 'generic',
  105. data: {
  106. a: {x: 11},
  107. b: [4, 2],
  108. c: new Date(),
  109. },
  110. };
  111. const wrapper = render(<ExceptionMechanism data={mechanism} />);
  112. expect(wrapper.container).toSnapshot();
  113. });
  114. });
  115. });