feat: syntax highlighting of code section (#6236)

Co-authored-by: AdrieanKhisbe <adriean.khisbe@live.fr>
This commit is contained in:
Tim Lai
2020-07-17 15:29:15 -07:00
committed by GitHub
parent 9e294fbab5
commit a73783b73d
20 changed files with 340 additions and 228 deletions

View File

@@ -3,22 +3,24 @@ import expect from "expect"
import { shallow } from "enzyme"
import HighlightCode from "components/highlight-code"
const fakeGetConfigs = () => ({syntaxHighlight: {activated: true, theme: "agate"}})
describe("<HighlightCode />", () => {
it("should render a Download button if downloadable", () => {
const props = {downloadable: true}
const props = {downloadable: true, getConfigs: fakeGetConfigs }
const wrapper = shallow(<HighlightCode {...props} />)
expect(wrapper.find(".download-contents").length).toEqual(1)
})
it("should render a Copy To Clipboard button if copyable", () => {
const props = {canCopy: true}
const props = {canCopy: true, getConfigs: fakeGetConfigs }
const wrapper = shallow(<HighlightCode {...props} />)
expect(wrapper.find("CopyToClipboard").length).toEqual(1)
})
it("should render values in a preformatted element", () => {
const value = "test text"
const props = {value: value}
const props = {value: value, getConfigs: fakeGetConfigs}
const wrapper = shallow(<HighlightCode {...props} />)
const preTag = wrapper.find("pre")

View File

@@ -74,9 +74,9 @@ describe("OpenAPI 3.0 Allow Empty Values in Request Body", () => {
.get(".execute.opblock-control__btn")
.click()
// cURL component
.get(".responses-wrapper .copy-paste")
.get(".responses-wrapper .curl-command")
.should("exist")
.get(".responses-wrapper .copy-paste textarea")
.get(".responses-wrapper .curl-command span")
.should("contains.text", "tags=&status=")
})
@@ -101,9 +101,9 @@ describe("OpenAPI 3.0 Allow Empty Values in Request Body", () => {
.get(".execute.opblock-control__btn")
.click()
// cURL component
.get(".responses-wrapper .copy-paste")
.get(".responses-wrapper .curl-command")
.should("exist")
.get(".responses-wrapper .copy-paste textarea")
.get(".responses-wrapper .curl-command span")
.should("contains.text", "&status=")
.should("not.contains.text", "tags=")
})
@@ -131,9 +131,9 @@ describe("OpenAPI 3.0 Allow Empty Values in Request Body", () => {
.get(".execute.opblock-control__btn")
.click()
// cURL component
.get(".responses-wrapper .copy-paste")
.get(".responses-wrapper .curl-command")
.should("exist")
.get(".responses-wrapper .copy-paste textarea")
.get(".responses-wrapper .curl-command span")
.should("not.contains.text", "tags=")
.should("not.contains.text", "status=")
})

View File

@@ -23,7 +23,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(1) > .parameters-col_description input")
.should("have.class", "invalid")
// cURL component should not exist
.get(".responses-wrapper .copy-paste")
.get(".responses-wrapper .curl-command")
.should("not.exist")
})
it("on execute, if value exists, should NOT render class 'invalid' and SHOULD render cURL component", () => {
@@ -43,7 +43,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
.click()
.should("not.have.class", "invalid")
// cURL component should exist
.get(".responses-wrapper .copy-paste")
.get(".responses-wrapper .curl-command")
.should("exist")
})
})
@@ -69,7 +69,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
.get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
.should("have.class", "invalid")
// cURL component should not exist
.get(".responses-wrapper .copy-paste")
.get(".responses-wrapper .curl-command")
.should("not.exist")
})
it("on execute, if value exists, even if just single space, should NOT render class 'invalid' and SHOULD render cURL component that contains the single space", () => {
@@ -91,10 +91,10 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
.get(".opblock-body .opblock-section .opblock-section-request-body .body-param textarea")
.should("not.have.class", "invalid")
// cURL component should exist
.get(".responses-wrapper .copy-paste")
.get(".responses-wrapper .curl-command")
.should("exist")
.get(".responses-wrapper .copy-paste textarea")
.should("contains.text", "-d \" \"")
.get(".responses-wrapper .curl-command span")
.should("contains.text", "\" \"")
})
})
@@ -125,7 +125,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
.get(".opblock-body .opblock-section .opblock-section-request-body .parameters:nth-child(2) > .parameters-col_description input")
.should("have.class", "invalid")
// cURL component should not exist
.get(".responses-wrapper .copy-paste")
.get(".responses-wrapper .curl-command")
.should("not.exist")
})
it("on execute, if all values exist, even if array exists but is empty, should NOT render class 'invalid' and SHOULD render cURL component", () => {
@@ -152,7 +152,7 @@ describe("OpenAPI 3.0 Validation for Required Request Body and Request Body Fiel
.should("have.value", "")
.should("not.have.class", "invalid")
// cURL component should exist
.get(".responses-wrapper .copy-paste")
.get(".responses-wrapper .curl-command")
.should("exist")
})
})