contexts.spec.tsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import {DeviceEventContext} from 'sentry/components/events/contexts/device';
  3. import {commonDisplayResolutions} from 'sentry/components/events/contexts/device/utils';
  4. import {UserEventContext} from 'sentry/components/events/contexts/user';
  5. import {FILTER_MASK} from 'sentry/constants';
  6. import {DeviceContext} from 'sentry/types';
  7. describe('User', function () {
  8. it("displays filtered values but doesn't use them for avatar", function () {
  9. const {rerender} = render(
  10. <UserEventContext
  11. data={{
  12. id: '26',
  13. name: FILTER_MASK,
  14. email: '',
  15. username: '',
  16. ip_address: '',
  17. data: {},
  18. }}
  19. event={TestStubs.Event()}
  20. />
  21. );
  22. expect(screen.getByTestId('user-context-name-value')).toHaveTextContent(FILTER_MASK);
  23. expect(screen.getByText('?')).toBeInTheDocument();
  24. rerender(
  25. <UserEventContext
  26. data={{
  27. id: '26',
  28. name: '',
  29. email: FILTER_MASK,
  30. username: '',
  31. ip_address: '',
  32. data: {},
  33. }}
  34. event={TestStubs.Event()}
  35. />
  36. );
  37. expect(screen.getByTestId('user-context-email-value')).toHaveTextContent(FILTER_MASK);
  38. expect(screen.getByText('?')).toBeInTheDocument();
  39. rerender(
  40. <UserEventContext
  41. data={{
  42. id: '26',
  43. name: '',
  44. email: '',
  45. username: FILTER_MASK,
  46. ip_address: '',
  47. data: {},
  48. }}
  49. event={TestStubs.Event()}
  50. />
  51. );
  52. expect(screen.getByTestId('user-context-username-value')).toHaveTextContent(
  53. FILTER_MASK
  54. );
  55. expect(screen.getByText('?')).toBeInTheDocument();
  56. });
  57. });
  58. describe('Device', function () {
  59. const device: DeviceContext = {
  60. type: 'device',
  61. name: 'Device Name',
  62. screen_resolution: '3840x2160',
  63. screen_width_pixels: 3840,
  64. screen_height_pixels: 2160,
  65. device_type: 'desktop',
  66. };
  67. describe('getInferredData', function () {
  68. it('renders', function () {
  69. const {container} = render(
  70. <DeviceEventContext data={device} event={TestStubs.Event()} />
  71. );
  72. expect(container).toSnapshot();
  73. });
  74. it('renders screen_resolution inferred from screen_width_pixels and screen_height_pixels', function () {
  75. render(
  76. <DeviceEventContext
  77. data={{...device, screen_resolution: undefined}}
  78. event={TestStubs.Event()}
  79. />
  80. );
  81. expect(
  82. screen.getByTestId('device-context-screen_width_pixels-value')
  83. ).toHaveTextContent(String(device.screen_width_pixels));
  84. expect(
  85. screen.getByTestId('device-context-screen_height_pixels-value')
  86. ).toHaveTextContent(String(device.screen_height_pixels));
  87. expect(
  88. screen.getByTestId('device-context-screen_resolution-value')
  89. ).toHaveTextContent(
  90. `${device.screen_resolution} (${
  91. commonDisplayResolutions[String(device.screen_resolution)]
  92. })`
  93. );
  94. });
  95. it('renders screen_width_pixels and screen_height_pixels inferred from screen_resolution', function () {
  96. render(
  97. <DeviceEventContext
  98. data={{
  99. ...device,
  100. screen_width_pixels: undefined,
  101. screen_height_pixels: undefined,
  102. }}
  103. event={TestStubs.Event()}
  104. />
  105. );
  106. expect(
  107. screen.getByTestId('device-context-screen_width_pixels-value')
  108. ).toHaveTextContent(String(device.screen_width_pixels));
  109. expect(
  110. screen.getByTestId('device-context-screen_height_pixels-value')
  111. ).toHaveTextContent(String(device.screen_height_pixels));
  112. expect(
  113. screen.getByTestId('device-context-screen_resolution-value')
  114. ).toHaveTextContent(
  115. `${device.screen_resolution} (${
  116. commonDisplayResolutions[String(device.screen_resolution)]
  117. })`
  118. );
  119. });
  120. });
  121. });