threads.spec.jsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import Threads from 'sentry/components/events/interfaces/threads';
  3. import {OrganizationContext} from 'sentry/views/organizationContext';
  4. describe('Threads', () => {
  5. const entries = TestStubs.Entries()[0];
  6. const event = TestStubs.Event({entries});
  7. const organization = TestStubs.Organization();
  8. const exceptionEntry = entries[0];
  9. const data = exceptionEntry.data;
  10. const type = exceptionEntry.type;
  11. it('Display multiple frames', () => {
  12. const newEvent = {
  13. ...event,
  14. entries: [
  15. {
  16. ...event.entries[0],
  17. data: {
  18. ...event.entries[0].data,
  19. values: [
  20. event.entries[0].data.values[0],
  21. {
  22. module: 'example.application',
  23. type: 'Error',
  24. value: 'an error occurred',
  25. stacktrace: {
  26. frames: [
  27. {
  28. function: 'main',
  29. module: 'example.application',
  30. lineNo: 1,
  31. filename: 'application',
  32. },
  33. {
  34. function: 'doThing',
  35. module: 'example.application',
  36. lineNo: 2,
  37. filename: 'application',
  38. },
  39. ],
  40. },
  41. },
  42. ],
  43. },
  44. },
  45. event.entries[1],
  46. event.entries[2],
  47. ],
  48. };
  49. const wrapper = mountWithTheme(
  50. <OrganizationContext.Provider value={organization}>
  51. <Threads
  52. type={type}
  53. data={data}
  54. orgId="org-slug"
  55. projectId="project-id"
  56. event={newEvent}
  57. />
  58. </OrganizationContext.Provider>
  59. );
  60. // Total frames passed
  61. const totalFramesPasses =
  62. newEvent.entries[0].data.values[0].stacktrace.frames.length +
  63. newEvent.entries[0].data.values[1].stacktrace.frames.length;
  64. expect(wrapper.find('Line').length).toBe(totalFramesPasses);
  65. });
  66. it('Display no frame', () => {
  67. const wrapper = mountWithTheme(
  68. <OrganizationContext.Provider value={organization}>
  69. <Threads
  70. type={type}
  71. data={{...data, values: [{...data.values[0], stacktrace: null}]}}
  72. orgId="org-slug"
  73. projectId="project-id"
  74. event={{
  75. ...event,
  76. entries: [
  77. {
  78. ...event.entries[0],
  79. data: {
  80. ...event.entries[0].data,
  81. values: [{...event.entries[0].data.values[0], id: 0, stacktrace: null}],
  82. },
  83. },
  84. event.entries[1],
  85. event.entries[2],
  86. ],
  87. }}
  88. />
  89. </OrganizationContext.Provider>
  90. );
  91. // no exceptions or stacktraces have been found
  92. expect(wrapper.find('Line').length).toBe(0);
  93. });
  94. describe('Displays the stack trace of an exception if all threadIds of exceptionEntry.data.values do not match the threadId of the active thread and if the active thread has crashed equals true', () => {
  95. const threadsEntry = entries[1];
  96. it('Displays the exception stacktrace', () => {
  97. const wrapper = mountWithTheme(
  98. <OrganizationContext.Provider value={organization}>
  99. <Threads
  100. type={threadsEntry.type}
  101. data={threadsEntry.data}
  102. orgId="org-slug"
  103. projectId="project-id"
  104. event={event}
  105. />
  106. </OrganizationContext.Provider>
  107. );
  108. // envent.entries[0].data.values[0].stacktrace is defined
  109. expect(wrapper.find('Line').length).toBe(1);
  110. });
  111. it('Displays the the active thread stacktrace', () => {
  112. const wrapper = mountWithTheme(
  113. <OrganizationContext.Provider value={organization}>
  114. <Threads
  115. type={threadsEntry.type}
  116. data={threadsEntry.data}
  117. orgId="org-slug"
  118. projectId="project-id"
  119. event={{
  120. ...event,
  121. entries: [
  122. {
  123. ...event.entries[0],
  124. data: {
  125. ...event.entries[0].data,
  126. values: [{...event.entries[0].data.values[0], stacktrace: null}],
  127. },
  128. },
  129. event.entries[1],
  130. event.entries[2],
  131. ],
  132. }}
  133. />
  134. </OrganizationContext.Provider>
  135. );
  136. // the 'threads' entry has a stack trace with 23 frames, but as one of them is duplicated, we only display 22
  137. expect(wrapper.find('Line').length).toBe(22);
  138. });
  139. });
  140. });