You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

55 lines
2.0 KiB

  1. /* eslint-env mocha */
  2. import React from "react"
  3. import expect from "expect"
  4. import { render } from "enzyme"
  5. import Markdown from "components/providers/markdown"
  6. import { Markdown as OAS3Markdown } from "corePlugins/oas3/wrap-components/markdown.js"
  7. describe("Markdown component", function() {
  8. describe("Swagger 2.0", function() {
  9. it("allows image elements", function() {
  10. const str = `![Image alt text](http://image.source "Image title")`
  11. const el = render(<Markdown source={str} />)
  12. expect(el.html()).toEqual(`<div class="markdown"><p><img src="http://image.source" title="Image title"></p>\n</div>`)
  13. })
  14. it("allows heading elements", function() {
  15. const str = `
  16. # h1
  17. ## h2
  18. ### h3
  19. #### h4
  20. ##### h5
  21. ###### h6`
  22. const el = render(<Markdown source={str} />)
  23. expect(el.html()).toEqual(`<div class="markdown"><h1>h1</h1>\n<h2>h2</h2>\n<h3>h3</h3>\n<h4>h4</h4>\n<h5>h5</h5>\n<h6>h6</h6>\n</div>`)
  24. })
  25. it("allows links", function() {
  26. const str = `[Link](https://example.com/)`
  27. const el = render(<Markdown source={str} />)
  28. expect(el.html()).toEqual(`<div class="markdown"><p><a href="https://example.com/" target="_blank">Link</a></p>\n</div>`)
  29. })
  30. })
  31. describe("OAS 3", function() {
  32. it("allows image elements", function() {
  33. const str = `![Image alt text](http://image.source "Image title")`
  34. const el = render(<OAS3Markdown source={str} />)
  35. expect(el.html()).toEqual(`<div class="renderedMarkdown"><div><p><img src="http://image.source" title="Image title"></p></div></div>`)
  36. })
  37. it("allows heading elements", function() {
  38. const str = `
  39. # h1
  40. ## h2
  41. ### h3
  42. #### h4
  43. ##### h5
  44. ###### h6`
  45. const el = render(<OAS3Markdown source={str} />)
  46. expect(el.html()).toEqual(`<div class="renderedMarkdown"><div><h1>h1</h1>\n<h2>h2</h2>\n<h3>h3</h3>\n<h4>h4</h4>\n<h5>h5</h5>\n<h6>h6</h6></div></div>`)
  47. })
  48. })
  49. })