Add unit test for images in markdown

This commit is contained in:
Owen Conti
2017-10-08 10:26:32 -06:00
parent 1785d48746
commit 60e8091eed
2 changed files with 36 additions and 23 deletions

View File

@@ -30,6 +30,9 @@ export default Markdown
const sanitizeOptions = { const sanitizeOptions = {
allowedTags: sanitize.defaults.allowedTags.concat([ "h1", "h2", "img" ]), allowedTags: sanitize.defaults.allowedTags.concat([ "h1", "h2", "img" ]),
allowedAttributes: {
"img": sanitize.defaults.allowedAttributes.img.concat(["title"])
},
textFilter: function(text) { textFilter: function(text) {
return text.replace(/"/g, "\"") return text.replace(/"/g, "\"")
} }

View File

@@ -5,8 +5,14 @@ import { render } from "enzyme"
import Markdown from "components/providers/markdown" import Markdown from "components/providers/markdown"
import { Markdown as OAS3Markdown } from "corePlugins/oas3/wrap-components/markdown.js" import { Markdown as OAS3Markdown } from "corePlugins/oas3/wrap-components/markdown.js"
describe.only("Markdown component", function() { describe("Markdown component", function() {
describe("Swagger 2.0", function() { describe("Swagger 2.0", function() {
it("allows image elements", function() {
const str = `![Image alt text](http://image.source "Image title")`
const el = render(<Markdown source={str} />)
expect(el.html()).toEqual(`<div class="markdown"><p><img src="http://image.source" title="Image title"></p>\n</div>`)
})
it("allows heading elements", function() { it("allows heading elements", function() {
const str = ` const str = `
# h1 # h1
@@ -14,23 +20,27 @@ describe.only("Markdown component", function() {
### h3 ### h3
#### h4 #### h4
##### h5 ##### h5
###### h6 ###### h6`
`
const el = render(<Markdown source={str} />) const el = render(<Markdown source={str} />)
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>`) 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>`)
}) })
}) })
describe("OAS 3", function() { describe("OAS 3", function() {
it("allows image elements", function() {
const str = `![Image alt text](http://image.source "Image title")`
const el = render(<OAS3Markdown source={str} />)
expect(el.html()).toEqual(`<div class="renderedMarkdown"><div><p><img src="http://image.source" title="Image title"></p></div></div>`)
})
it("allows heading elements", function() { it("allows heading elements", function() {
const str = ` const str = `
# h1 # h1
## h2 ## h2
### h3 ### h3
#### h4 #### h4
##### h5 ##### h5
###### h6 ###### h6`
`
const el = render(<OAS3Markdown source={str} />) const el = render(<OAS3Markdown source={str} />)
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>`) 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>`)
}) })