feat: consolidate syntax highlighting code into standalone plugin (#9783)

This commit is contained in:
Vladimír Gorej
2024-04-05 21:12:25 +02:00
committed by GitHub
parent f844319188
commit 7260005bd8
20 changed files with 231 additions and 113 deletions

View File

@@ -1,26 +1,39 @@
import React from "react"
import expect from "expect"
import { shallow, mount } from "enzyme"
import HighlightCode from "core/components/highlight-code"
import HighlightCode from "core/plugins/syntax-highlighting/components/HighlightCode"
import SyntaxHighlighter from "core/plugins/syntax-highlighting/components/SyntaxHighlighter"
const fakeGetConfigs = () => ({syntaxHighlight: {activated: true, theme: "agate"}})
const fakeGetConfigs = () => ({ syntaxHighlight: { activated: true, theme: "agate" }})
const fakeGetComponent = (name, isContainer) => {
const components = { HighlightCode, SyntaxHighlighter }
const Component = components[name]
if (isContainer) {
return ({ ...props }) => {
return <Component getConfigs={fakeGetConfigs} getComponent={fakeGetComponent} {...props} />
}
}
return Component
}
describe("<HighlightCode />", () => {
it("should render a Download button if downloadable", () => {
const props = {downloadable: true, getConfigs: fakeGetConfigs }
const props = { downloadable: true, getConfigs: fakeGetConfigs, getComponent: fakeGetComponent }
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, getConfigs: fakeGetConfigs }
const props = { canCopy: true, getConfigs: fakeGetConfigs, getComponent: fakeGetComponent }
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, getConfigs: fakeGetConfigs}
const props = { value, getConfigs: fakeGetConfigs, getComponent: fakeGetComponent }
const wrapper = mount(<HighlightCode {...props} />)
const preTag = wrapper.find("pre")