contexts.spec.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import Device from 'sentry/components/events/contexts/device/device';
  3. import {commonDisplayResolutions} from 'sentry/components/events/contexts/device/utils';
  4. import User from 'sentry/components/events/contexts/user/user';
  5. import {FILTER_MASK} from 'sentry/constants';
  6. describe('User', function () {
  7. it("displays filtered values but doesn't use them for avatar", function () {
  8. const user1 = {
  9. id: '26',
  10. name: FILTER_MASK,
  11. };
  12. const wrapper1 = mountWithTheme(<User data={user1} />);
  13. expect(wrapper1.find('[data-test-id="user-context-name-value"]').text()).toEqual(
  14. FILTER_MASK
  15. );
  16. expect(wrapper1.find('LetterAvatar').text()).toEqual('?');
  17. const user2 = {
  18. id: '26',
  19. email: FILTER_MASK,
  20. };
  21. const wrapper2 = mountWithTheme(<User data={user2} />);
  22. expect(wrapper2.find('[data-test-id="user-context-email-value"]').text()).toEqual(
  23. FILTER_MASK
  24. );
  25. expect(wrapper2.find('LetterAvatar').text()).toEqual('?');
  26. const user3 = {
  27. id: '26',
  28. username: FILTER_MASK,
  29. };
  30. const wrapper3 = mountWithTheme(<User data={user3} />);
  31. expect(wrapper3.find('[data-test-id="user-context-username-value"]').text()).toEqual(
  32. FILTER_MASK
  33. );
  34. expect(wrapper3.find('LetterAvatar').text()).toEqual('?');
  35. });
  36. });
  37. describe('Device', function () {
  38. const event = TestStubs.Event();
  39. const device = {
  40. name: 'Device Name',
  41. screen_resolution: '3840x2160',
  42. screen_width_pixels: 3840,
  43. screen_height_pixels: 2160,
  44. };
  45. describe('getInferredData', function () {
  46. it('renders', function () {
  47. const wrapper = mountWithTheme(<Device data={device} event={event} />);
  48. expect(wrapper).toSnapshot();
  49. });
  50. it('renders screen_resolution inferred from screen_width_pixels and screen_height_pixels', function () {
  51. const wrapper = mountWithTheme(
  52. <Device data={{...device, screen_resolution: undefined}} event={event} />
  53. );
  54. expect(
  55. wrapper.find('[data-test-id="device-context-screen_width_pixels-value"]').text()
  56. ).toEqual(String(device.screen_width_pixels));
  57. expect(
  58. wrapper.find('[data-test-id="device-context-screen_height_pixels-value"]').text()
  59. ).toEqual(String(device.screen_height_pixels));
  60. expect(
  61. wrapper.find('[data-test-id="device-context-screen_resolution-value"]').text()
  62. ).toEqual(
  63. `${device.screen_resolution} (${
  64. commonDisplayResolutions[device.screen_resolution]
  65. })`
  66. );
  67. });
  68. it('renders screen_width_pixels and screen_height_pixels inferred from screen_resolution', function () {
  69. const wrapper = mountWithTheme(
  70. <Device
  71. data={{
  72. ...device,
  73. screen_width_pixels: undefined,
  74. screen_height_pixels: undefined,
  75. }}
  76. event={event}
  77. />
  78. );
  79. expect(
  80. wrapper.find('[data-test-id="device-context-screen_width_pixels-value"]').text()
  81. ).toEqual(String(device.screen_width_pixels));
  82. expect(
  83. wrapper.find('[data-test-id="device-context-screen_height_pixels-value"]').text()
  84. ).toEqual(String(device.screen_height_pixels));
  85. expect(
  86. wrapper.find('[data-test-id="device-context-screen_resolution-value"]').text()
  87. ).toEqual(
  88. `${device.screen_resolution} (${
  89. commonDisplayResolutions[device.screen_resolution]
  90. })`
  91. );
  92. });
  93. });
  94. });