contexts.spec.tsx 3.8 KB

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