response-body.jsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import React from "react"
  2. import { shallow } from "enzyme"
  3. import ResponseBody from "components/response-body"
  4. describe("<ResponseBody />", function () {
  5. const highlightCodeComponent = () => null
  6. const components = {
  7. highlightCode: highlightCodeComponent
  8. }
  9. const props = {
  10. getComponent: c => components[c],
  11. }
  12. it("renders ResponseBody as 'application/json'", function () {
  13. props.contentType = "application/json"
  14. props.content = "{\"key\": \"a test value\"}"
  15. const wrapper = shallow(<ResponseBody {...props} />)
  16. expect(wrapper.find("highlightCodeComponent").length).toEqual(1)
  17. })
  18. it("renders ResponseBody as 'text/html'", function () {
  19. props.contentType = "application/json"
  20. props.content = "<b>Result</b>"
  21. const wrapper = shallow(<ResponseBody {...props} />)
  22. expect(wrapper.find("highlightCodeComponent").length).toEqual(1)
  23. })
  24. it("renders ResponseBody as 'image/svg'", function () {
  25. props.contentType = "image/svg"
  26. const wrapper = shallow(<ResponseBody {...props} />)
  27. console.warn(wrapper.debug())
  28. expect(wrapper.find("highlightCodeComponent").length).toEqual(0)
  29. })
  30. it("should render a copyable highlightCodeComponent for text types", function () {
  31. props.contentType = "text/plain"
  32. props.content = "test text"
  33. const wrapper = shallow(<ResponseBody {...props} />)
  34. console.warn(wrapper.debug())
  35. expect(wrapper.find("highlightCodeComponent[canCopy]").length).toEqual(1)
  36. })
  37. })