device.spec.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import ContextCard from 'sentry/components/events/contexts/contextCard';
  4. import {getDeviceContextData} from 'sentry/components/events/contexts/knownContext/device';
  5. import type {DeviceContext} from 'sentry/types/event';
  6. const MOCK_DEVICE_CONTEXT: DeviceContext = {
  7. name: '', // redacted
  8. screen_resolution: '1136x768',
  9. orientation: 'portrait',
  10. family: 'Android',
  11. battery_level: 100,
  12. battery_temperature: 45,
  13. screen_dpi: 480,
  14. memory_size: 1055186944,
  15. timezone: 'America/Los_Angeles',
  16. external_storage_size: 534761472,
  17. external_free_storage: 534702080,
  18. screen_width_pixels: 768,
  19. low_memory: false,
  20. simulator: true,
  21. screen_height_pixels: 1136,
  22. free_memory: 658702336,
  23. online: true,
  24. screen_density: 3,
  25. type: 'device',
  26. charging: true,
  27. model_id: 'NYC',
  28. brand: 'google',
  29. storage_size: 817143808,
  30. boot_time: '2019-12-11T11:38:15Z',
  31. arch: 'x86',
  32. manufacturer: 'Google',
  33. free_storage: 508784640,
  34. model: 'Android SDK built for x86',
  35. };
  36. const MOCK_REDACTION = {
  37. name: {
  38. '': {
  39. rem: [['organization:0', 's', 0, 0]],
  40. len: 25,
  41. },
  42. },
  43. };
  44. describe('DeviceContext', function () {
  45. it('returns values and according to the parameters', function () {
  46. // We need to use expect.anything() for some fields as they return React components.
  47. expect(
  48. getDeviceContextData({data: MOCK_DEVICE_CONTEXT, event: EventFixture()})
  49. ).toEqual([
  50. {key: 'name', subject: 'Name', value: ''},
  51. {
  52. key: 'screen_resolution',
  53. subject: 'Screen Resolution',
  54. value: '1136x768',
  55. },
  56. {key: 'orientation', subject: 'Orientation', value: 'portrait'},
  57. {key: 'family', subject: 'Family', value: 'Android'},
  58. {key: 'battery_level', subject: 'Battery Level', value: '100%'},
  59. {
  60. key: 'battery_temperature',
  61. subject: 'Battery Temperature (°C)',
  62. value: 45,
  63. },
  64. {key: 'screen_dpi', subject: 'Screen DPI', value: 480},
  65. {
  66. key: 'memory_size',
  67. subject: 'Memory Size',
  68. value: expect.anything(),
  69. },
  70. {
  71. key: 'timezone',
  72. subject: 'timezone',
  73. value: 'America/Los_Angeles',
  74. meta: undefined,
  75. },
  76. {
  77. key: 'external_storage_size',
  78. subject: 'External Storage Size',
  79. value: expect.anything(),
  80. },
  81. {
  82. key: 'external_free_storage',
  83. subject: 'External Free Storage',
  84. value: expect.anything(),
  85. },
  86. {
  87. key: 'screen_width_pixels',
  88. subject: 'Screen Width Pixels',
  89. value: 768,
  90. },
  91. {key: 'low_memory', subject: 'Low Memory', value: false},
  92. {key: 'simulator', subject: 'Simulator', value: true},
  93. {
  94. key: 'screen_height_pixels',
  95. subject: 'Screen Height Pixels',
  96. value: 1136,
  97. },
  98. {
  99. key: 'free_memory',
  100. subject: 'Free Memory',
  101. value: expect.anything(),
  102. },
  103. {key: 'online', subject: 'Online', value: true},
  104. {key: 'screen_density', subject: 'Screen Density', value: 3},
  105. {key: 'charging', subject: 'Charging', value: true},
  106. {key: 'model_id', subject: 'Model Id', value: 'NYC'},
  107. {key: 'brand', subject: 'Brand', value: 'google'},
  108. {
  109. key: 'storage_size',
  110. subject: 'Storage Size',
  111. value: expect.anything(),
  112. },
  113. {
  114. key: 'boot_time',
  115. subject: 'Boot Time',
  116. value: expect.anything(),
  117. },
  118. {key: 'arch', subject: 'Architecture', value: 'x86'},
  119. {key: 'manufacturer', subject: 'Manufacturer', value: 'Google'},
  120. {
  121. key: 'free_storage',
  122. subject: 'Free Storage',
  123. value: expect.anything(),
  124. },
  125. {
  126. key: 'model',
  127. subject: 'Model',
  128. value: expect.anything(),
  129. },
  130. ]);
  131. });
  132. it('renders with meta annotations correctly', function () {
  133. const event = EventFixture({
  134. _meta: {contexts: {device: MOCK_REDACTION}},
  135. });
  136. render(
  137. <ContextCard
  138. event={event}
  139. type={'device'}
  140. alias={'device'}
  141. value={{...MOCK_DEVICE_CONTEXT, name: ''}}
  142. />
  143. );
  144. expect(screen.getByText('Device')).toBeInTheDocument();
  145. expect(screen.getByText('Orientation')).toBeInTheDocument();
  146. expect(screen.getByText('portrait')).toBeInTheDocument();
  147. expect(screen.getByText('Name')).toBeInTheDocument();
  148. expect(screen.getByText(/redacted/)).toBeInTheDocument();
  149. });
  150. });