contextSummary.spec.jsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import React from 'react';
  2. import {shallow} from 'enzyme';
  3. import ContextSummary, {
  4. OsSummary,
  5. GpuSummary,
  6. } from 'app/components/events/contextSummary';
  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_RUNTIME = {
  25. version: '1.7.13',
  26. type: 'runtime',
  27. name: 'Electron',
  28. };
  29. const CONTEXT_BROWSER = {
  30. version: '65.0.3325',
  31. name: 'Chrome',
  32. };
  33. describe('ContextSummary', function() {
  34. describe('render()', function() {
  35. it('should render nothing without contexts', () => {
  36. const event = {
  37. id: '',
  38. contexts: {},
  39. };
  40. const wrapper = shallow(<ContextSummary event={event} />);
  41. expect(wrapper).toMatchSnapshot();
  42. });
  43. it('should render nothing with a single user context', () => {
  44. const event = {
  45. id: '',
  46. user: CONTEXT_USER,
  47. contexts: {},
  48. };
  49. const wrapper = shallow(<ContextSummary event={event} />);
  50. expect(wrapper).toMatchSnapshot();
  51. });
  52. it('should bail out with empty contexts', () => {
  53. const event = {
  54. id: '',
  55. user: CONTEXT_USER,
  56. contexts: {
  57. device: {},
  58. os: {},
  59. },
  60. };
  61. const wrapper = shallow(<ContextSummary event={event} />);
  62. expect(wrapper).toMatchSnapshot();
  63. });
  64. it('should render at least three contexts', () => {
  65. const event = {
  66. id: '',
  67. user: CONTEXT_USER,
  68. contexts: {
  69. device: CONTEXT_DEVICE,
  70. },
  71. };
  72. const wrapper = shallow(<ContextSummary event={event} />);
  73. expect(wrapper).toMatchSnapshot();
  74. });
  75. it('should render up to four contexts', () => {
  76. const event = {
  77. id: '',
  78. user: CONTEXT_USER,
  79. contexts: {
  80. os: CONTEXT_OS,
  81. browser: CONTEXT_BROWSER,
  82. runtime: CONTEXT_RUNTIME,
  83. device: CONTEXT_DEVICE, // must be omitted
  84. },
  85. };
  86. const wrapper = shallow(<ContextSummary event={event} />);
  87. expect(wrapper).toMatchSnapshot();
  88. });
  89. it('should skip non-default named contexts', () => {
  90. const event = {
  91. id: '',
  92. user: CONTEXT_USER,
  93. contexts: {
  94. os: CONTEXT_OS,
  95. chrome: CONTEXT_BROWSER, // non-standard context
  96. runtime: CONTEXT_RUNTIME,
  97. device: CONTEXT_DEVICE,
  98. },
  99. };
  100. const wrapper = shallow(<ContextSummary event={event} />);
  101. expect(wrapper).toMatchSnapshot();
  102. });
  103. it('should skip a missing user context', () => {
  104. const event = {
  105. id: '',
  106. contexts: {
  107. os: CONTEXT_OS,
  108. chrome: CONTEXT_BROWSER, // non-standard context
  109. runtime: CONTEXT_RUNTIME,
  110. device: CONTEXT_DEVICE,
  111. },
  112. };
  113. const wrapper = shallow(<ContextSummary event={event} />);
  114. expect(wrapper).toMatchSnapshot();
  115. });
  116. });
  117. });
  118. describe('OsSummary', function() {
  119. describe('render()', function() {
  120. it('should render the version string', () => {
  121. const os = {
  122. kernel_version: '17.5.0',
  123. version: '10.13.4',
  124. type: 'os',
  125. build: '17E199',
  126. name: 'Mac OS X',
  127. };
  128. const wrapper = shallow(<OsSummary data={os} />);
  129. expect(wrapper).toMatchSnapshot();
  130. });
  131. it('should render the kernel version when no version', () => {
  132. const os = {
  133. kernel_version: '17.5.0',
  134. type: 'os',
  135. build: '17E199',
  136. name: 'Mac OS X',
  137. };
  138. const wrapper = shallow(<OsSummary data={os} />);
  139. expect(wrapper).toMatchSnapshot();
  140. });
  141. it('should render unknown when no version', () => {
  142. const os = {
  143. type: 'os',
  144. build: '17E199',
  145. name: 'Mac OS X',
  146. };
  147. const wrapper = shallow(<OsSummary data={os} />);
  148. expect(wrapper).toMatchSnapshot();
  149. });
  150. });
  151. });
  152. describe('GpuSummary', function() {
  153. describe('render()', function() {
  154. it('should render name and vendor', () => {
  155. const gpu = {
  156. name: 'Mali-T880',
  157. vendor_name: 'ARM',
  158. version: 'OpenGL ES 3.2 v1.r22p0-01rel0.f294e54ceb2cb2d81039204fa4b0402e',
  159. };
  160. const wrapper = shallow(<GpuSummary data={gpu} />);
  161. expect(wrapper).toMatchSnapshot();
  162. });
  163. it('should render unknown when no vendor', () => {
  164. const gpu = {
  165. type: 'gpu',
  166. name: 'Apple A8 GPU',
  167. };
  168. const wrapper = shallow(<GpuSummary data={gpu} />);
  169. expect(wrapper).toMatchSnapshot();
  170. });
  171. });
  172. });