richHttpContent.spec.jsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {mountWithTheme, shallow} from 'sentry-test/enzyme';
  2. import RichHttpContent from 'sentry/components/events/interfaces/richHttpContent/richHttpContent';
  3. describe('RichHttpContent', function () {
  4. let data;
  5. afterEach(function () {});
  6. describe('getBodySection', function () {
  7. it('should return plain-text when given unrecognized inferred Content-Type', function () {
  8. data = {
  9. query: '',
  10. data: 'helloworld',
  11. headers: [],
  12. cookies: [],
  13. env: {},
  14. inferredContentType: null,
  15. };
  16. const wrapper = mountWithTheme(<RichHttpContent data={data} />);
  17. expect(
  18. wrapper.find('[data-test-id="rich-http-content-body-section-pre"]')
  19. ).toBeTruthy();
  20. });
  21. it('should return a KeyValueList element when inferred Content-Type is x-www-form-urlencoded', function () {
  22. data = {
  23. query: '',
  24. data: {foo: ['bar'], bar: ['baz']},
  25. headers: [],
  26. cookies: [],
  27. env: {},
  28. inferredContentType: 'application/x-www-form-urlencoded',
  29. };
  30. const wrapper = mountWithTheme(<RichHttpContent data={data} />);
  31. expect(
  32. wrapper.find('[data-test-id="rich-http-content-body-key-value-list"]')
  33. ).toBeTruthy();
  34. });
  35. it('should return a ContextData element when inferred Content-Type is application/json', function () {
  36. data = {
  37. query: '',
  38. data: {foo: 'bar'},
  39. headers: [],
  40. cookies: [],
  41. env: {},
  42. inferredContentType: 'application/json',
  43. };
  44. const wrapper = mountWithTheme(<RichHttpContent data={data} />);
  45. expect(
  46. wrapper.find('[data-test-id="rich-http-content-body-context-data"]')
  47. ).toBeTruthy();
  48. });
  49. it('should not blow up in a malformed uri', function () {
  50. // > decodeURIComponent('a%AFc')
  51. // URIError: URI malformed
  52. data = {
  53. query: 'a%AFc',
  54. data: '',
  55. headers: [],
  56. cookies: [],
  57. env: {},
  58. };
  59. expect(() => shallow(<RichHttpContent data={data} />)).not.toThrow(URIError);
  60. });
  61. it("should not cause an invariant violation if data.data isn't a string", function () {
  62. data = {
  63. query: '',
  64. data: [{foo: 'bar', baz: 1}],
  65. headers: [],
  66. cookies: [],
  67. env: {},
  68. };
  69. expect(() => mountWithTheme(<RichHttpContent data={data} />)).not.toThrow();
  70. });
  71. });
  72. });