contextSummary.spec.jsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import ContextSummary from 'sentry/components/events/contextSummary';
  3. import ContextSummaryGPU from 'sentry/components/events/contextSummary/contextSummaryGPU';
  4. import ContextSummaryOS from 'sentry/components/events/contextSummary/contextSummaryOS';
  5. import ContextSummaryUser from 'sentry/components/events/contextSummary/contextSummaryUser';
  6. import {FILTER_MASK} from 'sentry/constants';
  7. const CONTEXT_USER = {
  8. email: 'mail@example.org',
  9. id: '1',
  10. };
  11. const CONTEXT_DEVICE = {
  12. arch: 'x86',
  13. family: 'iOS',
  14. model: 'iPhone10,5',
  15. type: 'device',
  16. };
  17. const CONTEXT_OS = {
  18. kernel_version: '17.5.0',
  19. version: '10.13.4',
  20. type: 'os',
  21. build: '17E199',
  22. name: 'Mac OS X',
  23. };
  24. const CONTEXT_OS_SERVER = {
  25. kernel_version: '4.3.0',
  26. version: '4.3.0',
  27. type: 'os',
  28. build: '123123123',
  29. name: 'Linux',
  30. };
  31. const CONTEXT_RUNTIME = {
  32. version: '1.7.13',
  33. type: 'runtime',
  34. name: 'Electron',
  35. };
  36. const CONTEXT_BROWSER = {
  37. version: '65.0.3325',
  38. name: 'Chrome',
  39. };
  40. describe('ContextSummary', function () {
  41. describe('render()', function () {
  42. it('renders nothing without contexts', () => {
  43. const event = {
  44. id: '',
  45. contexts: {},
  46. };
  47. const wrapper = mountWithTheme(<ContextSummary event={event} />);
  48. expect(wrapper).toSnapshot();
  49. });
  50. it('renders nothing with a single user context', () => {
  51. const event = {
  52. id: '',
  53. user: CONTEXT_USER,
  54. contexts: {},
  55. };
  56. const wrapper = mountWithTheme(<ContextSummary event={event} />);
  57. expect(wrapper).toSnapshot();
  58. });
  59. it('should bail out with empty contexts', () => {
  60. const event = {
  61. id: '',
  62. user: CONTEXT_USER,
  63. contexts: {
  64. device: {},
  65. os: {},
  66. },
  67. };
  68. const wrapper = mountWithTheme(<ContextSummary event={event} />);
  69. expect(wrapper).toSnapshot();
  70. });
  71. it('renders at least three contexts', () => {
  72. const event = {
  73. id: '',
  74. user: CONTEXT_USER,
  75. contexts: {
  76. device: CONTEXT_DEVICE,
  77. },
  78. };
  79. const wrapper = mountWithTheme(<ContextSummary event={event} />);
  80. expect(wrapper).toSnapshot();
  81. });
  82. it('renders up to four contexts', () => {
  83. const event = {
  84. id: '',
  85. user: CONTEXT_USER,
  86. contexts: {
  87. os: CONTEXT_OS,
  88. browser: CONTEXT_BROWSER,
  89. runtime: CONTEXT_RUNTIME,
  90. device: CONTEXT_DEVICE, // must be omitted
  91. },
  92. };
  93. const wrapper = mountWithTheme(<ContextSummary event={event} />);
  94. expect(wrapper).toSnapshot();
  95. });
  96. it('should prefer client_os over os', () => {
  97. const event = {
  98. id: '',
  99. user: CONTEXT_USER,
  100. contexts: {
  101. client_os: CONTEXT_OS,
  102. os: CONTEXT_OS_SERVER,
  103. browser: CONTEXT_BROWSER,
  104. runtime: CONTEXT_RUNTIME,
  105. },
  106. };
  107. const wrapper = mountWithTheme(<ContextSummary event={event} />);
  108. expect(wrapper).toSnapshot();
  109. });
  110. it('renders client_os too', () => {
  111. const event = {
  112. id: '',
  113. user: CONTEXT_USER,
  114. contexts: {
  115. client_os: CONTEXT_OS,
  116. browser: CONTEXT_BROWSER,
  117. runtime: CONTEXT_RUNTIME,
  118. },
  119. };
  120. const wrapper = mountWithTheme(<ContextSummary event={event} />);
  121. expect(wrapper).toSnapshot();
  122. });
  123. it('should skip non-default named contexts', () => {
  124. const event = {
  125. id: '',
  126. user: CONTEXT_USER,
  127. contexts: {
  128. os: CONTEXT_OS,
  129. chrome: CONTEXT_BROWSER, // non-standard context
  130. runtime: CONTEXT_RUNTIME,
  131. device: CONTEXT_DEVICE,
  132. },
  133. };
  134. const wrapper = mountWithTheme(<ContextSummary event={event} />);
  135. expect(wrapper).toSnapshot();
  136. });
  137. it('should skip a missing user context', () => {
  138. const event = {
  139. id: '',
  140. contexts: {
  141. os: CONTEXT_OS,
  142. chrome: CONTEXT_BROWSER, // non-standard context
  143. runtime: CONTEXT_RUNTIME,
  144. device: CONTEXT_DEVICE,
  145. },
  146. };
  147. const wrapper = mountWithTheme(<ContextSummary event={event} />);
  148. expect(wrapper).toSnapshot();
  149. });
  150. });
  151. });
  152. describe('OsSummary', function () {
  153. describe('render()', function () {
  154. it('renders the version string', () => {
  155. const os = {
  156. kernel_version: '17.5.0',
  157. version: '10.13.4',
  158. type: 'os',
  159. build: '17E199',
  160. name: 'Mac OS X',
  161. };
  162. const wrapper = mountWithTheme(<ContextSummaryOS data={os} />);
  163. expect(wrapper).toSnapshot();
  164. });
  165. it('renders the kernel version when no version', () => {
  166. const os = {
  167. kernel_version: '17.5.0',
  168. type: 'os',
  169. build: '17E199',
  170. name: 'Mac OS X',
  171. };
  172. const wrapper = mountWithTheme(<ContextSummaryOS data={os} />);
  173. expect(wrapper).toSnapshot();
  174. });
  175. it('renders unknown when no version', () => {
  176. const os = {
  177. type: 'os',
  178. build: '17E199',
  179. name: 'Mac OS X',
  180. };
  181. const wrapper = mountWithTheme(<ContextSummaryOS data={os} />);
  182. expect(wrapper).toSnapshot();
  183. });
  184. });
  185. });
  186. describe('GpuSummary', function () {
  187. describe('render()', function () {
  188. it('renders name and vendor', () => {
  189. const gpu = {
  190. name: 'Mali-T880',
  191. vendor_name: 'ARM',
  192. version: 'OpenGL ES 3.2 v1.r22p0-01rel0.f294e54ceb2cb2d81039204fa4b0402e',
  193. };
  194. const wrapper = mountWithTheme(<ContextSummaryGPU data={gpu} />);
  195. expect(wrapper).toSnapshot();
  196. });
  197. it('renders unknown when no vendor', () => {
  198. const gpu = {
  199. type: 'gpu',
  200. name: 'Apple A8 GPU',
  201. };
  202. const wrapper = mountWithTheme(<ContextSummaryGPU data={gpu} />);
  203. expect(wrapper).toSnapshot();
  204. });
  205. });
  206. });
  207. describe('UserSummary', function () {
  208. describe('render', function () {
  209. it('prefers email, then IP, then id, then username for title', function () {
  210. const user1 = {
  211. email: 'maisey@dogsrule.com',
  212. ip_address: '12.31.20.12',
  213. id: '26',
  214. username: 'maiseythedog',
  215. name: 'Maisey Dog',
  216. data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
  217. };
  218. const wrapper1 = mountWithTheme(<ContextSummaryUser data={user1} />);
  219. expect(wrapper1.find('[data-test-id="user-title"]').render().text()).toEqual(
  220. user1.email
  221. );
  222. const user2 = {
  223. ip_address: '12.31.20.12',
  224. id: '26',
  225. username: 'maiseythedog',
  226. name: 'Maisey Dog',
  227. data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
  228. };
  229. const wrapper2 = mountWithTheme(<ContextSummaryUser data={user2} />);
  230. expect(wrapper2.find('[data-test-id="user-title"]').render().text()).toEqual(
  231. user2.ip_address
  232. );
  233. const user3 = {
  234. id: '26',
  235. username: 'maiseythedog',
  236. name: 'Maisey Dog',
  237. data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
  238. };
  239. const wrapper3 = mountWithTheme(<ContextSummaryUser data={user3} />);
  240. expect(wrapper3.find('[data-test-id="user-title"]').render().text()).toEqual(
  241. user3.id
  242. );
  243. const user4 = {
  244. username: 'maiseythedog',
  245. name: 'Maisey Dog',
  246. data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
  247. };
  248. const wrapper4 = mountWithTheme(<ContextSummaryUser data={user4} />);
  249. expect(wrapper4.find('[data-test-id="user-title"]').render().text()).toEqual(
  250. user4.username
  251. );
  252. });
  253. it('renders NoSummary if no email, IP, id, or username', function () {
  254. const user = {
  255. name: 'Maisey Dog',
  256. data: {siblings: ['Charlie Dog'], dreamsOf: 'squirrels'},
  257. };
  258. const wrapper = mountWithTheme(<ContextSummaryUser data={user} />);
  259. expect(wrapper.find('[data-test-id="user-title"]')).toHaveLength(0);
  260. expect(wrapper.find('[data-test-id="no-summary-title"]').text()).toEqual(
  261. 'Unknown User'
  262. );
  263. });
  264. it('does not use filtered values for title', function () {
  265. const user1 = {
  266. email: FILTER_MASK,
  267. };
  268. const wrapper1 = mountWithTheme(<ContextSummaryUser data={user1} />);
  269. expect(wrapper1.find('[data-test-id="user-title"]')).toHaveLength(0);
  270. expect(wrapper1.find('[data-test-id="no-summary-title"]').text()).toEqual(
  271. 'Unknown User'
  272. );
  273. // TODO: currently, the IP filter just eliminates IP addresses rather than
  274. // filtering them like other user data, so here, where you'd expect a filtered
  275. // IP address, there isn't one. Add a similar entry to the above and below
  276. // if/when that changes.
  277. const user2 = {
  278. id: FILTER_MASK,
  279. };
  280. const wrapper2 = mountWithTheme(<ContextSummaryUser data={user2} />);
  281. expect(wrapper2.find('[data-test-id="user-title"]')).toHaveLength(0);
  282. expect(wrapper2.find('[data-test-id="no-summary-title"]').text()).toEqual(
  283. 'Unknown User'
  284. );
  285. const user3 = {
  286. username: FILTER_MASK,
  287. };
  288. const wrapper3 = mountWithTheme(<ContextSummaryUser data={user3} />);
  289. expect(wrapper3.find('[data-test-id="user-title"]')).toHaveLength(0);
  290. expect(wrapper3.find('[data-test-id="no-summary-title"]').text()).toEqual(
  291. 'Unknown User'
  292. );
  293. });
  294. it('does not use filtered values for avatar', function () {
  295. // id is never used for avatar purposes, but is enough to keep us from
  296. // ending up with a NoSummary component where the UserSummary component
  297. // should be
  298. const user1 = {
  299. id: '26',
  300. name: FILTER_MASK,
  301. };
  302. const wrapper1 = mountWithTheme(<ContextSummaryUser data={user1} />);
  303. expect(wrapper1.find('LetterAvatar').text()).toEqual('?');
  304. const user2 = {
  305. id: '26',
  306. email: FILTER_MASK,
  307. };
  308. const wrapper2 = mountWithTheme(<ContextSummaryUser data={user2} />);
  309. expect(wrapper2.find('LetterAvatar').text()).toEqual('?');
  310. const user3 = {
  311. id: '26',
  312. username: FILTER_MASK,
  313. };
  314. const wrapper3 = mountWithTheme(<ContextSummaryUser data={user3} />);
  315. expect(wrapper3.find('LetterAvatar').text()).toEqual('?');
  316. });
  317. });
  318. });